Data Structure Worksheet
Data Structure Worksheet
Worksheet
Exercise 1
1. Define the following terms
a. Algorithm
b. Data structures
c. Complexity Analysis
d. Big-Oh Notation
2. Give a Big-Oh , in terms of n, of the running time of each of the following methods.
Exercise 2
1) For each of the following two
loops:
Write an expression f(n) that defines the number of assignment operations executed
by the code
State what the big-O complexity of the code is
Using definition 3, suggest reasonable values for c and N
1
i. for (cnt1=0, i=1; i<=n; i++)
for (j=1; j<=n; j++)
cnt1++;
2) For each of the following two loops, state what the big-O complexity of the code is:
3) The following conversation was overheard between a programmer and a computer scientist:
Programmer: I just wrote a really fast program to solve the WOW problem. I wrote it in
assembler, optimized every loop, and used every special instruction available on the Quadrium-7
processor.
Computer Scientist: How fast is it?
Programmer: Well, for 10 BogoUnits, it took 10 seconds to find the optimum, and for 11, it took
20 seconds, and for 12, it took 40 seconds, and for 13, it took 80 seconds, and so on.
Computer Scientist: But that's really slow! I have a O( n3 ) algorithm, which is much faster.
Programmer: Faster? I tried your program and it took 1000 seconds for 10 BogoUnits. How
can you claim your method is faster?
a. Estimate how long it would take the Computer Scientist's algorithm to solve the problem
for 20 BogoUnits.
b. Estimate how long it would take the Programmer's program to solve the problem for 20
BogoUnits.
c. What additional information do you need to decide which solution is in fact better for the
actual problem?