level: Recursion
Questions and Answers List
level questions: Recursion
Question | Answer |
---|---|
In the context of programming state what recursion is | A subroutine which calls itself |
What are the characteristics of a recursive subroutine | Must contain a stopping cndition (base case) For any input values other than teh stopping condition the routine must call itself Stopping condition must be reachable after a finite number if loops |
Why is recursion used Give an exmple | Sometimes recursion is the only/ best way in which to complete a problem Tree traversal algorithm |
What are the benifits of recursion | (Usually) fewer lines |
What are the downsides of recursion and why | Not very efficient on memory Every time a recursion is called, processor ha to remreber where it was in the program Remever the values of the varaibles beasue they are local to that copy of the fucnion |
What datastructures used for recursion | Stack |