Hllo
Hllo
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
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.
(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)
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...
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();
Newnodeprev= NULL
Step 2. Make the next pointer of the new node point to the first node
Newnodenext = head;
Step 3. Make the previous pointer of the first node point to the new node.
Headprev= 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 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
Operations
1. addition
2. subtraction
3. transpose
Explanation with examples (15 marks)
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