361spr11

advertisement
CS 361, Introduction to Data Structures
Final Exam Spring 2011
Open book, open notes, but you are not to communicate with anyone else in any manner
concerning this exam during the exam period. The ODU Honor code is in effect for the duration.
You are to solve no more than 3 of the following problems in C++, using the STL library; each
code should run stand-alone as a simulation. You can develop the code in any environment but
they should compile using Codeblocks, DEV or g++. Submit your solutions as a single zipped
file via the web-submit utility
1. Imagine that there are processes that are being generated at random intervals, each
process has an id (0001 to 9999) and in addition each process has a complexity score that
is directly proportional to the product of its required memory and its expected run time.
We can treat the complexity score (c >= 0) as a random value with a mean of 5 and a
standard deviation of 1. As the processes are generated they are placed into a queue of
length q (user input). Processes are removed from the front of the queue after they have
been in the front for c time steps. IF a process is generated and the queue if full then the
overload is placed in a separate priority queue with the lowest c score given the highest
priority. When room is made in the process queue, it is refilled from the priority queue.
Generate a simulation of this process handler.
Time
1
2
3
4
Queue
<>
<P1, P2>
<P1,P2,P3>
<P2,P3>
New Processes P-id(c)
P1(3) P2(1)
P3(4)
None
P5(1)
Priority Queue
<>
<>
<>
22
23
24
etc
<P44(2), P45, …P54>
<P44(2), P45,…P54>
<P44(2) P45, P54>
<P45, P54, …P54, P56>
P55(3), P56(1)
P57(2)
None
None
<>
<P56, P55>
<P56, P57, P55>
<P57, P55>
2. Imagine a chess board (8x8) with one knight on it. The knight is placed at location row 0
and column 1, (standard position), implement an algorithm that will allow the knight to
move around the board randomly until ALL locations have been visited.
3. This is an experimental question, please implement the following code fragment in a fully
functional C++ code. Given ints j, n, and T: where n is user input, the functions b is
return type bool, and both p and q each return a time cost . The value T stores the
cumulative sum of those costs.
i. For(j=0; j<n; j++)
ii. {If b(j) {q(j);}
iii. Else {
1. If(b(j+1){q(j-1);}
2. Else {p(j+3);}
3. }
iv. }
Where b(i) takes i+2 seconds and (on average) the function b( ) returns true 50% of the
time
q(i) takes i seconds
p(i) takes i+1 seconds
Create a graph showing best, average, and worst case T scores for your code in number 5
above for n = powers of 2 from 21 to 216. If there are any results you cannot provide be
specific as to the reason.
4. Using your mountain project source code as a starting point, you are to write a
code that randomly chooses one of the quadrilaterals on the surface of your
mountain, this will be the entrance to your cave. A line segment representing that
tunnel beginning at the centroid of that quad travels a distance equal to the average
of the three sides of that triangle in the direction normal to that surface INTO the
mountain. You should store this segment as a vector beginning at the centroid in
the form v = xmi + ymj + zmk . These xm, ym, and zm values will be referenced many
times. At this point what happens is determined by the following table.
Probability
0.10
0.70
Event
Continue straight for the same distance as before
Tunnel changes direction by generating a new random
vector direction such that when
.10
.10
v=ai + bj + ck
-xm < a < xm
-ym < b < ym
-zm < c < zm
The tunnel splits in two by generating two different
vectors in the same way as the change of direction
table above
Current tunnel branch terminates
As the tunnel splits then there is an additional branch that must be explored. If at any time a
branch of the tunnel intersects the surface of your mountain that branch should terminate
(hint: consider the 2-d projection of your quads as seen from above).
Save your tunnel system as a set of line segments in a separate data file then plot them with
your mountain. They should automatically appear as a different color.
5. Create a class gene that contains a sequence of 4 amino acids (represented by chars)
Generate a linked list of length L of class Gene, this is a protein. Generate a second
linked list of length 10 < L2 < L. Search for a matching sequence of at least 4 genes that
can be found in both proteins. If none exist state so. If they do exist display at what index
they can be found in each protein.
Download