Nothing Special   »   [go: up one dir, main page]

0% found this document useful (0 votes)
0 views19 pages

dsa

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 19

• Which of the following data structures is linear?

a) Tree
b) Graph
c) Stack
d) Hash Table
Answer: c) Stack

• Which of the following is the time complexity of adding an element to a stack


implemented with an array?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)

• What is the best-case time complexity of Binary Search?

a) O(n)
b) O(n log n)
c) O(1)
d) O(log n)
Answer: c) O(1)

• Which data structure is most suitable for implementing a recursive function?

a) Queue
b) Stack
c) Array
d) Linked List
Answer: b) Stack

• What is the minimum number of nodes in a complete binary tree with depth d?

a) 2^d - 1
b) 2^(d+1) - 1
c) 2^(d-1)
d) d
Answer: a) 2^d – 1
• In a circular linked list, how do you make a node the new head?

a) Add the node at the beginning


b) Set the previous node’s next to the new node
c) Set the next pointer of the last node to the new node
d) None of the above
Answer: c) Set the next pointer of the last node to the new node

• Which sorting algorithm is best for a linked list?

a) Bubble Sort
b) Quick Sort
c) Heap Sort
d) Merge Sort
Answer: d) Merge Sort

• If the root node of a max-heap is removed, what operation is performed to


restore the max-heap property?

a) Insertion
b) Deletion
c) Heapify
d) Bubble up
Answer: c) Heapify

• Which operation is performed last when pushing an element in a linked list?

A. Allocate memory
B. Update the head pointer
C. Assign data to the node
D. Connect the new node with other nodes
Answer: B) Update the head pointer

• What is the time complexity for inserting an element at the end of a singly linked
list if a pointer to the last node is maintained?

A) O(1)

B) O(n)

C) O(log n)
D) O(n log n)
Answer: A) O(1)

• What is the average time complexity for searching an element in a linked list?

A) O(1)

B) O(log n)

C) O(n)

D) O(n^2)
Answer: C) O(n)

• Which of the following data structures can be used to implement a queue?

A) Stack

B) Array

C) Linked List

D) Both B and C
Answer: D) Both B and C

• What is the main advantage of a doubly linked list over a singly linked list?

A) Requires less memory

B) Allows bidirectional traversal

C) Easier to implement

D) Faster for searching


Answer: B) Allows bidirectional traversal

• Which operation has the highest time complexity in an adjacency matrix


representation of a graph?

A) Finding all neighbors of a node

B) Checking if two nodes are adjacent

C) Inserting a new edge

D) Deleting a node
Answer: D) Deleting a node
• In an AVL tree, what is the maximum height difference between the left and right
subtrees of any node?

A) 1

B) 2

C) 3

D) 4
Answer: A) 1

• Which of the following is true for an undirected graph represented using an


adjacency list?

A) It always has a unique path between two nodes

B) The memory used depends on the number of vertices and edges

C) Memory required is always proportional to the square of vertices

D) None of the above


Answer: B) The memory used depends on the number of vertices and edges

• What is the minimum height of a binary search tree with 31 nodes?

A) 5

B) 4

C) 6

D) 7
Answer: A) 5

• Which traversal method is used for breadth-first traversal in a binary tree?

A) Inorder

B) Preorder

C) Postorder

D) Level order
Answer: D) Level order

• Which data structure is used for depth-first search (DFS) in graphs?

A) Queue
B) Stack

C) Priority Queue

D) Array
Answer: B) Stack

• Which of the following applications can use a circular queue effectively?

A) BFS in graph traversal

B) Round-robin scheduling in operating systems

C) Heap operations

D) Inorder traversal of binary trees


Answer: B) Round-robin scheduling in operating systems

• What is the worst-case time complexity of inserting an element in an AVL tree?


