HNDIT1211 Data Structures and Algorithms
HNDIT1211 Data Structures and Algorithms
I~ I
SUATE
S!~~!TITUfEOF ADVANCED
TECRNOLOGICAL
EDUCATION
(Established in the Ministry of Higher Education, vide in Act No. 29 of 1995)
ee
Instructions for Candidates: No. of questions: 05
Answer four (4) questions only. No. of pages : 04
Time: Two (2) hours
al
01.
I. What is an algorithm? Give two properties of an algorithm. (4 marks)
m
ii. What is the importance of studying data structures and algorithms? (3 marks)
iii. Differentiate linear and non -linear data structures using suitable examples.
co (4 marks)
IV. Write a function that determines whether a string is a palindrome (i.e. reads the same
backward and forward; e.g. "level"). (6 marks)
rin
v. Write a program to create following two matrices A, B and display the addition A+B
(Tota125 marks)
IT
02.
i. What does the acronym LIFO stand for? (1 mark)
AT
1
HNDIT 1 Data Structures and Algorithms 2015 ;tid semester
v. A stack can be stored in an array, using an integer index to record the next free position
in the array. Write algorithms to perform following operations for this stack
representation.
a. Pop 0 (3 marks)
c. Isfimpty t) (3 marks)
(Total 25 marks)
03.
ee
11. Briefly explain the following operations in Queue.
a. New / initializeQueueO
b. EnQueue / enQueue(x)
al
c. DeQueue / deQueueO
d. Empty? / islsrnptyt)
e. Full? / isFullO (5 marks)
m
iii. To implement a queue using circular array we need the following data fields:
An array - Que[] (for example an integer array of size 6)
co
The array index of the front item - front (initial value 0)
The array index of the rear item - rear (initial value 0)
The number of elements currently in the queue - size (initial value 0)
rin
The following figure shows the initial state of the array and other data.
o 2 3 4 5
Que
IT
AT
Draw state of the array and other data after executing each of the following operations.
a. enQueue(lO)
b. enQueue(17)
c. deQueueO
d. enQueue(3)
2
HNDIT 1 Data Structures and Algarithms 2015 :i'd semester
e. deQueueO (5 marks)
IV. Define a class Queue in C++ to implement the above queue with the given data
fields and following methods.
• Constructor to initialize data members
• Enqueue (x)
• Dequeue I) (9 marks)
ee
q.enQueue(9);
q.enQueue(7);
int x=q.dsQueuer);
q.enQueue(2);
q.enQueue(6);
al
q.enQueue(3 );
cout«q.deQueueO; (4 marks)
m
(Total 25 marks)
04.
co
1. Memory is allocated dynamically for linked list and trees. Briefly explain what
dynamic memory allocation is. (3 Marks)
List two (02) application areas of trees.
rin
11.
(2 Marks)
Ill. Suppose you have a singly-linked list declared as follows:
class MyList
{
IT
private:
struct ListNode II Declare a structure for the list
{
float value;
struct ListNode *next;
};
AT
\ .
!.
3
HNDIT 1 Data Structures and Algorithms 2015 r" semester
Use the above declaration to write C++ implementations to accomplish the
following tasks.
a. Add an element to the end of the list (4 marks)
b. To check whether the list is empty (3 marks)
c. Display list. (4 marks)
IV. Graphically explain the following tree operations to the given binary search tree.
a. Inserting a new node - (74) (3 marks)
b. Searching a given key value - (49) (3 marks)
c. Deleting a node with one child - (32) (3 marks)
ee
al
m (Total 25 marks)
co
05.
1. Define Best, Worst and Average case efficiencies. (6 marks)
rin
23,8,17,5,35,15
v. Consider the following sorted data set. Search 25 using binary search algorithm
indicating the sequence of array elements at each step. (6 marks)
10,15,25,30,33,34,36
(Total 25 marks)
4
HNDIT 1 Data Structures and Algorithms 2015 I'd semester