0% found this document useful (0 votes)
7 views

Csifinal 5

Uploaded by

michaelberliant
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Csifinal 5

Uploaded by

michaelberliant
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Throughout this exam, unless specified, every logarithm is in base 2.

Question 1 [ 2 points] What are the running time complexities of the algorithms in the following
pseudo-code fragments (in big-Oh notation)? Choose the best big-Oh estimate as a function of n,
the size of the input data.

1+1+2+2
nztn
Algorithm AlgoI(A) + .
.
it
Let A be an array of size n
for i 0 to (n 1) do
for j 0 to n/2 do
(
n⇒
a 2 l + 2 t.it
A[i] j*j
end for
( i 121
nz
+ m

if
=

(
.

end for -
.

a) O(n log n) 0b) O(n2) c) O(n3 ) d) O(2n ) e) O(n) f ) O(log n)

Algorithm AlgoII(A) +3 + . .
.
+ ( Mti )
Let A be an array of size n

@
the the O ( n4j
iyz
for i 0 to (n ⇤ n) do

1+2
)
= i =
for j 0 to i do
A[j mod n] j+A[j mod n]
LAGAN tent
/
end for
Mount
end for COPYRIGHT
b) O(n2 )
0c) O(n )
4
a) O(n log n) d) O(2n ) e) O(j mod n) f ) O(n2n )

Question 2 [2 points] What is the worst case big-Oh complexity of inserting an element in the
following data structures (as a function of the number n of elements stored in the data structure):
.

1. An unsorted doubly linked list:


a) O(1) b) O(log n) c) O(n)
O d) O(n log n)

2. An AVL binary search tree:


0 O(log n) c) O(n)
a) O(1) b) d) O(n log n)

3. A Hash table where collisions are resolved with linear probing:


a) O(1) b) O(log n) 0 c) O(n) d) O(n log n)

4. A 2-4 tree:
a) O(1) 0 b) O(log n) c) O(n) d) O(n log n)

You might also like