{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

finalc - CS 373 U Makeup Final Exam Questions(August 2 2004...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 [1] A [2] 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 off the left
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern