Class Notes (1,100,000)
US (490,000)
Cornell (1,000)
CS (100)
CS 2110 (30)
Gries (30)
Lecture 8

CS 2110 Lecture Notes - Lecture 8: Circular Definition, Exponentiation, Palindrome

Computer Science
Course Code
CS 2110

This preview shows half of the first page. to view the full 2 pages of the document.
Lecture 8 - Recursion
oCircular definition: a definition that is circular!!
oRecursion in real life:
<noun phrase> = <noun>, or <adj><noun phrase> or <adverb><noun>
Factorial function
Family trees - great great great great… great grandmother
oTwo different questions
How does it execute?
How do we understand recursive methods?
oStack: List with at least two basic ops:
Push an element onto its top
Pop remove an element
oStack Frame
Method call: push a frame for call on stack. Assign argument values to
parameters. Execute method body. Use the frame for the call to reference
local variables and parameters.
End of method call: pop its frame from the stack; if it is a function leave
the return value on top of stack.
oTo execute a method Call:
Push a frame for the call on the stack
Assign argument values to parameters
Execute method body
Pop frame for call from stack, and push returned value on stack
oStack frame of sumDig(824):
oHow does it execute?
Its not magic!!! WOAAAAHHHH!! Trace the code’s execution using
method call algorithm, drawing the stack frames as you go.
oBut how does it work???
Requires a different approach
oBack to real world examples
Factorial: n! = n (n-1)!
find more resources at
find more resources at
You're Reading a Preview

Unlock to view full version