Professional Documents
Culture Documents
hw2 Questions
hw2 Questions
hw2 Questions
Homework 2
Due: 05/07/2019 (Tuesday) (11:55 PM)
ID: ________9243_________
a e
b c f
b c
d e f g
2. Assume that you should search a number in a list of n numbers. How can you take advantage of the fact
that the list is known to be sorted? Give separate answers for the following two cases.
[Note: If it is difficult to draw a diagram when doing homework, you can draw it on paper by hand. Then
take a picture of the paper and insert it.]
A B D
C E
4. Assume a binary tree with five vertices such as v1, v2, v3, v4, and v5. Determine the maximum
number of edges possible in the tree.
V = {v1, v2, v3, v4, v5}
|E|=|V|-1
E=5–1=4
Maximum number of edges = 4
5. (a) If your program takes n2 time and your classmate’s program takes n*log n time, whose program is
faster? Pick one between “You” and “Your Classmate”.
My program = n2
My classmate = n*log n
(b) If your program takes constant time and your classmate’s program takes log n time, whose program is
faster? Pick one between “You” and “Your Classmate”.
My program = constant time
My classmate = log n
(a) Present the basic operation of the algorithm. When you present the basic operation, you should
indicate the line number of the basic operation clearly.
Line # Operation
4 <
5 <
7 >
9 +
10 return
(b) Present the time complexity category of the algorithm among the eight most popular time
complexity categories we covered in the lecture.
(b) Present the time complexity category of the algorithm among the eight most popular time complexity
categories we covered in the lecture.
Linear Time O(n)