You are on page 1of 5

CSE 464: Homework 1.

0 Fall 2012
Dr. J. Karro karroje@muohio.edu

Due date: Thusday, Sept. 30 by 9:30 AM Submission Instructions: This assignment must be typed, and submitted electronically in pdf format. This assignment must be uploaded by Thusday, Sept. 30 by 9:30 AM. Your submission must have your name in the document (not just as part of the le name). Are argument should be clear, concise, and (of course) correct. You will loose points for sloppy writing, bad grammar, etc... Use of the Internet for solving these problems is strictly forbidden, and will be treated as an honor code violation. Please include your answers to all questions on your own paper. Dont forget to clearly specify your name and assignment number. Remember: You may work on these problems together but no notes may leave the meeting. Writeups are you own!

Problem 1 (20 points): Consider the following pseudocode: double pow(x, n): (1) if n == 0: (2) return 1 (3) else: (4) r = floor(n/2) (5) p = pow(x,r) (6) v = p * p (7) if n % 2 == 1: (8) v = v * x (9) return v Prove that for any integer n 0 and any number x > 0, pow(x, n) returns the value xn .

Problem 2 (20 points): Consider the following sorting algorithm: void StoogeSort(Array A, int i, int j) (1) if A[i] > A[j] (2) swap(A[i], A[j]) (3) if i < j-1 // t will be 1/3 the size of the array segment (rounded down) (4) t <-- floor( (j-i+1)/3 ) (5) StoogeSort(A, i, j-t) (6) StoogeSort(A, i+t, j) (7) StoogeSort(A, i, j-t) Prove that the call: StoogeSort(A, 0, n-1) sorts the array A (where A is an array of integers of size n 1).

Problem 3 (20 points): The Kingdom of Boragravia is planning on laying down a highway system to connect their n cities. However, being slightly odd, their ruler Nuggan has dictated that the system will conform to two rules: 1. Every pair of cities will be connected by exactly one direct route. 2. Every road will be a one-way. Initially the civil engineers designing the road system were worried some city might get cut-o. But as they experimented with dierent designs, they notice that every design they tried has a Hamiltonian Path: a path that visits every city exactly once without going the wrong way on any road. (Where that path starts and ends depends on the conguration, but it always seems to be one.) Prove that for any n 2 and any highway conguration conforming to these rules, there exists a Hamiltonian Path.

Problem 4 (20 points): This is a group problem. Through Niihka you have been assigned study groups. This problem is to be worked on as a group, but written up and submitted by a single person (designated by me). All students will get the grade of this writeup. For this problem, the usual group-work restrictions do not apply. That is: the person writing up the problem may walk away with notes about this problem. Submission instructions: This is to be submitted by the 1st person, alphabetically, in your group and is to be submitted as part of that students assignment, not as a separate assignment. Suppose there are n identical cars on a circular track. If you took all the gas from all the cars and put it into the one car, you would have exactly enough enough gas get the car around the track exactly once. Prove that there is at least one car that can complete a lap by draining the gas from other cars as it passed them.

You might also like