Chapter 4 Data Structures
Chapter 4 Data Structures
21. Which order does the queue data structure follow? (U)
ANS : FIFO ( First-In First-Out).
22. What is enqueue? (U)
ANS : Enqueue is an operation of Queue which adds a new item to the rear of the
queue.
23. What is dequeue? (U)
ANS : Dequeue is an operation of Queue which removes the front item from the
queue.
24. What is linked list? (U)
ANS : A linked list is a linear collection of data elements called nodes.
25. How do we establish linearity in linked list? (U)
ANS : By storing the next node address to the link in the previous node
26. Name the type of memory allocation use by the linked list. (U)
ANS : Dynamic memory allocation
27. What is non-linear data structure? (U)
ANS : A Non-Linear Data structures is a data structure in which data item is
connected to several other data items.
28. Give an example for non-linear data structure. (U)
ANS : trees and graphs
29. What is a node? (U)
A node is a fundamental part of tree. Each element of a tree is called a node of the
tree.
30. What is parent node? (U)
ANS : parent node is an immediate predecessor a node.
31. What is a child node? (U)
ANS : child node successor of parent node is called the child node.
b. Non Primitive
i. Linear
ii. Non Linear
2. Mention the different operations performed on primitive data structure. (U)
ANS : Refer in other section
3. What is linear and non-linear data structure? (U)
ANS : i. Linear Data structures:
Linear Data structures are kind of data structure that has homogeneous elements.
ii. Non-Linear Data structures:
A Non-Linear Data structures is a data structure in which data item is connected to
several other data items.
4. What is an array? Mention the different types of arrays. (U)
ANS : An array is an ordered collection of elements of same data type that share
common name.
i. One-dimensional Array
ii. Two-dimensional Array
iii. Multi-dimensional Array
5. Mention two types of searching techniques. (U)
ANS : Linear Search and Binary Search
6. Write any two applications of arrays. (A)
ANS : 1. Used to perform matrix operation
2. Used to store the values of same type.
7. What are PUSH and POP operations on stacks? (U)
ANS : push(item): It adds a new item to the top of the stack.
pop( ): It removes the top item from the stack.
8. Write the memory representation of queues using arrays. (A)
9. What is the purpose of new and delete operators? (U)
o Example: If an array A has values 10, 20, 30, 40, 50, stored in location 0,1, 2, 3, 4
the UB= 4 and LB=0
o Size of the array L = 4 – 0 + 1 = 5
5. Consider the array A of order 25 x 4 with base value 2000 and one word per
memory location. Find the memory address of A[12][3] in row-major order. (A)
ANS : LOC ( A[ i ][ j] ) = base (A) +W [ n (i – LB) + (j – LB)]
Given Base (A)=2000 , m=25 , n=4 , LB=0 , W=1 , i=12 , j=3
LOC ( A[ 12 ][ 3] ) = 2000 +1 [4 (12-0) + (3-0)
=2000 + 4 (12) + 3
=2000 + 48 +3
=2051
6. Consider the array A of order 25x4 with base value 2000 and one word per
memory location. Find the address of A[12][3] in column-major order. (A)
ANS : LOC ( A[ i ][ j] ) = base (A) +W [ (i – LB) + m (j – LB)]
Given Base (A)=2000 , m=25 , n=4 , LB=0 , W=1 , i=12 , j=3
LOC ( A[ 12 ][ 3] ) = 2000 +1 [ (12-0) + 25 (3-0)
` =2000 + 1 (12) + 75
Prepared by : Sanil Abraham, Deeksha Mahalakshmipuram Page 8
CHAPTER 4 - DATA STRUCTURES
=2000 + 87
=2087
7. What are the advantages of arrays? (A)
ANS : Advantages of Array:
It is used to represent multiple data items of same type by using single name.
It can be used to implement other data structures like linked lists, stacks, queues,
tree, graphs etc.
Two-dimensional arrays are used to represent matrices.
Many databases include one-dimensional arrays whose elements are records.
stack overflow condition. Similarly, you cannot remove elements beyond the base
of the stack. If such is the case, we will reach a stack underflow condition.
TOP = MAXSTX indicates that the stack is full and TOP = NULL
indicates that stack is empty.
The pointer variable FRONT contains the location of the element to be removed or
deleted.
The pointer variable REAR contains location of the last element inserted.
The condition FRONT = NULL indicates that queue is empty.
The condition REAR = N-1 indicates that queue is full.
4. Write an algorithm for searching an element using binary search method. (A)
ANS :
ALGORITHM: Binary_Search (BEG, END, MID ELE) A is an array with N
elements. Let BEG, END, MID denote Beginning, end and middle location of the
array
Step 1: Set BEG=LB, END=UB LOC = -1
Step 2: While(BEG <= END)
MID = (BEG+END)/2
if ( ELE = A [ MID ] ) then
LOC = MID
Goto Step 3
else
if( ELE < A[MID])
END=MID-1;
else
BEG=MID+1;
[End if]
[End if]
[End of While loop]
Step 3: if ( LOC >= 0 ) then
Print Element, “Found in Location”, LOC
else
Print Element, “Search is Unsuccessful”
Step 4: Exit
element in a series of elements. Once you reach a dead end, you must backtrack.
by using stack.
postfix.
o Simple Queue
o Circular Queue
o Priority Queue
o Dequeue ( Double Ended Queue)
Simple Queue: In simple queue insertion occurs at the rear end of the list and
deletion occurs at the front end of the list.
REAR = NULL
else
FRONT = FRONT + 1 [Increment FRONT pointer]
Step 4: Return
13. Write the applications of queues. (A)
ANS :
14. What are the operations performed on the linked list? (U)
ANS :
A linked list is a linear collection of data elements called nodes.
15. Define the following : a. Root Node b. Leaf Node c. Height d. Depth e. Internal
node. (U)
ANS :
Leaf or terminal node: Nodes that do not have any children are called leaf node. (J,
K, L)
Height: the height or depth of a tree is defined to be the maximum number of nodes
in a branch of tree. ( The height of tree is 5)
Internal Node: A node has one or more children is called an internal node. ( B, C, D,
H)