0% found this document useful (0 votes)
22 views12 pages

Hllo

The document outlines the syllabus and examination structure for a B.Sc. Degree in Data Structures using C++ for the October 2019 semester. It includes definitions, examples, algorithms, and operations related to various data structures such as arrays, linked lists, stacks, queues, trees, and hashing. Additionally, it covers topics like search algorithms, file organization, and sparse matrices, providing a comprehensive overview of data structure concepts and implementations.

Uploaded by

abdulhakkim12a02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views12 pages

Hllo

The document outlines the syllabus and examination structure for a B.Sc. Degree in Data Structures using C++ for the October 2019 semester. It includes definitions, examples, algorithms, and operations related to various data structures such as arrays, linked lists, stacks, queues, trees, and hashing. Additionally, it covers topics like search algorithms, file organization, and sparse matrices, providing a comprehensive overview of data structure concepts and implementations.

Uploaded by

abdulhakkim12a02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

QP CODE: 19102230

B.Sc. Degree (CBCS) EXAMINATION, OCTOBER 2019


Third Semester
CORE COURSE-CS3CRT08
Data Structure using C++
Scheme
Part A
1. The data structures that are derived from primitive data structures are called
non-primitive data structures. These data types are not actually defined by the
programming language but are created by the programmer.
Example: Arrays, lists and files (Definition 1 mark, Example 1 mark)
2. Linear search sequentially checks each element of the list for the target value
until a match is found or until all the elements have been searched. Binary search
compares the target value to the middle element of the array. If they are an
unequal, that half array is eliminated and the search continues on the remaining
half until it is successful. Linear search can be performed in an unsorted array but
a binary search is possible only in a sorted array
(2 marks)
3. Infix, Postfix and Prefix notations are three different but equivalent ways of
writing expressions. If the operators are written in-between their operands it is
an infix expression. Eg: X + Y. If the operator is written before the operands it is
called prefix expression. Eg:+XY and if the operator is placed after the operands it
is called a postfix expression. Eg: XY+ (definition 1 mark, example 1 mark)

4. Double Ended Queue is also a Queue data structure in which the insertion and
deletion operations are performed at both the ends (front and rear).
(1 mark)
Two types of deques are there. They are input restricted deque(insertion can be
made only at one end, but deletion from both ends ) and output restricted
deque(deletion can be made at only one end, but insertion from both ends).
(1 mark)
5. The NULL pointer is used to denote the end of a memory search or processing
event. In linked list a NULL pointer is a pointer that does not point to any node,
object or function. The final node in the linked list does not point to a next node
and so the value is set to NULL.
(2 marks)
6. Step 1: Copy the address of first node i.e. head node to some temp variable say
temp.
i.e. temp = head
Step 2 : Move the head to the second node of the linked list
i.e. head = head->next.
Step 3 : Free the memory occupied by the first node
ie. delete(temp) (Steps 1 mark, codes 1 mark)
7. Allocating a variable implies reserving some memory for that variable. In C and
C++ if a variable is allocated but not assigned, it is said to have a "garbage value",
that is, some information that was being held any random piece of the
computer's memory.
(2 marks)
8. A binary tree is made of nodes, where each node contains a "left" reference, a
"right" reference, and a data element. The topmost node in the tree is called the
root. Every node (excluding a root) in a tree is connected by a directed edge from
exactly one other node. This node is called a parent. The nodes which reside in
the last level are called leaves

(Explanation 1 ½ mark , diagram ½ mark)

9. Error in Question. Give 2 marks for attempting the question.

10. To reduce the file search times, the storage media may be divided into cells. A
cell may be an entire disk pack or it may simply be a cylinder. Lists are localized to
lie within a cell. This technique is called cellular portioning
(2 marks)
11. A file organization refers to the organization of the data of a file into records,
blocks and access structures; this includes the way the records and blocks are
placed on the storage medium and interlinked. They primarily deal with physical
storage of data which assumes significance in retrieving, storing and reorganizing
data in a database.
Example: Sequential, random, indexed (2 marks)
12. Collision resolution techniques can be broken into two classes: open hashing and
closed hashing. (1 mark)
In Open hashing, keys are stored in linked lists attached to cells of a hash table.
But in closed hashing all keys are stored in the hash table without the use of
linked list.

Part B
13. 1-D array can be implemented as contiguous memory locations
Multidimensional array (2-D) as Row major and Column major orders
Explanation with example (5 marks)

14. The selection sort algorithm sorts an array by repeatedly finding the minimum
element (considering ascending order) from unsorted part and putting it at the
beginning. The algorithm maintains two subarrays in a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element (considering ascending
order) from the unsorted subarray is picked and moved to the sorted subarray.
(2 marks)

(1 mark)
Algorithm/Program ( 2 marks)

15. A stack is a container of objects that are inserted and removed according to the
last-in first-out (LIFO) principle. A real-world stack allows operations at one end
only. For example, we can place or remove a card or plate from the top of the
stack only. Likewise, Stack allows all data operations at one end only. At any given
time, we can only access the top element of a stack.
Stack representation
Stack operations may involve
 push() − Pushing (storing) an element on the stack.
 pop() − Removing (accessing) an element from the stack. (2 ½ marks)
