0 0 votes int recfunc( int n ) 2 { if( ) 3 return n; 4 int i=0; 5 while(i<100){ 6 printf ("HELLO"); 7 i=i+1; } 8 int a; 9 a=2* recfunc(n/2); 10 while(j<a){ 11 printf("BYE !"); 12 j=j+1; } 13 return a; } what is the recurrence relation for this? Algorithms + – hitendra singh 1.4k views answer comment Share Follow Print See all 10 Comments 10 10 Comments reply Shaik Masthan commented Sep 13, 2018 reply Follow flag what is j? 1 1 replyShare hitendra singh commented Sep 13, 2018 reply Follow flag j is a variable 0 0 replyShare Shaik Masthan commented Sep 13, 2018 reply Follow flag i mean what is initialization of j? 0 0 replyShare hitendra singh commented Sep 13, 2018 reply Follow flag j=o 0 0 replyShare Shaik Masthan commented Sep 13, 2018 reply Follow flag R(n) = R(n/2) + O(n/2) 0 0 replyShare hitendra singh commented Sep 13, 2018 reply Follow flag or rather its O(n) instead of O(n/2) is this O(n) term because of while loop 0 0 replyShare Shaik Masthan commented Sep 13, 2018 reply Follow flag yes.. 0 0 replyShare sakharam commented Sep 13, 2018 reply Follow flag Shaik Masthan Shouldn't it be R(n) = R(n/2) + thetha(n)? The while loop runs through 0 to a-1 = a iterations in total And if we check the value of a for some values of n, a refunc(n/2) returns n/2 And 2* n/2=n. So it should run for n/2 iterations and each iteration takes constant time. Correct me if I am wrong. 0 0 replyShare hitendra singh commented Sep 13, 2018 reply Follow flag but what about when n is odd , lets say n=5 so , 5/2 =2. Thus instead of 2.5 , you will get only 4 as 2*(5/2=2) correct me if am wrong. 0 0 replyShare sakharam commented Sep 13, 2018 reply Follow flag Shaik Masthan hitendra singh Now I get it, its closer to thetha(n/2) when the number is odd. :-D Thanks 0 0 replyShare Please log in or register to add a comment.