You are on page 1of 7

FINAL EXAMINATION

(SEPTEMBER 2021 SESSION)

ALGORITHM AND DATA STRUCTURE


CCS10403

STUDENT NAME :

PART A
Question 1
a)

i. Array is a pointer because it links to the initial member of the collection and its impossible to
initiate objects in array. Structure is not a pointer however the installation of structure objects is
possible.

ii. Because the items in an array are stored in a continuous way, we can easily determine the
address of any element in an array provided we know the element's base address. The entries in
the linked list, on the other hand, are not kept in a logical order. It is made up of several blocks,
each of which is represented by a node.

iii. In a stack, just one end of the list, called the top, is used for insertion and deletion. In queues,
insertion and deletion occur from opposite ends of the list. The deletion occurs from the
beginning of the list, whereas the insertion occurs at the back of the list.

iv. Because there is no such thing as a root node in a graph, a cycle might arise in the data
structure. There is a single root node in a tree data structure, but there will be no cycle.

v. Nodes in a Singly Linked have a data field and a next link field. A prior link field, as well as a data
field and a future link field, are all present in a Doubly Linked List. The only way to traverse a
Singly Linked List is to use the following node's link.

b)

i. struct car
{
char platNum[10];
char brand[10];
int modelYear;
}c1,c2,c3;

ii. struct song


{
char name[20];
char singer[20];
char genre;
}s1,s2,s3;
c)

 Traversal - access each element of the linked list


 Insertion - adds a new element to the linked list
 Deletion - removes the existing elements
 Search - find a node in the linked list
 Sort - sort the nodes of the linked list
PART B
Answer THREE (3) questions only.

Question 1

Question 2

Question 3

a)

b)
i. AB–CD+*Ef/*
Serial Number Expression Stack Postfix
0 (
1 A ( A
2 * (* A
3 B (* AB
4 - (* AB-
5 C (*( AB-C
6 + (*(+ AB-C
7 D (*(+ AB-CD
8 ) (* AB-CD+
9 * (* AB-CD+*
10 E (*( AB–CD+*E
11 / (*(/ AB–CD+*E
12 F (*(/ AB–CD+*Ef
13 ) (* AB–CD+*Ef/
14 ) AB–CD+*Ef/*
ii. 5, 20, 15, 25, 2, *, *, -, +
Serial Number Expression Stack Postfix
0 (
1 5 ( 5
2 20 ( 5,20
3 15 ( 5,20,15
4 - (- 5,20,15
5 * (-* 5,20,15
6 25 (-* 5,20,15,25
7 2 (-* 5,20,15,25,2
8 * (-* 5,20,15,25,2,*
9 + (+ 5,20,15,25,2,*,*,-
10 ) 5,20,15,25,2,*,*,-,+

Question 4

a)
i.

ii. 4, 9, 20, 32 is leaf node in the tree diagram above. There is 4 leaf node in total.
iii. Inorder: 4, 7, 8, 9, 12, 16, 20, 21, 26, 32
Preorder: 16, 12, 7, 4, 8, 9, 21, 20, 26, 32
Postorder: 4, 9, 8, 7, 12, 20, 32, 26, 21, 16

b)
i. (((a+b)*(c-d))–((e+f)*g))
Input String Postfix Expression Stack (Infix)
ab+cd-*ef+g*– b+cd-*ef+g*– a
ab+cd-*ef+g*– +cd-*ef+g*– ab
ab+cd-*ef+g*– cd-*ef+g*– (a+b)
ab+cd-*ef+g*– d-*ef+g*– (a+b)c
ab+cd-*ef+g*– -*ef+g*– (a+b)cd
ab+cd-*ef+g*– *ef+g*– (a+b)(c-d)
ab+cd-*ef+g*– ef+g*– ((a+b)*(c-d))
ab+cd-*ef+g*– f+g*– ((a+b)*(c-d))e
ab+cd-*ef+g*– +g*– ((a+b)*(c-d))ef
ab+cd-*ef+g*– g*– ((a+b)*(c-d))(e+f)
ab+cd-*ef+g*– *– ((a+b)*(c-d))(e+f)g
ab+cd-*ef+g*– – ((a+b)*(c-d))((e+f)*g)
ab+cd-*ef+g*– (((a+b)*(c-d))–((e+f)*g))

ii.

iii. -*+ab-cd*+efg
Question 5

a)
adjacency matrix:
A B C D E F G H
A 0 1 0 1 0 0 0 0
B 0 0 1 0 1 0 1 0
C 1 0 0 0 0 0 0 0
D 0 0 1 0 0 0 0 0
E 0 0 0 0 0 0 0 1
F 0 0 0 0 0 0 0 0
G 0 0 0 0 0 1 0 0
H 0 0 0 0 0 1 1 0

Adjacency list:

0 -> 1 -> 3
1 -> 2 -> 4 -> 6
2 -> 0
3 -> 2
4 -> 7
5 ->
6 -> 5
7 -> 5 -> 6

b)

You might also like