▪ O(log n)
▪ O(n)
▪ O(n^2)
▪ O(1)
Answer: A) O(log n)
• Which data structure supports the "First In, First Out" (FIFO) order?
▪ Stack
▪ Queue
▪ Linked List
▪ Tree
Answer: B) Queue
• What is the space complexity of a breadth-first search (BFS) in a binary tree?
▪ O(1)
▪ O(n)
▪ O(log n)
▪ O(n^2)
Answer: B) O(n)
• Which of the following methods is used to traverse a binary search tree in sorted
order?
▪ Preorder
▪ Postorder
▪ Inorder
▪ Level order
Answer: C) Inorder
• What is the time complexity of deleting a node from a singly linked list with n
nodes?
▪ O(1)
▪ O(n)
▪ O(n log n)
▪ O(n^2)
Answer: B) O(n)
• Which of the following algorithms is used to find the shortest path in a weighted
graph?
▪ DFS
▪ BFS
▪ Dijkstra’s Algorithm
▪ Floyd-Warshall Algorithm
Answer: C) Dijkstra’s Algorithm
• In a priority queue implemented with a binary heap, what is the time complexity
of inserting a new element?
▪ O(log n)
▪ O(n)
▪ O(n log n)
▪ O(1)
Answer: A) O(log n)
• Which traversal technique uses backtracking?
▪ Level order
▪ Breadth-first traversal
▪ Depth-first traversal
▪ Binary search
Answer: C) Depth-first traversal
• What is the minimum number of edges in a connected graph with n vertices?
▪ n-1
▪ n
▪ n+1
▪ n^2
Answer: A) n - 1
• Which of the following statements is true for a circular queue implemented with
an array?
• Elements can only be inserted at one end
• Elements can be removed from both ends
• When the queue is full, the front and rear pointers are at the same position
• None of the above
Answer: C) When the queue is full, the front and rear pointers are at the same
position
• What is the time complexity of searching for an element in a balanced binary
search tree?
• O(n)
• O(log n)
• O(n log n)
• O(1)
Answer: B) O(log n)
• Which data structure is commonly used in implementing a cache?
• Stack
• Queue
• Hash Map
• Linked List
Answer: C) Hash Map
• What is the minimum number of nodes required to form a full binary tree of
height h?
• 2^h - 1
• 2^(h+1) - 1
• 2^(h-1)
• h
Answer: A) 2^h - 1
• Which of the following is a stable sorting algorithm?
• Quick Sort
• Merge Sort
• Heap Sort
• Selection Sort
Answer: B) Merge Sort
• In which scenario is a circular linked list useful?
• Implementing undo functionality
• CPU scheduling in operating systems
• Maintaining a To-Do list
• All of the above
Answer: D) All of the above
• Which data structure is used by compilers to check for matching parentheses in
an expression?
• Queue
• Tree
• Stack
• Array
Answer: C) Stack
• What is the time complexity for accessing an element by index in an array?
• O(1)
• O(log n)
• O(n)
• O(n^2)
Answer: A) O(1)
• What is the height of an AVL tree with n nodes?
• O(log n)
• O(n)
• O(n^2)
• O(1)
Answer: A) O(log n)
• Which traversal method should be used to clone a binary tree?
• Inorder
• Preorder
• Postorder
• Level Order
Answer: B) Preorder
• Which of the following data structures does NOT store elements in sorted order?
• Stack
• Binary Search Tree
• AVL Tree
• Heap
Answer: A) Stack
• Which of the following is the most suitable data structure to implement a
priority queue?
• Array
• Linked List
• Binary Heap
• Binary Search Tree
Answer: C) Binary Heap
• Which of the following methods is used to delete an element from a binary heap?
• Remove the root and Heapify
• Remove the root and adjust the tree
• Simply remove the node
• Traverse and delete
Answer: A) Remove the root and Heapify
• Which of the following trees is self-balancing?
• Binary Search Tree
• AVL Tree
• Splay Tree
• Both B and C
Answer: D) Both B and C
• What is the worst-case time complexity of bubble sort?
• O(log n)
• O(n)
• O(n^2)
• O(n log n)
Answer: C) O(n^2)
• In a linked list, the head pointer is generally used to point to which node?
• Last node
• Middle node
• First node
• None of the above
Answer: C) First node
• Which of the following data structures is best suited for hierarchical data?
• Stack
• Array
• Tree
• Queue
Answer: C) Tree
• What is the maximum number of children a binary tree node can have?
• 1
• 2
• 3
• Unlimited
Answer: B) 2
• Which of the following is an example of non-linear data structure?
• Stack
• Queue
• Linked List
• Tree
Answer: D) Tree
• What is the time complexity for insertion in an unsorted array?
• O(1)
• O(log n)
• O(n)
• O(n^2)
Answer: A) O(1)
• Which sorting algorithm is typically used for external sorting?
• Quick Sort
• Bubble Sort
• Merge Sort
• Selection Sort
Answer: C) Merge Sort
• Which of the following data structures is used in implementing LRU (Least
Recently Used) cache?
• Queue
• Linked List and Hash Map
• Stack
• Tree
Answer: B) Linked List and Hash Map
• What is the maximum number of edges in a simple, undirected graph with n
vertices?
• n
• n(n-1)/2
• n^2
• n/2
Answer: B) n(n-1)/2
• Which of the following searching algorithms is best suited for a sorted array?
• Linear Search
• Binary Search
• Jump Search
• Both B and C
Answer: D) Both B and C
• Which of the following is not a balanced binary tree?
• AVL Tree
• Red-Black Tree
• Binary Search Tree
• 2-3 Tree
Answer: C) Binary Search Tree
• In a binary max heap, the largest element is found at which node?
• Leaf node
• Root node
• Any node
• Right-most node
Answer: B) Root node
• Which data structure is optimal for finding the shortest path in an unweighted
graph?
• DFS
• BFS
• Dijkstra's Algorithm
• Bellman-Ford Algorithm
Answer: B) BFS
• What is the time complexity of reversing a linked list?
• O(1)
• O(log n)
• O(n)
• O(n log n)
Answer: C) O(n)
• Which traversal order is used in depth-first search (DFS) of a graph?
• Inorder
• Preorder
• Postorder
• Level Order
Answer: B) Preorder
• In an adjacency matrix representation of a graph, the space complexity is:
• O(n)
• O(log n)
• O(n^2)
• O(n log n)
Answer: C) O(n^2)
• Which of the following is true for a complete binary tree?
• Every node has exactly two children
• All levels except possibly the last are completely filled

