{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Offical+Review+Quesiton+W2009

Offical+Review+Quesiton+W2009 - CS115 Final Exam Review...

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

View Full Document Right Arrow Icon
CS115 Final Exam Review Session Solution last update Apr 19 th , 2009 copy right 2009 Oda_Ea gle Production, all right reserved C S115/116/125/134/135/136/241/240/341/343 Tutor odaea [email protected] 1. Write a recursive function sum-powers-one-half, which consumes a natural number n and computes 1+ ½ + ½ 2 + … + (½) n-1 + (½) n ( define ( sum-powers-one-half n) ( cond ( ( zero? n ) 1 ) ( else ( + ( expt 1/2 n ) ( sum-powers-one-half ( sub1 n ) ) ) ) ) ) 2. Write a function to return the largest key in a non-empty association list. ( define ( largest-key aal ) ( local ( ( define ( largest-key-help aal msf) ( cond ( ( empty? aal ) msf ) ( ( < ( first ( first aal ) ) ( first msf ) ) ( largest-key-help ( rest aal ) msf ) ) ( else ( largest-key-help ( rest aal ) ( first aal ) ) ) ) ) ) ( cond ( ( empty? aal ) empty ) ( else ( largest-key-help aal ( first aal ) ) ) ) ) ) 3. bsts can be used to store dictionaries as well. Write a function to return the largest key stored in a bst. Note: make use of the property of the bst. ( define ( largest-key-bst bst ) ( cond ( ( empty? ( tree-right bst ) ) ( tree-key bst ) ) ( else ( largest-key-bst ( tree-right bst ) ) ) ) )
Background image of page 1

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

View Full Document Right Arrow Icon
4. Consider finding the longest string which is stored as an associated value in a dictionary. Write this method for both implementations of dictionaries discussed in class.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}