0 votes 0 votes PS : This question is similar to GATE2004-82, but different, so plz donot close it with duplicate Note, and help in answering Algorithms algorithms time-complexity made-easy-test-series + – Salazar asked Jan 31, 2018 • edited Mar 5, 2019 by Aditi Singh Salazar 459 views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply hs_yadav commented Jan 31, 2018 reply Follow Share first half part of the aaray is....filled with 1's and rest n/2 part is zero...then value of count would be n/2 ...and for remaing n/2 times evry we will get otexecute f(count)....therefor total time would be N/2*(n2)=> O(n3) 0 votes 0 votes MiNiPanda commented Jan 31, 2018 reply Follow Share @hs_yadav Alternate 1's and 0's can also give the same result na? Like f(1), f(2), f(3)...f(n/2) Which means 1^2 + 2^2 +... (n/2)^2 Sum of squares is of the form n*(n+1)(2n+1)/6 so it's O(n^3) . 0 votes 0 votes Salazar commented Jan 31, 2018 reply Follow Share @MINIPanda , yes i think alternative 1's and 0's give same answer - O(n^3), but the answer is given as O(n) :( , i think that's wrong 1 votes 1 votes Please log in or register to add a comment.