in Algorithms retagged by
359 views
1 vote
1 vote

in Algorithms retagged by
359 views

3 Comments

It quit famous algorithm but try take m and n at least 2 or 3 different sets and see results.and correlate it
0
0
It would be easy for me if u give some examples...
0
0
let n=100 & m=50

1) n>m

n=n%m

n=0

2) n=0 m=50

swap(0,50)

3) return 50
–1
–1

1 Answer

2 votes
2 votes
Best answer

Proceed according to Algorithm

I am taking an examples here :

example : 

consider m=13 , n=17 , Now

Both IF conditions are false so directly go to while loop here (m>0)

1) n= 17 % 13 = 4

   After Swap(4 , 13) the values will be m = 4 and n = 13 ...(m>0)

2) n= 13 % 4 = 1

  After Swap(1 , 4) the values will be m = 1 and n = 4...(m>0)

3) n= 4 % 1 =0

  After Swap(0 , 1) the values will be m = 1 and n = 0...(m>0)

4)) n= 0 % 1 = 1

Now you can see 4 iterations have been performed to reach the end. Here i have taken n = 17

So as n=17 has taken 4 iterations so COMPLEXITY WILL BE O(log n)  as log 17 is approx equal to 4.

Now you can take any values for m and n you will get COMPLEXITY O(log n) assuming worst case only.

selected by

1 comment

Is this question correct as the code for swap function is not present?
0
0

Related questions