Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views8 pages

Dsa Final Question and Answer

The document contains a series of multiple-choice questions and fill-in-the-blank questions related to data structures and algorithms, along with their corresponding answers and explanations. Topics covered include stack operations, binary search trees, sorting algorithms, and complexities of various data structures. Each question is followed by the correct answer and a brief rationale for why that answer is correct.

Uploaded by

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

Dsa Final Question and Answer

The document contains a series of multiple-choice questions and fill-in-the-blank questions related to data structures and algorithms, along with their corresponding answers and explanations. Topics covered include stack operations, binary search trees, sorting algorithms, and complexities of various data structures. Each question is followed by the correct answer and a brief rationale for why that answer is correct.

Uploaded by

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

Direction 1: Choose the best answer and put your answer in the answer

1. The process of inserting an element in stack is called


a,Create
c. Evaluation
d. Pop
b. Push
2. Which of the following is false about a binary search tree?
a,The left child is always lesser than its parent
b,In order sequence gives decreasing order of elements
c. The left and right sub-trees should also be binary search trees
d. The right child is always greater than its parent
3. Which is the easiest and least efficient searching technique?
a,Linear search
c. Fibonacci search
d. None of the above
b. Binary search
4. In a stack, if a user tries to remove an element from an empty stack it is called
a. Garbage Collection
c. Overflow
b. Empty collection
d. Underflow
5. What is a full binary tree?
a. Each node has exactly one or two children
b. Each node has exactly two children
c. All the leaves are at the same level
d. Each node has exactly zero or two children
6. Quick sort algorithm is an example of
a. Greedy approach
b. Dynamic Programming
c. Divide and conquer
d. Improved binary search
7. Consider an algorithm for determining whether a sequence of parentheses is balanced infix expres-
sion. The maximum number of parentheses that are pushed on to the stack ANY ONE TIME when the al-
gorithm analyzes the expression (()(())(())) is:
a. I
b. 3
c. 2
d. 4 or more
8. What is the value of the postfix expression 6324+-*?
a. 1
c. -18
b. 40
d. 7
9,What is not true about insertion sort?
a.Exhibits the worst-case performance when the initial array is sorted in reverse order.
b. Worst case and average case performance is O(n2)
c can be compounded on the way
d,none
13. How many swaps are required to sort the given array using bubble sort
a,5
b. 4
c,7
d,6
14. Overflow in normal queue of array of size MAX Size, is detected with
a. Rear =MAX SIZE-1
b. Front= (rear+ 1)mod MAX_ SIZE
c. Front= rear +1
d. Rear= front
15. Which of the following about graph is true?
a. A graph may contain no edges and many vertices
b. A graph may contain many edges and no vertices
c. A graph may contain no edges and no vertices
d. A weighted graph contains associated cost for each edge
16. What is the time complexity to count the number of elements in the linked list
a. 0(1)
c. O(log(n))
b. O(n^2)
d. O(n)
17. What is the space complexity for deleting a linked list?
a. Either O(1) or O(n)
c. O(1)
b. O(n)
d. O(log(n))
18. Which of the following is false about a doubly linked list?
a. We can navigate in both the directions
b. It requires more space than a singly linked list
c. The insertion and deletion of a node take a bit longer than single linked list
d. Implementing a doubly linked list is easier than singly linked list
19. What is the worst case time complexity of inserting a node in a doubly linked list?
a. O(nlog(n))
b. O(n)
c. O(log(n))
d. O(1)
20. What are the worst case and average case complexities of searching in a binary search tree?
a. O(n), O(log(n))
b. O(log(n)), O(log(n))
c. O(log(n)), O(n)
d. O(n), O(n)
21. Which of the following is important property of a recursive method?
a. It must call itself in its body
b. It must have a sentinel
c. It must converge and gradually stop
d. b&d
e all
22. If the elements "A", "B", "C" and "d"are inserted into a queue respectively and are deleted one at a
time, in what order will they be removed?
a. ABCD
b. DCBA
c. DCAB
d. ABDC

23. A pivot element to partition unsorted list is used in


a. Merge Sort
b. Selection Sort
c. Insertion Sort
d. Quick Sort