C) All leaf nodes are at the same level

D) None of the above


Answer: B) All levels except possibly the last are completely filled

• What is the time complexity of accessing an element in a hash table?

A) O(1)

B) O(log n)

C) O(n)

D) O(n log n)
Answer: A) O(1)

• Which of the following is the correct property of a max-heap?

A) Each parent node is greater than or equal to its child nodes

B) Each parent node is less than or equal to its child nodes


C) All nodes are equal

D) None of the above


Answer: A) Each parent node is greater than or equal to its child nodes

• What is the time complexity of searching for an element in an unbalanced binary


search tree?

A) O(n)

B) O(log n)

C) O(1)

D) O(n log n)
Answer: A) O(n)

• In which data structure is insertion performed at the rear and deletion at the front?

A) Stack

B) Queue

C) Linked List

D) Tree
Answer: B) Queue

• Which of the following sorting algorithms has a time complexity of O(n^2) in its
average case?

A) Quick Sort

B) Merge Sort

C) Selection Sort

D) Counting Sort
Answer: C) Selection Sort

• What is the minimum number of edges in a tree with n nodes?

A) 0

B) n - 1

C) n
D) 2n - 1
Answer: B) n - 1

• Which of the following is NOT a property of binary search trees?

A) The left subtree of a node contains only nodes with values less than the node’s key

B) The right subtree of a node contains only nodes with values greater than or equal to the
node’s key

C) Both left and right subtrees are also binary search trees

D) None of the above


Answer: D) None of the above

• In a directed acyclic graph (DAG), which algorithm is used to find the topological
order?

A) Dijkstra’s Algorithm

B) BFS

C) Topological Sort

D) DFS
Answer: C) Topological Sort

• Which data structure is used for implementing a minimum spanning tree?

A) Stack

B) Queue

C) Graph

D) Disjoint Set
Answer: D) Disjoint Set

• Which of the following algorithms does not use divide and conquer?

A) Merge Sort

B) Quick Sort

C) Binary Search

D) Selection Sort
Answer: D) Selection Sort
• What is the time complexity of enqueue and dequeue operations in a queue
implemented with a linked list?

A) O(1)

B) O(log n)

C) O(n)

D) O(n log n)
Answer: A) O(1)

• What is the height of a complete binary tree with n nodes?

A) O(log n)

B) O(n)

C) O(n log n)

D) O(1)
Answer: A) O(log n)

• Which data structure is suitable for applications involving Last-In, First-Out (LIFO)
operations?

A) Stack

B) Queue

C) Deque

D) Tree
Answer: A) Stack

• Which sorting algorithm is suitable for sorting data with a small range of integer
values?

A) Merge Sort

B) Heap Sort

C) Counting Sort

D) Quick Sort
Answer: C) Counting Sort

