cs1501-fall-08-test-1-answers

cs1501-fall-08-test-1-answers -...

Info iconThis preview shows pages 1–2. 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: ------------------------------------------------------------------------- CS1501 Test-1 ------------------------------------------------------------------------- Problem 1, Complexity, 20 points A. O(n^2) B. O(n log n) C. O(n^2) D. O(2^n) ------------------------------------------------------------------------- Problem 2, AVL Tree, 20 points 100 / \ 10 200 / \ / \ 5 50 150 300 ------------------------------------------------------------------------- Problem 3, Radix Search Trie, 20 points * / \ * * / / * * / / * * / \ \ A B * / \ R S ------------------------------------------------------------------------- Problem 4, Maximize Expression, 20 points Assume the expression is given as c-1...c-n: maximize(c-1...c-n) 1. If c-1...c-n are all integers, return c-1...c-n. 2. Set max = 0. 3. For each c-i: 1. If c-i is integer, continue. 2. If maximize(c1...ci-1) ci maximize(ci+1...cn) > max set max to that value. 4. Return max. Basically, divide the expression at each operator, maximize the left and right parts, combine using the operator, and return the largest value found. ------------------------------------------------------------------------- Problem 5, Binary Tree Proof, 20 points Proof by induction. This is trivial for depth 0. Suppose that the tree with depth k has 2^k leaves. Now, the tree of depth k+1 is just the tree of depth k where each leaf has two children. Thus, the tree of depth k+1 has 2*(2^k)=2^(k+1) leaves. ------------------------------------------------------------------------- ...
View Full Document

This note was uploaded on 01/27/2010 for the course CS 1501 taught by Professor Staff during the Fall '08 term at Pittsburgh.

Page1 / 2

cs1501-fall-08-test-1-answers -...

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

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