Algorithms_and_Data_Structures_05

# Algorithms_and_Data_Structures_05 - Lecture 5 Computer...

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

Computer Science Algorithms and Data Structures Prof. Dr. Andreas Nüchter Research I, Room 105 Jacobs University Bremen http://www.nuechti.de [email protected] Lecture 5

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

View Full Document
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
Algorithms and Data Structures Dr. Andreas Nüchter September 17, 2009 121 Last Lecture – “Big Oh”-Notation

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

View Full Document
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); } }
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 ?

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

View Full Document
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
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 ?

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

View Full Document
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 ?
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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/04/2010 for the course CS 320251 taught by Professor Nuechter during the Fall '09 term at Jacobs University Bremen.

### 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
Ask a homework question - tutors are online