0 0 votes Algorithms time-complexity array algorithm-design + – Deepalitrapti 1.7k views answer comment Share Follow Print See all 13 Comments 13 13 Comments reply air1ankit commented Sep 1, 2018 reply Follow flag Log n, option b 0 0 replyShare Deepalitrapti commented Sep 1, 2018 reply Follow flag How?? 0 0 replyShare MiNiPanda commented Sep 1, 2018 reply Follow flag How O(logn)? O_O 0 0 replyShare Shaik Masthan commented Sep 2, 2018 reply Follow flag Check this procedure 1.Sort the given array ===> O( n.log(n) ) assume index starts from one ===> maximum index = n, minimum index = 1 let the initialize j = maximum value 2. for( i=n; i>0; i--, j--) ====> O(n) if( a[i] == j ) continue; break; 3. print j value ===> it is missed so, total time complexity = O( n log(n) ) But Before that we have to check that, " Can we solved this problem with Binary Search ? " --- i will check and comment 1 1 replyShare MiNiPanda commented Sep 2, 2018 reply Follow flag @Shaik another way is like computing sum of first n integers i.e. from 1 to n = n(n+1)/2. Then loop over the array and on each iteration subtract the element at that index from this sum. The sum left at the end will be the missing no. TC: O(n). 1 1 replyShare Shaik Masthan commented Sep 2, 2018 reply Follow flag @MiNiPanda, super broo 0 0 replyShare MiNiPanda commented Sep 2, 2018 reply Follow flag From geeksforgeeks! :v 0 0 replyShare Shaik Masthan commented Sep 2, 2018 reply Follow flag @MiNiPanda Hahahah.... But really GFG is a wonderful site for especially for ALGORITHMS. if we really complete the portion in GFG, then no need to bother about any question of ALGORITHMS in GATE. 1 1 replyShare MiNiPanda commented Sep 2, 2018 reply Follow flag Yes very true.. 0 0 replyShare air1ankit commented Sep 2, 2018 reply Follow flag Sorry ,yes it should be O(n) , @minipanda thanks bro, Question smjhne me maine mistake kr diya tha .. 0 0 replyShare air1ankit commented Sep 2, 2018 reply Follow flag Well explanation bro @shaikmasthan 0 0 replyShare Shaik Masthan commented Sep 2, 2018 reply Follow flag we can't apply binary search, due to array is not sort. But we know that n is fixed ===> apply counting sort ==> O(n) then again with a for loop, we can know which is missing ===> O(n) O(n)+O(n) = O(n) 0 0 replyShare mrinmoyh commented Sep 17, 2020 reply Follow flag XOR method is also interesting- https://www.geeksforgeeks.org/find-the-missing-number/ 0 0 replyShare Please log in or register to add a comment.