13+-+Midterm+Exam+Review

13+-+Midterm+Exam+Review - 10/23/11 1 Midterm Exam Review

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10/23/11 1 Midterm Exam Review Super-Fast-Multiple-Lectures-in-One EECS 280 Programming and Introductory Data Structures 1 Exam Details Exam locations See CTools announcement Exam time Wed 26 Oct, 7-8:30pm (7:10p start) Yes, the exam is only 80 minutes No notes no book no electronics only a writing tool 2 Exam Format Expected to be 5 Questions 20 points each 80 minutes in length (this is always the case in EECS 280) Topics you should definitely study: Correctness, testing ,and exception handling Recursion and Tail Recursion Pointers, C-Strings, 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 10/23/11 2 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 step 6. } 7. } 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 (approximately). 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!...
View Full Document

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

Page1 / 11

13+-+Midterm+Exam+Review - 10/23/11 1 Midterm Exam Review

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

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