0 votes 0 votes what is the stack space required by the given function? gate(n) { if(n!=0) return gate(n-1); else printf("gate2016"); } Algorithms space-complexity algorithms + – Pranav Gupta 1 asked Jan 18, 2016 edited Nov 29, 2023 by Hira Thakur Pranav Gupta 1 1.0k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
2 votes 2 votes Gate(n)=gate(n-1)+1 Space complexity is length of longest branch in tree.. Gate(n)-->gate(n-1)+.......gate(1) So space complexity =O(n) Pooja Palod answered Jan 18, 2016 Pooja Palod comment Share Follow See all 4 Comments See all 4 4 Comments reply Abbas commented Jan 19, 2016 reply Follow Share correct explaination nice 1 votes 1 votes Pranav Gupta 1 commented Jan 19, 2016 reply Follow Share whats the diff between these two functions gate1(n){if(n!=0)return gate1(n-1);elseprintf("gate2016");} gate2(n){if(n!=0)gate2(n-1);elseprintf("gate2016");} 0 votes 0 votes Abbas commented Jan 20, 2016 reply Follow Share i think no difference and in fact no use of return in that. 0 votes 0 votes Guneet03 commented Aug 18, 2020 reply Follow Share well explained! 0 votes 0 votes Please log in or register to add a comment.