• In a binary tree, if a node has no children, it is called a:


A) Root node

B) Leaf node

C) Internal node

D) Parent node
Answer: B) Leaf node

• Which data structure is typically used for implementing DFS in a graph?

A) Queue

B) Stack

C) Priority Queue

D) Array
Answer: B) Stack

• In a hash table, collisions are resolved by:

A) Rehashing

B) Chaining

C) Linear Probing

D) All of the above


Answer: D) All of the above

• What is the time complexity for removing an element from a doubly linked list?

A) O(1)

B) O(log n)

C) O(n)

D) O(n log n)
Answer: A) O(1)

• Which of the following graph traversal algorithms can find the shortest path in an
unweighted graph?

A) DFS

B) BFS
C) Dijkstra's Algorithm

D) Kruskal's Algorithm
Answer: B) BFS

• Which of the following data structures is used for implementing recursion?

A) Queue

B) Stack

C) Priority Queue

D) Array
Answer: B) Stack

• Which algorithm is the most efficient for finding the shortest path in a weighted
graph?

A) BFS

B) DFS

C) Dijkstra's Algorithm

D) Prim’s Algorithm
Answer: C) Dijkstra's Algorithm

• In a binary search tree, which node is visited last in postorder traversal?

A) Root

B) Left child

C) Right child

D) None of the above


Answer: A) Root

• Which of the following is a self-balancing binary tree?

A) Binary Search Tree

B) AVL Tree

C) Max-Heap

D) Red-Black Tree
Answer: B) AVL Tree
• Which sorting algorithm has the best time complexity in the average case for a large
dataset?

A) Quick Sort

B) Bubble Sort

C) Insertion Sort

D) Selection Sort
Answer: A) Quick Sort

• What is the time complexity of inserting a node in a binary search tree with n nodes?

A) O(log n)

B) O(n)

C) O(n log n)

D) O(1)
Answer: A) O(log n)

• Which data structure is used to check for balanced parentheses in an expression?

A) Queue

B) Stack

C) Hash Table

D) Graph
Answer: B) Stack

• What is the worst-case time complexity of linear search?

A) O(1)

B) O(log n)

C) O(n)

D) O(n^2)
Answer: C) O(n)

• Which traversal technique is generally used for breadth-first traversal in a binary


tree?

A) Inorder
B) Preorder

C) Postorder

D) Level order
Answer: D) Level order

• In which case is selection sort better than merge sort?

A) Large dataset

B) Small dataset

C) Random dataset

D) None of the above


Answer: B) Small dataset

• What is the minimum time complexity for deleting a node from a linked list with n
nodes?

A) O(1)

B) O(log n)

C) O(n)

D) O(n log n)
Answer: A) O(1)

• In a max-heap, the largest element is found at which node?

a) Leaf node
b) Root node
c) Right-most node
d) Left-most node
Answer: b) Root node

• Which of the following techniques is NOT a sorting algorithm?

a) Bubble Sort
b) Counting Sort
c) Radix Sort
d) Floyd-Warshall
Answer: d) Floyd-Warshall

• Which of the following operations is the most time-consuming in a hash table?


a) Insertion
b) Deletion
c) Searching
d) Collision resolution
Answer: d) Collision resolution

• Which data structure is used to handle recursion in a program?

a) Queue
b) Stack
c) Linked List
d) Tree
Answer: b) Stack

• Which sorting algorithm is known for being the fastest for small datasets?

a) Quick Sort
b) Bubble Sort
c) Insertion Sort
d) Selection Sort
Answer: c) Insertion Sort

• In a binary search tree, what is the time complexity for finding the minimum or
maximum element?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: b) O(log n)

• What is the advantage of a circular queue over a linear queue?

a) Fixed size
b) Better memory utilization
c) Simpler implementation
d) Allows random access
Answer: b) Better memory utilization

• What is the worst-case time complexity of merge sort?

a) O(n)
b) O(log n)
c) O(n log n)
d) O(n^2)
Answer: C) O(n log n)

• Which data structure is optimized for Last-In, First-Out (LIFO) operations?


a) Queue
b) Stack
c) Priority Queue
d) Linked List
Answer: b) Stack
• What is the purpose of balancing in a binary search tree? –
a) To reduce memory usage
b) To minimize search time
c) To improve insertion time
d) To enable constant time operations
Answer: b) To minimize search time

You might also like