A stack can be implemented by means of Array and Linked List. Stack can
either be a fixed size one or it may have a sense of dynamic resizing
Array implementation

Stack has only One End that is TOP, Item can be pushed (add) and popped
(remove) by only this End (TOP Pointer). Array follows LIFO (Last In First Out)
property, it means Item that is inserted Last will be popped first.

Linked list implementation


The major problem with the stack implemented using an array is, it works
only for a fixed number of data values. But the stack implemented using
linked list can work for an unlimited number of values. In linked list
implementation of a stack, every new element is inserted as 'top' element.
That means every newly inserted element is pointed by 'top'. Whenever we
want to remove an element from the stack, simply remove the node which is
pointed by 'top' by moving 'top' to its previous node in the list.

(2 ½ marks)

16. Circular Queue is a linear data structure in which the operations are performed
based on FIFO (First In First Out) principle and the last position is connected back
to the first position to make a circle. It is also called ‘Ring Buffer’.
In a normal Queue, we can insert elements until queue becomes full. But once
queue becomes full, we can not insert the next element even if there is a space in
front of queue. But in circular queue we can continue insertion as long as space is
available.
(Definition 1 mark)

Operations performed on a circular queue are


Enqueue
In a circular queue, enQueue() is a function which is used to insert an element
into the circular queue. In a circular queue, the new element is always inserted
at rear position. The enQueue() function takes one integer value as parameter
and inserts that value into the circular queue. We can use the following steps to
insert an element into the circular queue...

 Step 1 - Check whether queue is FULL. ((rear == SIZE-1 && front == 0) || (front ==
rear+1))
 Step 2 - If it is FULL, then display "Queue is FULL!!! Insertion is not
possible!!!" and terminate the function.
 Step 3 - If it is NOT FULL, then check rear == SIZE - 1 && front != 0 if it is TRUE,
then set rear = -1.
 Step 4 - Increment rear value by one (rear++), set queue[rear] = value and check
'front == -1' if it is TRUE, then set front = 0. (Description 1 mark,
Algorithm 1 mark)

Dequeue
In a circular queue, deQueue() is a function used to delete an element from the
circular queue. In a circular queue, the element is always deleted
from front position. The deQueue() function doesn't take any value as a parameter.
We can use the following steps to delete an element from the circular queue...

 Step 1 - Check whether queue is EMPTY. (front == -1 && rear == -1)


 Step 2 - If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not
possible!!!" and terminate the function.
 Step 3 - If it is NOT EMPTY, then display queue[front] as deleted element and
increment the front value by one (front ++). Then check whether front == SIZE, if
it is TRUE, then set front = 0. Then check whether both front - 1 and rear are
equal (front -1 == rear), if it TRUE, then set both front and rear to '-1'
(front = rear = -1). (Description 1 mark, Algorithm 1 mark)

17. Doubly linked list is a type of linked list in which each node apart from storing its
data has two links. The first link points to the previous node in the list and the
second link points to the next node in the list. The first node of the list has its
previous link pointing to NULL similarly the last node of the list has its next node
pointing to NULL.
(1 ½ mark)

(1 mark)
Algorithm or Program for inserting node at the beginning (2 ½ mark)
Step 1. Create a new node
Newnode= new node();
Newnodeprev= NULL
Step 2. Make the next pointer of the new node point to the first node
Newnodenext = head;
Step 3. Make the previous pointer of the first node point to the new node.
Headprev= Newnode
Step 4. Make the head point to the new node.
Head=Newnode;

OR
Program

18. We can dynamically implement stacks and queues using linked lists.
Dynamic implementation of stack
The push operation of stack can be dynamically implemented by inserting
a node at the beginning of the linked list and when we pop an element, delete
the first node of the linked list. Thus the linked list will works in a LIFO manner.
Algorithm
Dynamic implementation of queue
The enqueue operation of queue can be dynamically implemented by inserting a
node at the beginning of the linked list and dequeue operation can be performed
by deleting the last node of the linked list
Algorithm (5 marks)

19. A Binary Tree is a complete Binary Tree if all levels are completely filled except
possibly the last level and the last level has all keys as left as possible.

Here all the levels except the last node has all the keys. In the last level all the
keys are as left as possible. The leaf node L cannot be the right child of F. Also G
cannot have a left subtree until F has got a right child.
(5 marks)
20. Binary Search Tree, is a node-based binary tree data structure which has the
following properties:
 The left subtree of a node contains only nodes with keys lesser than the
node’s key.
 The right subtree of a node contains only nodes with keys greater than the
node’s key.
 The left and right subtree each must also be a binary search tree.
There must be no duplicate nodes.
Here the sequence is 10,12,5,4,20,8,7,15,13
Take the first element as the root node

10

The next element is 12 which is greater than 10.So insert 12 as the right child
10

12

The next element is 5 which is less than 10.So it is added as the left child of 10
10

