Download - Lecture 26 - Dynamic Graphics Project
APS105Winter 2012
Jonathan Deberjdeber -at- cs -dot- toronto -dot- edu
Lecture 26March 21, 2012
2
Today
• Debugging
• Recursion
Debugging
3
All Software Has Bugs
4
• Unavoidable
• Techniques to help avoid them, and to help find them
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
Brian Kernighan
5Image: Naval Historical Center
Grace Hopper’s Lab Notebook
Types of Bugs
• Code that does not do what it’s supposed to
• Code that does what it’s supposed to, but that isn’t the right thing to do
• May be a bug in the design
6
Diagnosing Bugs• Need to be precise
7
My program doesn’t work.
My program crashes with a Segmentation Fault when given the input !.
My program crashes with a Segmentation Fault on line !"# when given the input !.
My program crashes.
My program crashes with a Segmentation Fault.
My program crashes with a Segmentation Fault on line !"# when given the input ! because I’m never storing a pointer in $%&'(.
Fixing Them
• In order to fix a bug, you have to find it
• Finding it is usually the hard part
8
Diagnosing Bugs
• Manual )&%*($+, statements
• Debugger
9
Knowing Where You Crashed
• Often that’s enough
• A debugger will tell you which line
• Need to compile with -. flag (.//0-12330-. ...)
10
40.560'782&9
+.56,0&8*
!"#$%&'()*!+,-+./0-1,/11!*22(#3(#445"$$'(676666666666666666676666666866666"#9(:&($;<#5"(=&>?@ABCD(#3($;<#5"EF'GG(((((((((((HI(>(&J
Crash is on this line
!"#$%&'(• Add in )&%*($+, statements to tell you what’s going on
11
%*(0/&92(9:%'(;.&2<=;>+/?2&0&;>@AB0/?2&0'C<6;3B000000000000000%*(0D2389B0%*(0<2EF2389B0%*(0<2E=;>G9*.(?,H00000005;86390)9&/9*(2.90I0+5;8639,D23890J0<2EF2389K000000%*(0*8<LC<6;3'0I0&%*(+)9&/9*(2.90M0<2E=;>G9*.(?,K000000)&%*($+NO&2>%*.0P50;8(0;$0P502'0P50'C<6;3'Q0R*NB0000000000000D2389B0<2EF2389B0*8<LC<6;3',K00QQQ
12
S59$%*90OTUVWWXYW0$23'9
%$0+OTUVWWXYW,H00)&%*($+NZ&%*(%*.0&;>0P5Q0R*NB0%,K[
13
Debugger• “Breakpoints” let you stop your program at a specific line
• Allows you to step through your code
• Step Over (go to the next line, skipping function calls)
• Step Into (go to the next line, entering function calls)
• Step Out (go back to the caller)
• Displays values of variables
• .56 is .//’s debugger, they’re also built-in to IDEs
14
The remaining 10% of the code accounts for the other 90% of the development time.
Tom Cargill
The first 90% of the code accounts for the first 90% of the development time.
Recursion
15
In order to understand recursion,you must first understand recursion.
Anonymous
16
Recursion
• A problem defined in terms of itself
17
If I need to put away a pile of books:
Put away the first bookPut away the remaining pile
If I need to climb a flight of stairs:
Climb one stair
Climb the remaining flight of stairs
If I need to calculate *\Multiply *0M0+*0-0!,\
18
19
20
Recursion
• A problem defined in terms of itself
• No more (or less) powerful than loops (iteration)
21
Put away the books one at a time
Climb the stairs one at a time
Start at ! and multiply it by each number up to *
If I need to put away a pile of books:
Put away the first bookPut away the remaining pile
If I need to climb a flight of stairs:
Climb one stair
Climb the remaining flight of stairs
If I need to calculate *\Multiply *0M0+*0-0!,\
22
If I need to put away a pile of books:
Put away the first bookPut away the remaining pile
If I need to climb a flight of stairs:
Climb one stair
Climb the remaining flight of stairs
If I need to calculate *\Multiply *0M0+*0-0!,\
22
What happens when I run out of books?
What happens when I get to the top?
When do I stop?
If I need to put away a pile of books:
Put away the first bookPut away the remaining pile
If I need to climb a flight of stairs:
Climb one stair
Climb the remaining flight of stairs
If I need to calculate *\Multiply *0M0+*0-0!,\
23
Recursion
• A problem defined in terms of itself
• No more (or less) powerful than loops (iteration)
• All recursive problems must have a “base case”, which is a trivial version of the problem
24
If there are no more books, we’re done
If we’re at the top, we’re done
If * is !, *\ is !
If I need to put away a pile of books:
Put away the first bookPut away the remaining pile
If I need to climb a flight of stairs:
Climb one stair
Climb the remaining flight of stairs
If I need to calculate *\
Multiply *0M0+*0-0!,\
Otherwise
Otherwise
Otherwise
25
Recursion and Programming
• A recursive function is a function that calls itself
• That’s it!
• Provides another way to iterate
• No more (or less) powerful than loops
• Similar to $;& loops vs. >?%39 loops
• Why bother? Makes some algorithms simpler
Factorial
26
*\0%'0*0M0+*0-0!,0M0+*0-0",0M0QQQ0M0"0M0!
%*(0$2/(;&%23X(9&2(%D9+%*(0*,H0000%*(0&9'83(0I0!K00000000$;&0+%*(0%0I0!K0%0]I0*K0%^^,0000H00000000&9'83(0MI0%K0000[00000000&9(8&*0&9'83(K[
Factorial
27
+*0-0!,\
+*0-0",\
*\0%'0*0M0+*0-0!,0M0+*0-0",0M0QQQ0M0"0M0!
*\0%'0*0M0+*0-0!,\
Factorial
28
%*(0$2/(;&%23=9/8&'%D9+%*(0*,H00000000%*(0&9'83(K000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000000&9(8&*0&9'83(K[
*\0%'0*0M0+*0-0!,\
Factorial
28
%*(0$2/(;&%23=9/8&'%D9+%*(0*,H00000000%*(0&9'83(K000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000000&9(8&*0&9'83(K[
%$0*0_0!
%$0*0II0!
*\0%'0*0M0+*0-0!,\
*\0%'0!
29
%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K000000%$0+*0II0!,00H0000&9'83(0I0!K00[000000000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K
00&9(8&*0&9'83(K[
30
%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K000000%$0+*0II0!,00H0000&9'83(0I0!K00[0000000000
00&9(8&*0&9'83(K[
00&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K
0093'900H
00[
Recursive Structure
• Steps for writing a recursive algorithm:
• Figure out the recursive structure of the problem
• Must be able to break the problem into two parts
• Each must be either trivial or a smaller version of the same problem
• Figure out the trivial base case(s)
• Convert pseudocode to C
31
Fibonacci
32
`+*,0I0`+*-!,0^0`+*-",
`+a,0I0aB0`+!,0I0!
aB0!B0!B0"B0bB0cB0#B0!bB0"!B0bdB0ccB0#eB0!ddB0"bbB0bffB0g!aB0
e#fB0!cefB0"c#dB0d!#!B0QQQ
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 & &"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8
& &"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 &
&"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 &
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 & &"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8
& &"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 &
&"73
33
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[
6 8 K ? B
&L8 &
34
%*(0$%6;*2//%=9/8&'%D9+%*(0*,H0000%*(0&9'83(K
0000%$0+*0II0a,0000H00000000&9'83(0I0aK0000[000093'90%$0+*0II0!,0000H00000000&9'83(0I0!K0000[000093'90000H00000000&9'83(0I0$%6;*2//%=9/8&'%D9+*0-0!,00000000000000000000000^0$%6;*2//%=9/8&'%D9+*0-0",K0000[00000000&9(8&*0&9'83(K[
35
%*(0$%6;*2//%X(9&2(%D9+%*(0*,H00%*(0$%6h*0I0!K0000000JJ0$%6+!,00%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,
00$;&0+%*(0%0I0"K0%0]I0*K0%^^,00H0000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K000000000000$%6h*i%*8'!0I0$%6h*K0000$%6h*0I0*9E(j9&<K00[0000000000%*(0&9'83(K000000%$0+*0II0a,00H0000&9'83(0I0$%6h*i%*8'!K00[0093'900H0000&9'83(0I0$%6h*K00[000000&9(8&*0&9'83(K[
%*(0$%6=9/8&'%D9+%*(0*,H00%*(0&9'83(K
00%$0+*0II0a,00H0000&9'83(0I0aK00[0093'90%$0+*0II0!,00H0000&9'83(0I0!K00[0093'900H0000&9'83(0I0$%6=9/8&'%D9+*0-0!,00000000000000^0$%6=9/8&'%D9+*0-0",K00[000000&9(8&*0&9'83(K[
Tracing Functions
36
• A key to understanding recursion is tracing the function calls
%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K0000000%$0+*0II0!,000H000000&9'83(0I0!K000[000000093'9000H000000&9'83(0I0*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000[0000000&9(8&*0&9'83(K[
<2%*+,
M#F'
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ
<2%*+,
M#F'
&'
5"$<P3'
B
$2/=9/8&'%D9+,
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ
<2%*+,
M#F'
&'
5"$<P3'
B
$2/=9/8&'%D9+,
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((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3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ
S
<2%*+,
M#F'
5"$<P3'
$2/=9/8&'%D9+,
KB
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ
S
KB
<2%*+,
M#F'
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ
KB
<2%*+,
M#F'
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ KB
<2%*+,
M#F'
:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ
:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ KB
38
Print out a line of n stars *0I0! M*0I0c MMMMM
D;%50)&%*(=;>+%*(0*,H0000$;&0+%*(0%0I0aK0%0]0*K0%^^,0000H00000000)&%*($+NMN,K0000[[
39
MMMMM
{
{
row of * stars
row of *0-0! stars
*0I0!
*0I0c
! star{
Print out a line of n stars M
MMMMM