24. State True or False.


i) Binary search is used for searching in a sorted array.
ii) The time complexity of binary search is O(log(n)).
a. True, True
b. False, True
c. False, False
d. True, False

25. A queue follows


a. LIFO principle
b. FIFO principle
c. Ordered array
d. Linear tree
26. How many children can a binary tree have?
a. 0 or 2
b. any number of children
c. 0
d. 0 or 1 or 2
27. Which of the following data structures is linear type?
a. Stack
b. Trees
c. Binary tree
d. Graph
28. Which of the following data structures is not linear data structure?
a. Arrays
b. Linked lists
c. Both of above
d. None of above
29. Which of the following sorting algorithm is of divide and conquer type?
a. Bubble sort
b. Insertion sort
c. Merge sort
d. All
30. Which of the following is not the part of ADT description?
a. Data
b. Operations
c. both of the above
d. None of the above

Direction II: Fill in the blank (Ipts each)


1. The hierarchical relationship between data elements can be easily represented using a nonlinear data
structure called................
2................ is a different implementation of iterative methods by calling the function in its body.
3. In............... search we start at the beginning of the list and check everyelement in the list.
4. A linear list of elements in which deletion can be done from one end and insertion can take place only
at the other end is known as...........
5. ...............search method is also known as sequential search.

Direction III: Work out (Write your answers on the answer pages provided)
1. Construct a binary search tree and make post-order traverse of BST with the fisllowing data : preorder
traversal of the tree is 10, 4, 3, 5, 11, 12
2. Write the preorder, in-order and post-order traverse of the following tree.
a. Inorder traversal:
b. Preorder traversal:
c. Postorder traversal:
3. Write the algorithm and basic line of code in C++ for stack push/pop operation.
4. Write the algorithm step and basic line of code in C++ for Doubly linked list
5. Implement the insert and search methods of Binary Search Tree in C++.

answer

1. The process of inserting an element in a stack is called


b. Push

Explanation: When an element is added to a stack, it is pushed onto the top of the stack. This operation
is commonly referred to as "push" in stack terminology.

2. Which of the following is false about a binary search tree?


b. In order sequence gives decreasing order of elements

Explanation: In a binary search tree, the in-order traversal gives elements in non-decreasing order. This
means that the elements are visited in ascending order, not descending order.

3. Which is the easiest and least efficient searching technique?


a. Linear search
Explanation: Linear search is the simplest searching technique where each element in the list is checked
until the desired element is found. However, it is also the least efficient for large datasets as it has a time
complexity of O(n).

4. In a stack, if a user tries to remove an element from an empty stack it is called


d. Underflow

Explanation: When an attempt is made to pop or remove an element from an empty stack, it is referred
to as "underflow" in stack terminology.

5. What is a full binary tree?


b. Each node has exactly two children

Explanation: A full binary tree is a tree in which every node other than the leaves has exactly two chil-
dren. This means that each internal node (non-leaf node) has exactly two children.

6. The best answer is:


c. Divide and conquer

Explanation: Quick sort is an example of a divide and conquer algorithm. It works by dividing the array
into smaller sub-arrays, sorting those sub-arrays, and then combining them to form a fully sorted array.
This approach of dividing the problem into smaller sub-problems, solving them, and then combining the
solutions is characteristic of the divide and conquer paradigm.

7. The best answer is:


d. 4 or more

Explanation: When analyzing the infix expression (()(()())(())), the maximum number of parentheses that
are pushed onto the stack at any one time is 4 or more. This occurs when the algorithm encounters the
sequence "(()())", where 4 opening parentheses are pushed onto the stack before any of them are
matched with closing parentheses.

8. The best answer is:


c. -18

Explanation: To evaluate the postfix expression 6324+-*, we perform the following steps:
- Push 6, 3, and 2 onto the stack.
- When encountering 4, pop 2 and 3, perform the operation 3 - 2 = 1, then push 1 back onto the stack.
- Finally, when encountering *, pop 1 and 6, perform the operation 6 * 1 = 6.
The final result left on the stack is -18.

9. The best answer is:


c. can be compounded on the way

