Take Print Question Bank
Take Print Question Bank
PART C - 10 Marks
XVI. Sequence the steps involved in Problem solving.
1. Problem solving is the act of defining a problem; determining the source of the
problem; identifying, prioritizing, and selecting alternatives for a solution; and
implementing a solution
2. Problem solving is a creative process which defines systematization and
mechanization.
3. Steps of Problem Solving :
The various steps for problem solving are,
(i) Problem Understanding phase
(ii) Getting started on a problem
(iii) Picking of specific examples
(iv) Similarities among problems
(v) Moving backwards from the solution
(i) Problem Understanding phase :
1. Problem understanding is the first step towards the solution of the
problem.
2. This phase defines the Problem statement which is a set of precisely
defined tasks.
(ii) Getting started on a problem :
1. There are many ways of solving a problem and there may be many
solutions for a problem.
2. So, it is difficult to recognize which solution would be more productive.
3. The best advice is not to get concerned with the details of the
implementation straightway without analysing.
(iii) Picking of specific examples :
1. Pick a specific problem and work out the mechanism to solve that
particular problem.
2. It is usually much easier to work out the details of a solution to a specific
problem because the relationship between the mechanism and the
problem is more clearly defined.
(iv) Similarities among problems :
1. This phases identifies if any similarities exists between the current
problem and the past problems which have being already solved.
2. But sometimes, it blocks from discovering a better solution to the
problem.
(v) Moving backwards from the solution :
1. This phases checks if the given problem is already having a solution.
2. If a known solution exists, then try to work backwards to the starting
point.
3. Even a guess at the solution to the problem may be enough to give a start
on the problem.
i) Sequence:
1. Sequence means that each step of the algorithm is executed in the specified
sequential order, where each step is executed exactly once.
2. Diagrammatic representation of Sequence,
3. Example:
Write an algorithm to compute and display the sum of two numbers.
Step 1: Start
Step 2: Input two numbers a and b
Step 3: Calculate sum = a + b
Step 4: Print sum
Step 5: Stop
(ii) Decision/Selection
1. Selection statements are used to determine the set of steps to be executed, based on
a Condition (Boolean Expression).
2. If the conditional result is true, one set of statements in the algorithm will be executed,
otherwise it will execute the other set of statements in the algorithm
3a. A decision statement can be stated in the following manner.
If condition then
Process 1
Else
Process 2
This is popularly known as the if-else construct.
3b. Here, if the condition is true then process 1 is executed but if the condition is false then
the else part - process 2 is executed.
4. Diagrammatic representation,
PART B - 6 Marks
6. Both queue operations (insert and delete) are performed on arrays with a constant
check being made to ensure that the array does not go out of bounds.
(i) enqueue() Operation:
The Insert operation involves checking whether or not the queue pointer
rear is pointing at the upper bound of the array.
If it is not, rear is incremented by 1 and the new item is added at the end
of the queue.
(ii) dequeue():
The Delete operation involves checking whether or not the queue pointer
front is already pointing at NULL (empty queue).
If it is not, the item that is being currently pointed is removed from the
queue and the front pointer is incremented by 1.
PART C - 6 Marks
3. Linear Types :
a) Array : An Array is a Linear Data structure that contains multiple data elements of the
same data type with a single name.
b) Linked Lists : Linked list is a linear data structure which is a collection of data elements
stored dynamically in such a manner that each element points at the next element in
the list.
c) Stacks : Stack is a linear data structure which follows a particular order in which the
operations are performed wherein the order may be LIFO(Last In First Out) or
FILO(First In Last Out). In stack, all insertion and deletion are permitted at only one end
of the list.
d) Queues : Queues are linear data structure which follows a particular order in which
the operations are performed wherein the order may be FIFO(First In First Out). In
Queue, items are inserted in one end and deleted in other end.
4. Non-Linear Types :
a) Trees :
A tree is a non-linear data structure with a hierarchy-based structure.
The tree data structure starts from a single node called a root node and has
subtrees connected to the root node.
Eg ,
where Parent node is E and Child nodes are H , I , J
b) Graphs :
A graph is an abstract non-linear data structure that is used to implement the
mathematical concept of graphs.
It is basically a collection of vertices (also called nodes) and edges that connect
these vertices.
Eg,
XVIII. Classify the different types of Linked lists (or) Summarize the various types of
Linked Lists.
Linked list can be categorized into three types namely,
1. Singly Linked List - the nodes only point to the address of the next node in the list.
2. Doubly Linked List - the nodes point to the addresses of both previous and next
nodes.
3. Circular Linked List - the last node in the list will point to the first node in the list. It
can either be singly linked or doubly linked.
XIX. Illustrate Push and Pop operations of a Stack with suitable Algorithm.
PUSH Operation :
i. Push() inserts an element at one end of the stack called top.
ii. The push operation involves checking whether or not the stack pointer is
pointing at the upper bound of the array.
iii. If it is not, the stack pointer is incremented by 1 and the new item is pushed
(inserted) at the top of the stack.
POP OPERATION:
i. Pop operation removes and returns the element at the top of the stack, if it is
not empty.
ii. The pop operation involves checking whether or not the stack pointer is already
pointing at NULL (empty stack).
iii. If it is not, the item that is being currently pointed is popped (removed) from the
stack (array) and the stack pointer is decremented by 1.
XX. Write a C Program for Push and Pop operation in a Stack.[Refer Practical Programs]
Sss
DATA STRUCTURES - MODULE 3 - TREES
PART A - 2 Marks
I) Describe Trees in Data structures.
1. A tree is a non-linear data structure with a hierarchy-based structure.
2. The tree data structure starts from a single node called a root node and has subtrees
connected to the root node.
3. Eg ,
IV) Identify the Parent node and Child nodes of the tree ,
Parent Node : E
Child Nodes : H , I , J
V) Define General Trees in Data structures.
1. General trees are unordered tree data structures where the root node has minimum 0
or maximum ‘n’ subtrees.
2. The General trees have no constraint placed on their hierarchy.
3. The root node thus acts like the superset of all the other subtrees.
4. Eg,
VIII) What are the methods of rotating the sub trees of an AVL tree?
An AVL tree may rotate in one of the following four ways:
1. Left Rotation
2. Right Rotation
3. Left-Right Rotation
4. Right-Left Rotation
3. In the above structure, all the nodes except leaf nodes(F,G,H,I,C) have 2 child
nodes.
COMPLETE BINARY TREE :
1. A complete binary tree is a binary tree type where all the leaf nodes must be on the
same level.
2. Eg,
3. In the above structure, all the leaf nodes(D,E,F,G) are in the same level.
Inorder Traversal : 4 2 5 1 6 3 7
Preorder Traversal : 1 2 4 5 3 6 7
Postorder Traversal : 4 5 2 6 7 3 1
PART C – 10 MARKS
XVII) Demonstrate the methods of rotating the sub trees of an AVL tree.
An AVL tree may rotate in one of the following four ways to keep itself balanced:
a. Left Rotation
b. Right Rotation
c. Left-Right Rotation
d. Right-Left Rotation
Left Rotation: When a node is added into the right subtree of the right subtree, if the tree
gets out of balance, we do a single left rotation.
Right Rotation: If a node is added to the left subtree of the left subtree, the AVL tree may get
out of balance, we do a single right rotation.
Left-Right Rotation : A left-right rotation is a combination in which first left rotation takes
place after that right rotation executes.
Right-Left Rotation: A right-left rotation is a combination in which first right rotation takes
place after that left rotation executes.
XVIII) Classify the Different Types of Trees in Data Structures
There are three types of trees −
(i) General Trees
(ii) Binary Trees
(iii) Binary Search Trees
XIX) Elaborate the concept of Trees and Binary tree traversals. (or)
Demonstrate Pre-Order, Post-Order and In-order tree traversals.
TREE :
1. A tree is a non-linear data structure with a hierarchy-based structure.
2. The tree data structure starts from a single node called a root node and has subtrees
connected to the root node.
BINARTY TREE TRAVERSAL :
1. A binary tree is traversed when one needs to access or display its elements.
2. There are 3 methods for traversing a binary tree:
(i) Pre-order Traversal − Traverses a tree in a pre-order manner.
(ii) In-order Traversal − Traverses a tree in an in-order manner.
(iii) Post-order Traversal − Traverses a tree in a post-order manner.
3. Pre Order Traversal :
PREORDER [ROOT – LEFT – RIGHT]
(i) In this traversal, the root node is visited first, then its left child and later its
right child.
(ii) This is repeated recursively until all the elements of the tree are traversed.
(iii) Algorithm Steps
Step 1: Visit the root.
Step 2: Traverse the left subtree, recursively call preorder(left-subtree)
Step 3: Traverse the right subtree, recursively call preorder(right-subtree).
(iv) Example :
Pre-Order Traversal : 1 2 3
4. In Order Traversal :
INORDER [LEFT – ROOT – RIGHT]
(i) In this traversal, the left child node is visited first, it’s root node is visited next
and then the right child node.
(ii) This is repeated recursively until all the elements of the tree are traversed.
(iii) Algorithm Steps
Step 1: Traverse the left subtree, recursively call inorder(left-subtree)
Step 2: Visit the root.
Step 3: Traverse the right subtree, recursively call inorder(right-subtree)
(iv) Example :
In-Order Traversal : 2 1 3
Post-Order Traversal : 2 3 1
XX) Give the algorithm for Preorder, Inorder and Postorder Tree traversal [ Refer above
answer]
Sss
DATA STRUCTURES - MODULE 4 - SORTING
PART A - 2 Marks
I) Define Sorting.
1. Sorting refers to the operation of arranging data in some given order, such as
increasing or decreasing with numerical data or alphabetically with character data.
2. The techniques of sorting can be divided into two categories. These are:
Internal Sorting
External Sorting
PART B – 6 Marks
IX) Discuss briefly the types of Sorting (OR) Compare Internal and External sorting (OR)
Discuss in detail External Sorting
1. Sorting is of two types namely,
a. Internal Sorting
b. External Sorting
2. Both Internal and External sorting is used to rearrange the data in a particular order.
3. Internal Sorting:
(i) If all the data that is to be sorted can be accommodates at a time in the main
memory, the internal sorting method is being performed.
(ii) Internal sorting is generally faster because main memory can be accessed faster
(iii) Random access to data is feasible as data is stored in main memory.
(iv) Internal sorting algorithms maintain stability
(v) Internal sorting is limited to the size of the main memory and may not be
efficient for large datasets.
(vi) Internal sorting uses simple sort strategy.
(vii) Examples : Heap sort , Insertion sort, Quick sort, Shell sort
4. External Sorting:
(i) When the data that is to be sorted cannot be accommodated in the memory at
the same time and some has to be kept in auxiliary memory such as hard disk,
floppy disk, magnetic tapes etc, then external sorting methods are performed.
(ii) External sorting is slower due to relatively slower access time of external storage
devices.
(iii) External sorting involves sequential access of data.
(iv) External Algorithms may not maintain stability.
(v) External sorting can handle dataset larger than the available memory.
(vi) External sorting typically uses a hybrid sort-merge strategy.
In the sorting phase, chunks of data small enough to fit in the main memory
are read, sorted, and written out to a temporary file.
In the merge phase, the sorted sub-files are combined into a single larger
file.
(vii) Examples: Merge sort, Tape sort , Polyphase sort , External radix
4. Algorithm :
Step 1 - If the element is the first element, assume that it is already sorted. Return 1.
Step2 - Pick the next element, and store it separately in a key.
Step3 - Now, compare the key with all elements in the sorted array.
Step 4 - If the element in the sorted array is smaller than the current element, then
move to the next element. Else, shift greater elements in the array towards the right.
Step 5 - Insert the value.
Step 6 - Repeat until the array is sorted.
5. Efficiency of Insertion Sort:
o Best Case : O(n)
o Average Case : O(n2)
o Worst Case : O(n2)
XVII) Elaborate the process of Quick Sort with an example.
1. Quick sort is a faster and highly efficient algorithm that follows divide-and-
conquer approach,
2. Working :
a. Divide: In Divide, first pick a pivot element and partition into two sub-arrays
such that each element in the left sub-array is less than or equal to the
pivot element and each element in the right sub-array is larger than the
pivot element.
b. Conquer: Recursively, sort two subarrays with Quicksort
c. Combine: Combine the already sorted array.
3. Example :
Let the elements of unsorted array be –
24 9 29 14 19 27
In the given array, we consider the leftmost element as pivot. So, in this case, a[left] =
24, a[right] = 27 and a[pivot] = 24.
Since, pivot is at left, so algorithm starts from right and move towards left.
Now, a[pivot] < a[right], so algorithm moves forward one position towards left, i.e.
-
Now, a[left] = 19, a[right] = 24, and a[pivot] = 24. Since, pivot is at right, so algorithm
starts from left and moves to right.
As a[pivot] > a[left], so algorithm moves one position to right as -
Now, a[left] = 9, a[right] = 24, and a[pivot] = 24. As a[pivot] > a[left], so algorithm
moves one position to right as -
Similarly,
Now, in a similar manner, quick sort algorithm is separately applied to the left and right
sub-arrays.
After sorting gets done, the array will be -
4. Algorithm :
Step 1 − Choose the highest index value as pivot
Step 2 − Take two variables to point left and right of the list excluding pivot
Step 3 − left points to the low index
Step 4 − right points to the high
Step 5 − while value at left is less than pivot move right
Step 6 − while value at right is greater than pivot move left
Step 7 − if both step 5 and step 6 does not match swap left and right
Step 8 − if left ≥ right, the point where they met is new pivot
5. Efficiency :
o Best Case : O(n log n)
o Average Case : O(n log n)
o Worst Case : O(n2)
PART A - 2 Marks
Cycle : A->B->C->A
Vertices : A,B,C,D
VIII) List the various methods to find the Shortest path in a Graph.
There are three different algorithms to calculate the shortest path between the
vertices of a graph namely,
Minimum spanning tree
Dijkstra’s algorithm
Warshall’s algorithm
Part B – 6 MARKS
IX) Explain briefly the types of Graphs. (or) Elaborate Directed and Undirected Graphs with
an example.
1. A graph can be
a. Directed graph
b. Undirected graph.
2. Directed Graph :
a. In a directed graph, edges form an ordered pair.
b. The edges have direction.
c. For Eg,
d. The Edges are (A, B) (B,C) (A,D) (D,C) and (C,A)
e. In the above example edge (A,B) , the traversal can be only from A to B and not B
to A as it is directed graph.
3. Undirected Graph :
a. In an undirected graph, edges for an unordered pair
b. The edges do not have any direction associated with them.
c. For Eg,
d. The Edges are (A, B) (B,C) (A,D) (D,C) (C,A) and (B,A) (C,B) (D,A) (C,D) (A,C)
e. In the above example edge (A,B) , the traversal can be from A to B and B to A as it
is undirected graph.
Adjacency Matrix
XI) Compare Trees and Graphs in Data structures.
Trees :
1. Tree is a non−linear data structure, which has only one path between two vertices.
2. Loops are not allowed in a tree structure.
3. Trees have exactly one root node.
4. Trees have three traversal techniques namely, pre−order, in−order, and post−order.
5. Trees follow the hierarchical model.
6. Trees are less complex structure.
7. Tree data structure will always have directed edges.
8. It is used for inserting, deleting or searching any element in tree.
9. Eg,
Graph :
1. Graph is also a non−linear data structure that can have more than one path between
vertices
2. Graphs can have loops
3. Graphs do not have a root node.
4. Graphs have two traversal techniques namely, breadth−first search and depth−first
search.
5. Graphs follow the network model.
6. Graphs are relatively more complex.
7. In graph data structure, all the edges can either be directed edges, undirected edges, or
both.
8. It is mainly used for finding the shortest path in the network.
9. Eg,
XIII. Illustrate how graphs are represented as Adjacency Matrix with an example.
1. An adjacency matrix is used to represent which nodes are adjacent to one another
2. Two nodes are said to be adjacent if there is an edge connecting them.
3. In an adjacency matrix, the rows and columns are labelled by graph vertices.
4. An entry aij in the adjacency matrix will contain 1, if vertices vi and vj are adjacent to
each other.
5. However, if the nodes are not adjacent, aij will be set to zero.
6. Eg,
7. Since an adjacency matrix contains only 0s and 1s, it is called a bit matrix or a Boolean
matrix.
8. The entries in the matrix depend on the ordering of the nodes in G. Therefore, a change
in the order of nodes will result in a different adjacency matrix.
9. General conclusions:
For a simple graph (that has no loops), the adjacency matrix has 0s on the diagonal.
The memory use of an adjacency matrix is O(n2), where n is the number of nodes
Number of 1s (or non-zero entries) in an adjacency matrix is equal to the number of
edges in the graph.
The adjacency matrix for a weighted graph contains the weights of the edges
connecting the nodes.
PART C – 10 Marks
XIV. Elucidate Breadth-first search with an example. (Or) Elucidate the methods of Graph
Traversals explaining any one method with an example
i. There are two standard methods of graph traversal namely ,
Breadth-first search
Depth-first search.
ii. During the execution of the algorithm, every node in the graph will have a variable
STATUS set to 1 or 2 or 3, depending on its current state.
1 – Ready state(Initial State)
2 – Waiting State (Node is placed in the queue or stack and waiting to be
processed)
3 – Processed state (Node has been completely processed)
iii. Breadth-first search (BFS) :
1. Breadth-first search is a graph search algorithm that begins at the root node
and explores all the neighbouring nodes.
2. Then for each of those nearest nodes, the algorithm explores their unexplored
neighbour nodes, and so on, until it finds the goal.
3. This is accomplished by using QUEUES that will hold the nodes that are waiting
for further processing ,
QUEUE1 holds all the nodes that are to be processed,
QUEUE2 holds all the nodes that are processed and deleted from
QUEUE1.
4. A variable STATUS to represent the current state of the node.
5. Example :
Adjacency List
A : B,D
B: C
C: A
D: C
Step 2 : Delete the node A from the Queue1 and add it to Queue2 . Insert all
neighbors to node A to Queue2
QUEUE 1 = {B,D}
QUEUE 2 = {A}
Step 3 : Delete the node B from the Queue1 and add it to Queue2 . Insert all
neighbors to node B to Queue2
QUEUE 1 = {D,C}
QUEUE 2 = {A,B}
Step 4 : Delete the node D from the Queue1 and add it to Queue2 . Insert all
neighbors to node D to Queue2. The only neighbor of D is C and since C is
already inserted , it will not be inserted again.
QUEUE 1 = {C}
QUEUE 2 = {A,B,D}
Step 5 : Delete the node C from the Queue1 and add it to Queue2 . Insert all
neighbors to node C to Queue2. The only neighbor of C is A and since A is
already inserted , it will not be inserted again.
QUEUE 1 = {}
QUEUE 2 = {A,B,D,C}
6. ALGORITHM :
Step 1: SET STATUS = 1 (ready state) for each node in G
Step 2: Enqueue the starting node A and set its STATUS = 2 (waiting state)
Step 3: Repeat Steps 4 and 5 until QUEUE is empty
Step 4: Dequeue a node N. Process it and set its STATUS = 3 (processed state).
Step 5: Enqueue all the neighbours of N that are in the ready state
(whose STATUS = 1) and set their STATUS = 2 (waiting state)
[END OF LOOP]
Step 6: EXIT
XV. Elucidate Depth-first search with an example. . (Or) Elucidate the methods of Graph
Traversals explaining any one method with an example
i. There are two standard methods of graph traversal namely ,
Breadth-first search
Depth-first search.
ii. During the execution of the algorithm, every node in the graph will have a variable
STATUS set to 1 or 2 or 3, depending on its current state.
1 – Ready state(Initial State)
2 – Waiting State (Node is placed in the queue or stack and waiting to be
processed)
3 – Processed state (Node has been completely processed)
iii. Depth-first search :
1. Depth-first search is a graph search algorithm that begins at the root node and
explores all the neighbouring nodes.
2. a.The depth-first search algorithm progresses by expanding the root node and
then going deeper and deeper until the goal node is found, or until a node that
has no children is encountered.
b. When a dead-end is reached, the algorithm backtracks, returning to the most
recent node that has not been completely explored.
3. This is accomplished by using STACKS that will hold the nodes that are waiting
for further processing
4. A variable STATUS to represent the current state of the node.
5. Example :
Adjacency List
A : B,D
B: C
C: A
D: C
Step 2 : Pop the node A from the Stack and Print it. Now, push all neighbors to
node A to Stack
STACK = {B,D}
PRINT A
Step 3 : Pop the node D from the Stack and print it. Push all neighbors to node
D to Stack.
STACK = {B,C}
PRINT A , D
Step 4 : Pop the node C from the Stack and print it. Push all neighbors to node C
to Stack. The only neighbor of C is A and since A is already inserted , it will not
be inserted again.
STACK = {B}
PRINT A,D,C
Step 5 : Pop the node B from the Stack and print it. Insert all neighbors to node
B to Stack. The only neighbor of B is C and since C is already inserted , it will not
be inserted again.
STACK= {}
PRINT A,D,C,B
XVIII) Discover the various methods to find the Shortest path in a Graph. Explain in detail
any one of the methods.
There are three different algorithms to calculate the shortest path between the vertices
of a graph. These algorithms include:
Minimum spanning tree
Dijkstra’s algorithm
Warshall’s algorithm
[Refer Notes]
XIX) Detail Adjacency Matrix and Adjacency List representations of a Graph with an
example.
[Refer Notes]
XX) Discuss the algorithm for Breadth-first and Depth-first algorithm [Refer Point 6 of
Previous Questions No. XV and XIV and write the algorithm of Breadth-first and Depth-first
search]