14. Sorting - ENGR 101, Section 100, Fall 10 M. Wellman 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ENGR 101, Section 100, Fall 10 M. Wellman 1 Recursion and Sorting ENGR 101, Lecture 14: 1 Nov 10 Announcements Exam 2 on Wed 3 Nov (6pm) watch for room announcements Open book/notes, same style/rules as Exam 1 Samples posted, review in Wed lecture Project 6 due Wed 10 Nov (9pm) last C++ assignment for the term (two more programming projects in Matlab) ENGR 101, Section 100, Fall 10 M. Wellman 2 Factorial n ! = 1 if n = 0 n ( n 1)! otherwise Recursive definition Relatives x is a relative of y iff: x is y s parent x is y s child x is y s spouse x is a relative of a relative of y Recursive definition ENGR 101, Section 100, Fall 10 M. Wellman 2 Factorial n ! = 1 if n = 0 n ( n 1)! otherwise Recursive definition Relatives x is a relative of y iff: x is y s parent x is y s child x is y s spouse x is a relative of a relative of y Recursive definition ENGR 101, Section 100, Fall 10 M. Wellman 3 Cousins x and y are first cousins iff they share a grandparent x and y are Nth cousins iff their respective parents are (N1)st cousins What are siblings? Recursive Definitions General Definition of a concept refers to the concept itself Programming Definition of a procedure invokes the procedure itself (ditto for functions) ENGR 101, Section 100, Fall 10 M. Wellman 4 Divide and Conquer A common algorithmic approach Three steps: Divide : Split problem into subproblems. Conquer : Solve subproblems. Combine : Merge subproblem solutions into overall solution. Recursive : Solution to problem based on solution to subproblems Back to Factorial Can write a function directly corresponding to mathematical definition: int factorial (int n) { if (n == 0) return 1; else return n * factorial(n-1); } n ! = 1 if n = 0 n ( n 1)! otherwise ENGR 101, Section 100, Fall 10 M. Wellman 5 Tracing Factorial factorial (4) return 4 * factorial (3) factorial (3)...
View Full Document

This note was uploaded on 05/25/2011 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 17

14. Sorting - ENGR 101, Section 100, Fall 10 M. Wellman 1...

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

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