Sunteți pe pagina 1din 3

BINDURA UNIVERSITY OF SCIENCE EDUCATION

DEP ARTMENT OF COMPUTER SCIENCE


BACHELOR (HONS) DEGREE IN COMPUTER SCIENCE
JULY/AUGUST 2014 EXAMINATIONS
DATA STRUCTURES AND ALGORITHMS - CS213
2 HOURS 30 MINUTES

INSTRUCTIONS TO CANDIDATES
This paper carries six questions. You are required to answer all. Total marks are 100.

Question 1. Algorithm analysis.

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

Question 2. Implementation of List ADT. [25]

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>

+ IsEmptyO : boolean •. setNext(slg: SLlNode<T»: void

+ 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

11. Implement the method IsLeaf . Tree ,--------------i T [5]


class is implemented using a list of Tree
children representation. # root: T
# childs: List<Tree>
+Tree( root: T)
+ AddChild( t : Tree)
+ IsLeafO : bool
+ GetChild{i) : Tree
+ DeleteChilf(i)
+ GetRoot() : T
+ Preorder() : List<T>
+ PostorderO : List<T>
+ InorderO : List<T>

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.

Question 6. Searching and sorting.


For the Merge sort algorithm.

1. Write the algorithm in pseudocode [7]


11. Characterize the algorithm according to the running time, the space and the
idea behind the algorithm. You can also use a comparison with other sorting [8]
algorithms.

****END OF PAPER****

Page 3 of 3

S-ar putea să vă placă și