CS3301 DS QB
CS3301 DS QB
UNIT-I
PART-A
• Integers
• Floating-point numbers.
• Character Constants
PART-B
1. Define stack?
Stack is an ordered collection of items into which new items may be inserted and from
which items may be deleted at one end, called the top of stack.
5. Define Dequeue.
A dequeue is an ordered list in which additions and deletions may be carried out at either end.
7. What are the limitations in the stack, when array used as home of stack?
The Array is finite collection of elements and in stack the number of elements is
unlimited. As the stack dynamically changes the attempts to insert more elements than the
array size cause overflow
8. Define Modularization?
Modularization is the concept of isolating the complex implementation into set of
independent and easily identifiable units, to make the program easily understandable and
modifiable.
9. What are the error conditions that could occur in stack implementation? How
could theybe rectified?
Overflow
Underflow
To avoid overflow, the stack should be checked whether it is full or not before every push
operation.
To avoid underflow, the stack should be checked for emptiness before every
pop operation.
15. What are the basic operations that could be performed on a Queue?
Insertion – insert (q, x) inserts x at the rear end.
Removal – x=remove (q) remove the element in front end.
Empty(q) – Checks whether queue has any elements or not.
16. What are the limitations of linear queue? How they can be rectified?
When an element is removed from linear queue, the location remains unused. Even if the
queue is empty, new elements cannot be inserted. To avoid this, consider queue as a circle,
having the first element immediately following the last element.
18. What are the two types of priority queues? Briefly explain?
Two types of priority queues are,
i) Ascending priority queue – In this queue, the items can be inserted arbitrarily
and only the smallest item will be removed.
ii) Descending priority queue- This allows insertion of items arbitrarily, and only
the maximum element from queue will be removed first.
a. 6 5 2 3 + 8 * + 3 + *2 3 1 * + 9 -
9. Briefly describe the operations of queue with example.
10. Describe about implementation of queue ADT using linked list. Give relevant examples
and diagrammatic representations.
11. Discuss and write a C program to implement queue functions using arrays.
12. Explain application of queue with suitable example.
13. Explain circular queue and its implementation.
14. Analyze the implementation of priority queue.
15. Prepare an algorithm to perform the operations in a double ended queue.Develop a C
program for linked list implementation of stack.
16. A circular queue has a size of 5 and has 3 elements 10,20 and 40 where F=2 and
R=4.After inserting 50 and 60,what is the value of F and R.Trying to insert 30 at this
stage what happens? Delete 2 elements from the queue and insert 70, 80 & 90.Assess the
sequence of steps with necessary diagrams with the value of F & R.
17. Generalize and develop a function to insert an element into a queue and delete an
element from a queue, in which the queue is implemented as a linked list.
UNIT-III
PART-A
1. Define Tree.
A Tree is a collection of one or more nodes with a distinct node called the root , while
remaining nodes are partitioned as T1 ,T2, ..,Tk , K≥ 0 each of which are sub trees, the edges of
T1,T2,…,Tk are connected the root.
20. Give the pre & postfix form of the expression (a + ((b*(c-e))/f).
The value in any left subtree is less than the value of its parent node.
The value in any right subtree is greater than the value of its parent node.
22.What do u mean by General trees?
General Tree is a tree with nodes having any number of children.
A heap can be implemented as an array by recording its elements in the top-down, left-to-right
fashion.
It is convenient to store the heap’s elements in positions 1 through n of such an array. In such a
representation
The parental node keys will be in the first n/2 positions of the array, while the leaf keys will
occupy the last n/2 positions
The children of a key in the array’s parental position ‘i’ (1 i n/2) will be in positions 2i and
2i+1and correspondingly, the parent of the key in position ‘i’ (2 i n) will be in position i/2.
31. What are the two alternatives that are used to construct a heap?
The two alternatives to construct a heap are
Bottom-up heap construction
Top-down heap construction
32. Give the pseudocode for Bottom-up heap construction.
ALGORITHM HeapBottomUp(H[1..n])
//Constructs a heap from the elements of the given array
//Input An array H[1..n] of orderable elements
//Output A heap H[1..n]
for I n/2 downto 1 do
k I ; v H[k] heap false while not heap and 2*k n do j 2*k if j < n
if H[j] < H[j+1] j j+1
if v H[j]
heap true
else H[k] H[j]; k j
H[k] v
33. What is the algorithm to delete the root’s key from the heap?
ALGORITHM
❖ Exchange the root’s key with the last key K of the heap
❖ Decrease the heap’s size by one
❖ “Heapify” the smaller tree by sifting K down the tree exactly in the same way as
bottom-up heap construction. Verify the parental dominance for K: if it holds stop
the process, if not swap K with the larger of its children and repeat this operation
until the parental dominance holds for K in its new position.
35.What is a min-heap?
A min-heap is a mirror image of the heap structure. It is a complete binary tree in which
every element is less than or equal to its children. So the root of the min-heap contains the
smallest element.A B-tree of order m in an m-way search tree that is either empty or is of height
≥1 and
2. All nodes other than the root node and failure nodes have at least m/2 children.
A Binary Heap is a complete binary tree in which the key value of any node must be
lesser than its children is called min heap. If the key value of any node is greater than its children
is called max heap.Binary heap is also called as partially ordered tree.
For any element in the array position ‘i’, the left child is at the position ‘2i’, the right
child is at the position ‘2i+1’ and parent is at the position ‘i/2’.
PART-B
1. Write an algorithm for preorder, inorder and postorder traversal of a binary tree.
2. Explain the following operations on a binary search tree with suitable
algorithms
a. Find a node
b. Find the minimum and maximum elements of binary search tree.
3. Write an algorithm for inserting and deleting a node in a binary search tree.
4. Describe the concept of threaded binary tree with example.
5. Discuss in detail the various methods in which a binary tree can be represented. Discuss
theadvantage and disadvantage of each method.
PART-A
1. Define Graph.
A Graph G, consists of a set of vertices V, and a set of edges E.V is a finite non-empty set
consisting of vertices of vertices of the graph. The set of edges E consists of a pair of vertices
from the vertex set.
Adjacency Matrix is a representation used to represent a graph with zeros and ones.A graph
containing n vertices can be represented using n rows and n columns
21. What is the use of Kruskal’s algorithm and who discovered it?
Kruskal’s algorithm is one of the greedy techniques to solve the minimum spanning
tree problem. It was discovered by Joseph Kruskal when he was a second-year graduate student.
23. Prove that the maximum number of edges that a graph with n Vertices is
n*(n-1)/2.
Choose a vertex and draw edges from this vertex to the remaining n-1 vertices. Then, from
these n-1 vertices, choose a vertex and draw edges to the rest of the n-2 Vertices. Continue
this process till it ends with a single Vertex.
Hence, the total number of edges added in graph is
(n-1)+(n-2)+(n-3)+…+1 =n*(n-1)/2.
24. Define connected and strongly connected graph.
Two Vertices u and v are said to be connected if there exists a path from u to v in the graph. A
directed graph is said to be connected if every pair of vertices in the graph is connected.
A directed graph is said to be strongly connected if for every pair of distinct vertices vi and vj,
there exists two disjoint paths, one from vi to vj and the other from vj to vi.
PART-B
PART-A
1. Define sorting
Sorting arranges the numerical and alphabetical data present in a list in a specific order
or sequence. There are a number of sorting techniques available. The algorithms can be
chosen based on the following factors
– Size of the data structure
– Algorithm efficiency
– Programmer’s knowledge of the technique.
Mention the types of sorting
2. x Internal sorting
x External sorting