This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 373 U Makeup Final Exam Questions (August 2, 2004) Spring 2004 Answer four of these seven problems; the lowest three scores will be dropped. 1. Suppose we are given an array A [1 .. n ] with the special property that A  A  and A [ n- 1] A [ n ]. We say that an element A [ x ] is a local minimum if it is less than or equal to both its neighbors, or more formally, if A [ x- 1] A [ x ] and A [ x ] A [ x + 1]. For example, there are five local minima in the following array: 9 7 7 2 1 3 7 5 4 7 3 3 4 8 6 9 We can obviously find a local minimum in O ( n ) time by scanning through the array. Describe and analyze an algorithm that finds a local minimum in O (log n ) time. [Hint: With the given boundary conditions, the array must have at least one local minimum. Why?] 2. Consider a random walk on a path with vertices numbered 1 , 2 , . . . , n from left to right. At each step, we flip a coin to decide which direction to walk, moving one step left or one step right with equal probability. The random walk ends when we fall off one end of the path, either by moving left from vertex 1 or by moving right from vertex n . In Midterm 2, you were asked to prove that if we start at vertex 1, the probability that the walk ends by falling...
View Full Document
This note was uploaded on 10/14/2011 for the course ECON 101 taught by Professor Smith during the Spring '11 term at West Virginia University Institute of Technology.
- Spring '11