CS 161 - Algorithms Homework 1, 25 Points
Due: Friday, October 5, 2012, 5:00pm
Please submit your solutions to the TA,
Michael Bannister
either in person at the beginning of the discussion section or
via email
-
5 points.
Problem R-1.6 from Goodrich-Tamassia.
-
5 points.
Problem R-1.13 from Goodrich-Tamassia.
-
5 points.
Given an array, A, describe an efficient algorithm for reversing A.
For example, if A=[3,4,1,5], then its reversal is A=[5,1,4,3].
You may only use O(1) memory
in addition to that used by A itself. What is the running time of your
algorithm?
-
5 points.
Suppose you are writing a simulator for a single-elimination
sports tournament (like in NCAA Division-1 basketball). There are n
teams at the beginning of the
tournament and in each round of the tournament teams are paired
up and the games for each pair
are simulated. Winners progress to the next round and losers
are sent home. This continues until a grand champion team is the final
winner. Suppose your simulator takes O(log n) time to process
each game. How much time does your simulator take in total?
-
5 points.
Given an array, A, of n-2
unique integers in the range from 1 to n,
describe an O(n)-time method
for finding the two integers in the range
from 1 to n that are not in A.
You may use only O(1) space in addition to the space
used by A.