-3

I have came up with a new sorting algorithm with just one do while loop in it, but i don't know how to calculate the efficiency of it in best,average and worst case so please help me in calculating it.
The loop starts with i=1 and the end condition for while loop is i<=n-2 and some times the value of i increases in the loop and some times i value will be decremented based on some condition.

I think i will better understand if u illustrate through simple examples. please help me............
Thank you in advance for those who help me.....

Will Vousden
  • 32,488
  • 9
  • 84
  • 95
  • 7
    We can't really evaluate the complexity of an algorithm without knowing what the algorithm is. In particular code (or even pseudo code) would be extremely helpful. – jpm Nov 12 '12 at 08:28
  • Unless you post the code you have, this looks like a "solve my homework assignment for me" request! – ppeterka Nov 12 '12 at 08:28
  • 3
    Who said one loop is always faster than two loops? [Shameless counterexample.](http://stackoverflow.com/questions/8547778/why-is-one-loop-so-much-slower-than-two-loops) – Mysticial Nov 12 '12 at 08:28
  • Did you reinvent [Gnome sort](http://en.wikipedia.org/wiki/Gnome_sort)? – Blastfurnace Nov 12 '12 at 14:55

1 Answers1

2

some times i value will be decremented based on some condition

This vagueness makes it impossible to analyze. If the "condition" is always true and i is decremented to zero, then the loop runs forever. So based on what you say, the time complexity could be anything from Theta(n) to infinity.

The way to work out time complexity is to calculate (or put an upper bound on) the number of operations performed, as a function of n. "Operations" in the case of sorting usually means comparisons and copies/moves, but if your algorithm does anything unusual then of course that has to be included.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699