Explanation: The statement "can be compounded on the way" is not true about insertion sort. Insertion
sort is an in-place sorting algorithm that does not require additional memory for compounding or merg-
ing sorted sub-arrays. It works by iteratively building a sorted portion of the array, so it does not involve
compounding on the way.
13. The best answer is:
d. 6

Explanation: To sort the given array using bubble sort, the following swaps are required:
- 5 and 2
- 5 and 3
- 5 and 4
- 7 and 4
- 7 and 6
- 7 and 5
This results in a total of 6 swaps.

14. The best answer is:


b. Front= (rear+ 1) mod MAX_SIZE

Explanation: Overflow in a normal queue of an array of size MAX_SIZE is detected when the front of the
queue is equal to (rear + 1) mod MAX_SIZE. This condition indicates that the queue has no available
space for the next element to be added, thus causing an overflow.

15. The best answer is:


a. A graph may contain no edges and many vertices

Explanation: A graph may contain no edges and many vertices. In graph theory, it is possible to have a
graph with only vertices and no edges connecting them. Such a graph is called a vertex set or isolated
vertices.

16. The best answer is:


d. O(n)

Explanation: The time complexity to count the number of elements in a linked list is O(n) because in the
worst case, you need to traverse the entire linked list to count all the elements.

17. The best answer is:


a. Either O(1) or O(n)

Explanation: The space complexity for deleting a linked list can be either O(1) or O(n). If the linked list is
singly linked, the space complexity for deleting it is O(1) because you only need to deallocate the mem-
ory for each node. However, if the linked list is doubly linked, you also need to deallocate memory for
the previous pointers, resulting in a space complexity of O(n).

18. The best answer is:


d. Implementing a doubly linked list is easier than singly linked list

Explanation: The statement that implementing a doubly linked list is easier than a singly linked list is
false. Implementing a doubly linked list requires more effort and complexity as compared to a singly
linked list due to the additional pointers for navigating in both directions.
19. The best answer is:
d. O(1)

Explanation: The worst case time complexity of inserting a node in a doubly linked list is O(1) because
you can directly insert a node at the beginning or end of the list, or after a given node without traversing
the entire list.

20. The best answer is:


a. O(n), O(log(n))

Explanation: The worst case complexity of searching in a binary search tree is O(n) when the tree is
skewed. However, the average case complexity of searching in a balanced binary search tree is O(log(n)).

21. The best answer is:


e. all

Explanation: All of the options are important properties of a recursive method. A recursive method must
call itself in its body, must have a base case or sentinel to stop the recursion, and must converge and
gradually stop.

22. The best answer is:


d. ABDC

Explanation: If the elements "A", "B", "C", and "D" are inserted into a queue respectively and are deleted
one at a time, they will be removed in the order "ABDC".

23. The best answer is:


d. Quick Sort

Explanation: A pivot element to partition an unsorted list is used in Quick Sort. Quick Sort selects a pivot
element and partitions the array around the pivot, which is crucial to its sorting process.

24. The best answer is:


a. True, True

Explanation: Binary search is used for searching in a sorted array, and its time complexity is O(log(n)).
Therefore, both statements i) and ii) are true.

25. The best answer is:


b. FIFO principle

Explanation: A queue follows the FIFO (First-In-First-Out) principle, where the element that is inserted
first is the one that is removed first.

26. The best answer is:


a. 0 or 2
Explanation: In a binary tree, each node can have either 0 or 2 children. This is a defining characteristic
of a binary tree.

27. The best answer is:


a. Stack

Explanation: Stack is a linear data structure as it follows the LIFO (Last-In-First-Out) principle and has a
linear ordering of elements.

28. The best answer is:


d. None of above

Explanation: Arrays and linked lists are both linear data structures, so none of the options given are non-
linear data structures.

29. The best answer is:


c. Merge sort

Explanation: Merge sort is a sorting algorithm of divide and conquer type, where the unsorted list is di-
vided into smaller sublists, sorted individually, and then merged back together.

30. The best answer is:


d. None of the above

Explanation: Both data and operations are part of the Abstract Data Type (ADT) description, so none of
the options given are not part of the ADT description.

You might also like