13+-+Midterm+Exam+Review

13+-+Midterm+Exam+Review - Midterm Exam Review...

Info iconThis preview shows pages 1–11. 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

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: Midterm Exam Review “Super-Fast-Multiple- Lectures-in-One” EECS 280 Programming and Introductory Data Structures 1 Exam Details Exam locations See the CTools announcement No notes – no book – no electronics – only a writing tool 2 Exam Format Expected to be 5 Questions – 20 points each Topics you should definitely study: Correctness, testing ,and exception handling Recursion and Tail Recursion Pointers, arrays, and functions pointers Lists and Trees (project 2) Enum and Structs (project 3) 3 Outline 4 Procedural Abstraction Recursion Testing Function Pointers Arrays Pointers Structs and Enums Templates Exceptions Procedural Abstraction Specification Comments You can never change the abstraction (which includes function headers), but you can change your implementation . We use specifications to describe our abstractions. There are three clauses to the specification: REQUIRES: the pre-conditions that must hold, if any. MODIFIES: how inputs are modified, if any. EFFECTS: what the procedure computes given legal inputs. 5 Outline 6 Procedural Abstraction Recursion Testing Function Pointers Arrays Pointers Structs and Enums Templates Exceptions Recursion A convenient place for using stacks “Recursive” just means “refers to itself”. So, a function is recursive if it calls itself. Likewise, a problem is recursive if: 1. There is (at least) one “trivial” base or “stopping” case. 2. All other cases can be solved by first solving one (or more) smaller cases, and then combining those solutions with a simple step. 7 Recursion Example 1 (n == 0) n * (n-1)! (n > 0) n! = int factorial (int n) // REQUIRES: n >= 0 // EFFECTS: computes n! 1. { 2. if (n == 0) { 3. return 1; // ‘base case’ 4. } else { 5. return n*factorial(n-1); // ‘recursive 8 Recursion Another kind of factorial int fact_helper(int n, int result) // REQUIRES: n >= 0 // EFFECTS: returns result * n! { if (n == 0) { return result; } else { return fact_helper(n-1, result * n); } } int factorial(int num) // REQUIRES: n >= 0 // EFFECTS: returns num! { return fact_helper(num, 1); } Re-write the recursive version to use the same amount of space as is required by the iterative version (approximatel y). 9 With tail recursion, there is no pending computation at each recursive step, so we can re-use the activation record rather than create a new one. int fact_helper(int n, int result) // REQUIRES: n >= 0 // EFFECTS: returns result * n! { if (n == 0) { return result; } else { return fact_helper(n- 1,result*n); } } int factorial(int num) // REQUIRES: n >= 0 // EFFECTS: returns num!...
View Full Document

This note was uploaded on 01/19/2012 for the course EECS 280 taught by Professor Noble during the Winter '08 term at University of Michigan.

Page1 / 65

13+-+Midterm+Exam+Review - Midterm Exam Review...

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