5 12
Next element is 4 which is less than 10 and less than 5.So 4 is inserted as the left
node of 5 10

5 12

Next node is 20 which is greater than 10 and greater than 12.So it is inserted as
the right child of 12. Continue the procedure until the last element is inserted in
the binary search tree.
10

5 12

4 8
20

7
15

13
(5 marks)
21. Hashing is a technique to convert a range of key values into a range of indexes of
an array. Hash Table is a data structure which stores data in an associative
manner. In a hash table, data is stored in an array format, where each data value
has its own unique index value. Access of data becomes very fast if we know the
index of the desired data. Thus, it becomes a data structure in which insertion
and search operations are very fast irrespective of the size of the data. Hash
Table uses an array as a storage medium and uses hash technique to generate an
index where an element is to be inserted or is to be located from.
(definition 2 marks)
Example: her we use modulo operator to get a range of key values. Consider an
example of hash table of size 20, and the following items are to be stored. Item
are in the (key,value) format.
Consider the following (key,value) pair
(Any example can be considered)

(1,20), (2,70), (42,80), (4,25), (12,44), (14,32), (17,11),(13,78),(37,98)

Sr.No. Key Hash Array Index

1 1 1 % 20 = 1 1

2 2 2 % 20 = 2 2

3 42 42 % 20 = 2 2

4 4 4 % 20 = 4 4

5 12 12 % 20 = 12 12

6 14 14 % 20 = 14 14

7 17 17 % 20 = 17 17

8 13 13 % 20 = 13 13

9 37 37 % 20 = 17 17

(Explanation with example 3 marks)


Part C

22. A matrix is a two-dimensional data object made of m rows and n columns,


therefore having total m x n values. If most of the elements of the matrix have 0
value, then it is called a sparse matrix.
Advantages of sparse matrix
Storage: There are lesser non-zero elements than zeros and thus lesser memory
can be used to store only those elements.
Computing time: Computing time can be saved by logically designing a data
structure traversing only non-zero elements.
If the number of zeroes in the matrix is greater than (m*n)/2 ,then it is a sparse
matrix
Example: 00304
00570
00000
02600
Representing a sparse matrix by a 2D array leads to wastage of lots of memory as
zeroes in the matrix are of no use in most of the cases. So, instead of storing
zeroes with non-zero elements, we only store non-zero elements. This means
storing non-zero elements with triples- (Row, Column, value)
Any example for triplet representation

Operations
1. addition
2. subtraction
3. transpose
Explanation with examples (15 marks)

23. Definition of queue


Diagrammatic representation
Different types of queues
Enqueue and dequeue operations with algorithm/program (15 marks)
24. Tree is a hierarchical data structure which stores the information naturally in the
form of hierarchy style. Tree is one of the most powerful and advanced data
structures. It is a non-linear data structure compared to arrays, linked lists, stack
and queue. It represents the nodes connected by edges.
Explain the following tree terminologies with an example diagram of degree 3

1. Root: This is the unique node in the tree in which further subtrees were
attached. A root node of a tree has its child. Left child and right child are the two
childes a root node can have in a tree.

2. Degree of Node: The total number of subtree attached to that node is called
the degree of the node.

3. Leaf Nodes: These are the terminals nodes of the tree. The nodes which have
degree 0 are called as leaf nodes of the tree. These nodes are always present at
the end of the tree.

4. Internal Nodes: The nodes in the tree which are other than leaf nodes and the
root node are called as internal nodes. These nodes are present in between root
node and leaf nodes in the tree that’s why these nodes are called as internal
node.

5. Level of tree: The root node is always considering at level zero, and then its
adjacent children are supposed to be at level 1 and so on..

6. Height of the tree: The maximum level is the height of the tree.

7. Degree of tree: The maximum degree of the node in the tree is called the
degree of the tree.
(15 marks)
25. In linked file organization, each file is a linked list of disk blocks which need not
be contiguous. The disk blocks can be scattered anywhere on the disk.
The directory entry contains a pointer to the starting and the ending file block.
Each block contains a pointer to the next block occupied by the file.
The file ‘jeep’ in following image shows how the blocks are randomly distributed.
The last block (25) contains -1 indicating a null pointer and does not point to any
other block.
Advantages:
1.This is very flexible in terms of file size. File size can be increased easily since the
system does not have to look for a contiguous chunk of memory.
2. This method does not suffer from external fragmentation. This makes it
relatively better in terms of memory utilization.
Indexed Allocation
In this scheme, a special block known as the Index block contains the pointers to
all the blocks occupied by a file. Each file has its own index block. The ith entry in
the index block contains the disk address of the ith file block. The directory entry
contains the address of the index block as shown in the image:

Advantages:
 This supports direct access to the blocks occupied by the file and therefore
provides fast access to the file blocks.
 It overcomes the problem of external fragmentation

Prepared by:

Ms. Sreerekha V K
Assistant Professor
Dept. of Computer Applications
MES College Marampally, Aluva
Mob: 9745386638

You might also like