Documente Academic
Documente Profesional
Documente Cultură
INSTRUCTIONS TO CANDIDATES
This paper carries six questions. You are required to answer all. Total marks are 100.
a. Arrange the following expressions by growth rate from slowest to fastest. [5]
1. n2+nlogn
II. 4n2
111. \Og2 n
IV. 2n
V. 4n + Sn2 + 6n4
b. Give a big-O characterization of the following algorithm. [10]
Algori1:hIll Ex2(A, 'I)
Inpu1: an DITay _Y 01- rt int e g evs
Ou1:pu1: the s urrr of the elernents at even cells in A
Begin :::'.
s = A[OI
t-or i= :2 1:0 " - 1 s1:ep ::2
s = S -I- Ar.rl
end f-ol-
l.-e1:urn .v
End
Implement the class SinglyLinkedList a linked list with header and tail references.
I hea~
~
551~12 ~711 o-Hf.
Page 1 of 3
# header: SLLNode<T> T I
«interface» # tail: SLlNode<T> SllNode
ILista +SlnglyLinkedListQ - data: T
- - - + LengthQ : int - next: NodoSE<T> 'sctc .-en(!:' 0' t Y' r,~'r)
1/... + Insert( T x, int i ) : void •. SLLNode( data: T, next: NodoSE<T»
+ Add( T x ) : void •. getOataO :T
+ GetElement( int i ) : T •. setData( data: T ): void
+ Delete( int I) :void •. getNextO : SLLNode<T>
+ Search( T x) : int
+ Reverse()
[20]
Question 3. Stacks and Queues.
The array-based stack implementation introduced in our lectures uses a fixed length array. As a
result, it is possible for the stack to become full. Implement the class StackDA this class uses a
dynamic array that grows and shrink according his state. The array start with a minimum size,
this size is a parameter of its constructor. If the array becomes full then Push double the length
of the array. If the number of elements in the array is less than its half and the number of
elements is less than minimum defined then the array is restored to its minimum size.
Question 4. Trees.
i. For the following binary tree write the preorder, postorder and inorder traversals. [10]
o
Page 2 of 3
[10]
Question 5. Graph.
Add the method ConectWithAll to a GraphAM (Graph using Adjacency Matrix and Vertex
List) class. The ConectWithAli method receive a vertex and connect this vertex with the rest
of vertices in the graph.
Example:
The image in the left show a graph A. The image III the right shows the result of
ConectWithAli with vertex "C" as a parameter.
****END OF PAPER****
Page 3 of 3