Data Structured and Algorithm
Data Structured and Algorithm
Marking Scheme
Question 01
a. Define Data Structure? (02 Marks)
Data structure is the arrangement of data in a computer memory/storage.
b. Briefly describe primitive and abstract data types? give one example for each. (04 Marks)
Primitive Data Types:
Primitive Data Types are basic data types of a programming language. These refer to
two things: a data item with certain characteristics and the permissible operations on that
data. Ex: integer and float.
Abstract Data Types:
ADT is a specification of a mathematical set of data and the set of operations that can be
performed on the data. Ex: Stack, Queue, LinkedList, Tree
d. Write C++ code to create the following array and display it on the screen. (Hint: consider the
pattern of the data set when creating it) (06 Marks)
2 4 6 8 10 12 14
Void main()
{
int new _array[10]; (01 Mark)
for(int i= 0; i<7;i++) (01 Mark)
new_array[i] = 2i+2; (02 Mark)
for(int i=0;i<7;i++) (01 Mark)
cout<<”The array values are\n”<<new_array[i]; (01 Mark)
}
e. Write a C++ program that stores the given marks of the student and display the average mark
of each student. Use 2D array to store the subject marks.
Mathematics Science English
75 62 88
85 82 90
55 63 73
70 61 65
59 63 70
(07 Marks)
Question 02
a. Give single answer to a pointer? (02 Marks)
Pointer contains memory address of a particular type of data. In C++, we use * to declare
a pointer.
Ex: int* iptr; char* cptr
b. Creating a structure to store ID number, Name, and Gender of an Employee (05 Marks)
struct Employee{
int ID;
char name[20];
char gender;
};
d. Implementing the following Linked List operations using structural diagram (06 Marks)
i. initializeList()
ii. insertFirstElement(25)
iii. insertAtEnd(30)
v. deleteElt(25)
vi. insertAtFront(42)
e. Write the following C++ method which is used to insert an element at the end of a linked
list. Assume that the list nodes are created using Struct listNode
(06 Marks)
void LinkedList::insertAtEnd(int elt) {
}
Question 03
a. Compare Stack and Queue data structures? (04 Marks)
Stack uses LIFO method to insert and retrieve data
Queue uses FIFO method.
Stack use top to find the location
Queue use fron and rear both to find the location
b. Briefly describe the two (02) different implementations of Stack using suitable diagrams?
(04 Marks)
Array based implementation Linked List based implementation
Top= 4 Top
arr[4] 50
arr[3] 40
arr[2] 30
arr[1] 20
arr[0] 10
ii. push(15)
iii. y = topElement( )
y=15
iv. x= pop()
x=15
e. Write C++ code for the displayStack() method mentioned in the (Question(02) part d).
(05 Marks)
Void displayStack()
{
Cout<<”Stack\n”;
Cout<<”---------------”;
for(int i=top-1;i>=0;i--)
{
Cout<<”|”<<stack_array[i]<<”|”;
Cout<<endl;
}
}
Question 04
a. Define Tree data structure. (02 Marks)
A tree is a data structure that emulates a hierarchical tree structure with a set of
linked nodes.
b. Draw a Tree diagram using the following list of information. (04 Marks)
Root node: A
Leaf nodes: L, M, N, O
Level one nodes: E, F, G
c. Define the following terms related to tree data structure. (02*3=06 Marks)
i. Path between two nodes
Path between two nodes in a tree is a sequence of edges which connect those
nodes
ii. Height of a Tree
The height of a tree is the largest depth of any of its nodes
iii. Degree of a Node
The degree of a node is the number of its children
d. Differentiate the Binary Tree and Binary Search Tree using suitable diagrams (06 Marks)
Binary Tree Binary Search Tree
Binary Tree is a specialized form of tree which Binary Search Tree is a type of binary tree which
represents hierarchical data in a tree structure. keeps the keys in a sorted order for fast lookup.
Each node must have at the most two child nodes The value of the nodes in the left subtree are less
with each node being connected from exactly than or equal to the value of the root node, and
one other node by a directed edge. the nodes to the right subtree have values
greater than or equal to the value of the root
node.
There is no relative order to how the nodes It follows a definitive order to how the nodes
should be organized. should be organized in a tree.
It’s basically a hierarchical data structure that is a It’s a variant of the binary tree in which the nodes
collection of elements called nodes. are arranged in a relative order.
It is used for fast and efficient lookup of data and It is mainly used for insertion, deletion, and
information in a tree structure. searching of elements.
e. Insert the following data set to the Binary Search Tree. Show the implementation using
diagrams. (07 Marks)
30,12,9,18,33,45,16
1 mark for root
2 marks for level by level (2*3 = 6 marks)
Question 05
a. Briefly describe the enqueue and dequeue operations of the queue data structure using
diagrams (04 Marks)
The following steps should be taken to enqueue (insert) data into a queue −
b. Sort the following data set using Bubble Sort Algorithm. Clearly mention your steps.
9,11,85,3,48,71,15,8 (1Mark per each pass (Pass1-Pass6) - 06 Marks)
Pass 0 (Original)
d. State best case and worst-case efficiency for insertion and selection sort algorithms.
(04 marks)
Selection Sort
• Worst case performance: O(n2)
• Best case performance: O(n2)
Insertion Sort
• Worst case performance: O(n2)
• Best case performance: O(n)