0 0 votes https://gateoverflow.in/394/gate2008-84 Here option A also leads to infinite loop right? it gets stuch at index 8 because 8 + 9 / 2 = 8 it never reaches 9 Algorithms + – A_i_$_h 850 views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Ashwin Kulkarni commented Nov 26, 2017 reply Follow flag You are true it never reaches to index 9. But there is no need to reach index 9. because number at index 9 is 10. and condition is given that x <10. Hence x must be upto 9 only. And for digit 9 it clearly stops at index 8. Hence in option A it doesn't fail. 0 0 replyShare A_i_$_h commented Nov 26, 2017 reply Follow flag @ashwin what if the element we are searching is 9 ? it gets stuck over the element 8 0 0 replyShare Ashwin Kulkarni commented Nov 26, 2017 reply Follow flag If we are searching for 9 it gets stuck at index 8 where 9 is present! Indexing starts from 0 to 9 in this example. so while searching digit 9, algorithm can stop at index 8 0 0 replyShare A_i_$_h commented Dec 16, 2017 reply Follow flag @ashwin sorry i meant OPTION B actually what if the element we are searching x=0 then it keeps iterating in an infinite loop right ? 0 0 replyShare Ashwin Kulkarni commented Dec 16, 2017 reply Follow flag In option B assume x =0. then while searching for 0 initially k = 9/2 = 4 j=k again k = 2 j=k again k =1 j=k again k=0 j=k here i=j also and hence won't go into infinite loop 0 0 replyShare A_i_$_h commented Dec 16, 2017 reply Follow flag @ashwin got it :) i was considering 1 / 2 as 1 by mistake :P like solving mod 1 1 replyShare Please log in or register to add a comment.