Lecture14_midtermReview

# Lecture14_midtermReview - Lecture 14 Midterm review Z...

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

Lecture 14 Midterm review Z. Morley Mao [email protected] Monday March 3 , 2008 1

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

View Full Document
Administrivia Midterm reminder: March 6, Thursday 7PM-8:30PM. No lecture on March 5, Wed. Email me ([email protected]) if you cannot  make it. People taking alternate midterm should have  received email from me Many office hours James: today 4pm - 10pm (SHAPIRO  BASEMENT) Alan: today 1:30 - 4 pm CSE West Morley: Tuesday 10-noon 4629 CSE 2
Material covered by the midterm Project 1 and Project 2 All lecture material up to and including   lecture 9 on exceptions Key topics (no particular order) Arrays, pointers C-strings Recursions, trees, lists Pass by reference, by value Function pointers Exceptions Testing 3

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

View Full Document
Sample midterm #5  Recursive String Processing Mountain word: its characters are strictly  increasing up until the middle character  and strictly decreasing afterwards: E.g., house Write a tail-recursive function isMountain,  taking in any C-string of zero or more  lower-case letters. 4
1. List and tail recursion Given a list_t, write a tail-recursive function List_t every_other(list_t list) Returns a list containing the 1 st , 3 rd , 5 th , etc.  elements of the original list in the order they  appear there. Solution: uses a helper function, need two  extra parameters, a list that holds the results  of intermediate computations and a boolean  to represent whether to keep the current first  element. 5

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

View Full Document
1. List and tail recursion list_t  every_other(list_t list) { return every_other_h(list, list_make(), true); } list_t  every_other_h(list_t list, list_t so_far, bool  odd_elt) { if(list_isEmpty(list)) return(so_far); if(odd_elt)      so_far =  append (so_far,      list_make(list_first(list),  list_make())); return every_other_h(list_rest(list), so_far, ! 6
2. Trees Given a tree_t t, write a recursive function  that returns true if and only if there is a  path from the root of t to a leaf node that  does NOT contain 0.  Define an empty tree to have such a path. 7

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

View Full Document
Solution to nonzeropath(tree_t t) bool nonzeroPath (tree_t t) {      if(tree_isEmpty())  return true;      if(tree_elt(t) == 0) return false;      return (nonzeroPath(tree_left(t)) ||        nonzeropath(tree_right(t))); } This solution is buggy, because for any tree that  contains a path reaching a non-leaf node with one  child, as long as that path contains no zeros, it will  return true! E.g., for the tree to the right, it should return false,
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/04/2008 for the course EECS 215 taught by Professor Phillips during the Winter '08 term at University of Michigan.

### Page1 / 23

Lecture14_midtermReview - Lecture 14 Midterm review Z...

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

View Full Document
Ask a homework question - tutors are online