16 16 votes Consider the function $F(n)$ for which the pseudocode is given below : Function F(n) begin F1 ← 1 if(n=1) then F ← 3 else For i = 1 to n do begin C ← 0 For j = 1 to n – 1 do begin C ← C + 1 end F1 = F1 * C end F = F1 end [$n$ is a positive integer greater than zero] Solve the recurrence relation for a closed form solution of $F(n)$. Algorithms gate1992 algorithms recurrence-relation descriptive + – go_editor 4.6k views answer comment Share Follow Print See 1 comment 1 1 comment reply mohan123 commented Dec 4, 2019 reply Follow flag part a https://gateoverflow.in/586/gate1992-07a 2 2 replyShare Please log in or register to add a comment.
Best answer 15 15 votes Function F(n) begin F1 ← 1 if(n=1) then F ← 3 //if (n==1) then return 3 else For i = 1 to n do begin C ← 0 For j = 1 to n – 1 do //inner loop runs n-1 times outer loop runs for n times begin C ← C + 1 end //means C=n-1 F1 = F1 * C //means n-1 is getting multiplied n times so ans is (n-1)^n for n>=2 end F = F1 end Rajesh Pradhan answered Nov 26, 2016 • selected Nov 29, 2017 by rahul sharma 5 Rajesh Pradhan comment Share Follow See all 6 Comments 6 6 Comments reply akankshadewangan24 commented Jun 30, 2017 reply Follow flag got it 0 0 replyShare rahul sharma 5 commented Oct 7, 2017 reply Follow flag How can we say that F = F1 is related to else and not to the main begin end? 0 0 replyShare srestha commented Oct 19, 2017 reply Follow flag @Rajesh Can u chk this one plz C is incrementing each time, then how (n-1) is multipling n times? 0 0 replyShare rahul sharma 5 commented Nov 29, 2017 reply Follow flag @Srestha,inner loop will go from 0 to n-1 and will increment c.So will have n-1.So inner loop is doing nothing but assigning n-1 to c.Now we multiply n-1*1 for first iteration.And outer loop is running n times.so everytime c get n-1 and this n-1(c) is multiplied with previous f1 which is n-1 itself so now we get n-1*n-1 and so on.outer loop goes n times and inside it multiply n-1 with f1 1 1 replyShare Manu Thakur commented Dec 24, 2017 reply Follow flag this program is not recursive, how can we write and solve recurrence relation for it? 7 7 replyShare `JEET commented Jan 2, 2020 reply Follow flag Yeah same thing and its definitely not possible. They suppose to write the kind of formula. 0 0 replyShare Please log in or register to add a comment.
11 11 votes F(n) = (n-1)n When n>=2 F(n) = 3 When n == 1 Rdr Deva answered Jun 3, 2016 Rdr Deva comment Share Follow See all 2 Comments 2 2 Comments reply akankshadewangan24 commented Jun 19, 2017 reply Follow flag i think it would be o(n^2) 1 1 replyShare Nikhil gate 2020 commented Jan 31, 2020 reply Follow flag here ask about close form. Solve the recurrence relation for a closed form solution 1 1 replyShare Please log in or register to add a comment.