sorting - What does this sort algorithm do? -
i studying exam , in 1 of professors older exams, had algorithm given, should analyzed... it's array field 1 2n-1 , n power of two, in task a) n equals 8 , keys 8-15 given , shall try out algorithm , tell him, m value being returned. me have m=4, not sure whether right or wrong , rather know, algorithm does... unfortunately have copy image , not find code in internet...
i come conclusion while loop runs indefinitely because both f(1)
, f(2)
equal 2. m f(3)
indeed 4.
in first loop elements accessed in groups of 2 , smaller 1 gets assigned corresponding element @ index i
isn't defined yet. after 4 iterations former defined numbers accessed , 2 smaller numbers (from execution before) accessed. in addition f
gets pair information.
now array should [2,2,4,3,2,5,4, 3,7,2,8,5,6,9,4]
note: first element , f(1)
smallest number of range a[n...2n-1]
n
power of 2.
than m
gets defined bigger 1 of 2 or 4 (a[2] , a[3]) 4. k
f(1) same in array: 2 (in if m
gets reassigned 4)
so there problem mentioned earlier k = 2
, f(k) = f(2) = 2 = k
k
never bigger n - 1
required break out of while loop => no answer answer ;)
Comments
Post a Comment