Sie sind auf Seite 1von 3

FACULTY OF INFORMATION TECHNOLOGY

BACHELOR OF INFORMATICS
END OF SEMESTER EXAMINATION
BIF 1201: DATA STRUCTURES AND ALGORITHMS
DATE: 10th July 2015
Time: 2 Hours
Instructions
1.
This examination consists of FIVE questions.
2.
Answer Question ONE (COMPULSORY) and any other TWO questions.
Question ONE (30 marks) (Compulsory)
a) i. What is data structure?
ii. Write any four attributes of entity EMPLOYEE?
b) Consider figure 1 below. Use it to answer questions that follow.

Figure 1.
i.
Fill in the values for the depth and height in the table below.
Node
A
B
C
D
E
F
G
H
I
J
K
L
M
N
ii.

Depth

[2 marks]
[2marks]

[7 marks]

Height

Is this Tree a Binary Tree?

[1mark]
Page 1 of 3

iii.
iv.

Which node is the sibling of E?


Which node is the sibling of H?

[1 marks]
[1 marks]

c) Determine the Big-O notation for the following:


i.
n3 + n10
ii.
0.001n3 + n + 1.999n3
iii.
10n3 + 2n5+ 200n 2 + 30n3

[ 6 marks]

d) Which ADT or data structure is most appropriate for each of the following problems:
i.
You want to build an address book with entries in alphabetical order by last name.
ii.
You want to build a meeting reminder for a PDA that keeps track of events you schedule and
periodically checks the next event to sound an alarm to remind you of the next thing you need to
do.
iii.
You want to build a table of contents for a textbook. The textbook consists of chapters, chapters
consist of sections, and sections consist of subsections.
iv.
You want to build an email address miner that scans a hard drive looking for email addresses,
then sends them to a remote host.
[4 marks]
e) Write a delete method for linked lists with integer data that deletes the first occurrence of a given
integer from the list and returns the resulting list.
[6 marks]

Question TWO (15 marks)


a) Consider figure 2 below. Use it to answer questions that follow.

Figure 2.
i.
Whats the result of Preorder Traversal?
ii.
Whats the result of Inorder Traversal?
iii.
Whats the result of Postorder Traversal?

[2 marks]
[2 marks]
[2 marks]

b) Draw the binary search tree that results from inserting the integers 57, 85, 35, 9, 47, 20, 26,
99, 93, 10 starting with 57 and ending with 10.
[6 marks]
c) If we push \s", \w", \a", \t" onto a stack, what letter will be returned when we pop () from the stack?
[3 marks]
Question THREE (15 marks)
a) i.
What is binary search tree?
[2 marks]
ii.
Write an iterative (non-recursive) BinarySearchTree method named min that returns the
smallest value in a binary search tree.
[4 marks]
b) Given the mystery function below what is the value of mystery(7263)
Page 2 of 3

int mystery(int x) {
if (x < 10)
return 0;
else
return 1 + mystery(x/10);
}
c) List one advantage of a linked list over an array.

[2 marks]
[2 marks]

d) What does the following pseudocode compute when seeded with the root node of a binary tree?
Each node in the tree stores the value of an integer called key and references to the left and right
children. (Remember that unlike a binary search tree, the keys stored in external nodes of a binary
tree are NOT empty.)
.
int compute(Node u)
{
if isExternal(u), return u.key
L <- 0
R <- 0
if u.left is not null
L<- compute(u.left)
if u.right is not null
R <- compute(u.right)
return (L + R)
}
[3 marks]
e) If we enqueue \s", \w", \a", \t" onto a queue, what letter will be returned when we dequeue() from
the queue?
[2 marks]
Question FOUR (15 marks)
a) i. What is an ADT?

[2 marks]

ii. What are two advantages of making a type abstract?


b) Prove that the following statement is false n1.5 = O(n log n).

[2 marks]
[5 marks]

c) Recall that in a binary tree, a node may have 0, 1, or 2 children. In the following questions about
binary trees, the height of a tree is the length (number of edges) of the longest path. A tree consisting
of just one node has height 0.
i.
What is the maximum number of nodes in a binary tree of height d?
ii.
What is the minimum number of nodes in a binary tree of height d?
iii.
What is the maximum height of a binary tree containing n nodes?
[6 marks]
Question FIVE (15 marks)
a) i. Which data structures can store homogeneous data elements?
[2 marks]
ii.
When new data are to be inserted into a data structure, but there is no available space, this
situation is usually called?
[2 marks]
iii.
What is the name of a data structure where elements can be added or removed at either end but
not in the middle?
[2 marks]
iv.
What is Deque?
[2 marks]
b) What is linked list? Write an algorithm for inserting an ITEM in the beginning of the linked list?
[7 marks]

Page 3 of 3

Das könnte Ihnen auch gefallen