Algorithms_and_Data_Structures_05

Algorithms_and_Data_Structures_05 - Lecture 5 Computer...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science Algorithms and Data Structures Prof. Dr. Andreas Nüchter Research I, Room 105 Jacobs University Bremen http://www.nuechti.de andreas@nuechti.de Lecture 5
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 120 Last Lecture Proof that the program for computing the greatest common divisor (gcd) is correct Analyzing algorithms Input vs. input length Testing und running the program for several inputs Counting # of operations, e.g., modulo operations (gcd), comparisons (sorting/searching), additions and multiplications (math programs) Landau / „Big-Oh“-Notation
Background image of page 2
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 121 Last Lecture – “Big Oh”-Notation
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 122 Recursion in the Programming Language C (1) Example (similar to the recursive version of gcd): How does the stack looks like for factorial(3) ? For every stack frame we have: Here: No local varables One argument ( i ) One return value Every recursion creates a new stack frame int factorial (int i) { if (i == 0) { return 1; } else { return i * factorial (i - 1); } }
Background image of page 4
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 123 Recursion in the Programming Language C (2) i = 3 stack frame factorial(3) return value ?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 124 Recursion in the Programming Language C (3) i = 3 stack frame factorial(3) return value ? return value factorial(2) i = 2 ? stack frame
Background image of page 6
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 125 Recursion in the Programming Language C (4) i = 3 stack frame factorial(3) return value ? return value factorial(2) i = 2 ? stack frame stack frame factorial(1) return value i = 1 ?
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 126 Recursion in the Programming Language C (5) i = 3 stack frame factorial(3) return value ? return value factorial(2) i = 2 ? stack frame stack frame factorial(1) return value i = 1 ? stack frame factorial(0) i = 0 ?
Background image of page 8
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 127 Recursion in the Programming Language C (6) i = 3 stack frame factorial(3) return value ? return value factorial(2) i = 2 ? stack frame stack frame factorial(1) return value i = 1 ? stack frame factorial(0) i = 0 1
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Dr. Andreas Nüchter September 17, 2009 128 Recursion in the Programming Language C (7) i = 3 stack frame factorial(3) return value ? return value factorial(2) i = 2 ? stack frame
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 37

Algorithms_and_Data_Structures_05 - Lecture 5 Computer...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online