Find the number of comparisons done in the following algorithm.
1 2 3 4 5 6 7 |
|
Assumptions and Details
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
For any non-negative integer n, the for-loop runs (n+1) times where there is an if-else comparison. Hence the total number of comparisons done are n + 1 .