Mcqs
Loop Detection
1. What is a node in a singly linked list?
*
A) The first element
B) The last element
C) An individual element
D) A pointer to the middle element
Correct answer
C) An individual element
2. In a doubly linked list, each node contains how many pointers?
A) One
B) Two
C) Three
D) Four
Correct answer
B) Two
3.In which type of linked list is loop detection not applicable?
A) Singly linked list
B) Doubly linked list
C) Circular linked list
D) Dynamic linked list
Correct answer
A) Singly linked list
4.Which of the following data structures is NOT typically used to implement a linked
list?
A) Array
B) Pointer
C) Node
D) Reference
Correct answer
A) Array
5. In a circular linked list, what is the difference between the last node's "next"
pointer and the first node's "next" pointer?
A) There is no difference
B) The last node points to the first node
C) The first node points to the last node
D) The last node points to null
6. Which of the following is a drawback of the Floyd's algorithm?
A) It may not always detect loops
B) It has a high space complexity
C) It requires sorting the linked list
D) It cannot handle singly linked lists
Correct answer
A) It may not always detect loops
7.What is a common method for detecting loops in a singly linked list?
A) Using a counter variable
B) Using a hash table
C)Using two pointers (slow and fast)
D) Traversing the list backward
8. What is the time complexity of the Floyd's algorithm for loop detection in a linked
list?
A) O(1)
B) O(n)
C) O(log n)
D) O(n^2)
Correct answer
B) O(n)
9. What is the space complexity of the Floyd's algorithm for loop detection in a linked
list?
A) O(1)
B) O(n)
C) O(log n)
D) O(n^2)
Correct answer
A) O(1)
10.Which of the following statements is true when comparing hashing and Floyd's
Tortoise algorithm for loop detection in linked lists or sequences?
A) Hashing guarantees constant time complexity for loop detection.
B) Floyd's Tortoise algorithm guarantees linear time complexity for loop detection.
C) Hashing requires additional memory to store hash values.
D) Floyd's Tortoise algorithm is not suitable for loop detection in singly linked lists.
Correct answer
C) Hashing requires additional memory to store hash values.
2.Sort the bitonic DLL
1.Which of the following data structures is suitable for implementing a bitonic doubly
linked list (DLL)?
0/1
A) ArrayList
B) LinkedList
C) Stack
D) PriorityQueue
Correct answer
B) LinkedList
2.What is a bitonic sequence?
0/1
A) A sequence of numbers with random order
B) A sequence of numbers that alternates between increasing and decreasing order
C) A sequence of numbers sorted in descending order
D) A sequence of numbers sorted in ascending order
Correct answer
B) A sequence of numbers that alternates between increasing and decreasing order
3.Which algorithm is commonly used to sort a bitonic sequence?
0/1
A) Quick Sort
B) Merge Sort
C) Bitonic Sort
D) Bubble Sort
Correct answer
C) Bitonic Sort
4.In the context of sorting a bitonic DLL, what does "bitonic merging" refer to?
0/1
A) Merging two sorted lists into a single sorted list
B) Merging two bitonic sequences into a single bitonic sequence
C) Combining two sorted arrays
D) Rearranging elements in a bitonic sequence
Correct answer
B) Merging two bitonic sequences into a single bitonic sequence
5.which data structure can be used to efficiently implement bitonic merging for a
bitonic DLL?
0/1
A) ArrayList
B) Stack
C) PriorityQueue
D) Deque
Correct answer
D) Deque
6. Which of the following is NOT a step involved in sorting a bitonic DLL?
0/1
A) Identifying the bitonic point
B) Splitting the list into two sublists
C) Merging the two sublists
D) Reversing the sublist before the bitonic point
Correct answer
D) Reversing the sublist before the bitonic point
7. How many sorting passes are required to completely sort a bitonic DLL?
0/1
A) One
B) Two
C) Three
D) It depends on the size of the list
Correct answer
B) Two
8.Which sorting algorithm is commonly used to sort the two sublists in a bitonic DLL?
0/1
A) Bubble Sort
B) Quick Sort
C) Merge Sort
D) Insertion Sort
Correct answer
C) Merge Sort
9.What is the Space complexity of sorting a bitonic DLL with n elements?
1/1
A) O(1)
B) O(log n)
C) O(n log n)
D) O(n^2)
10.In a bitonic DLL, where does the bitonic point occur?
0/1
A) At the beginning of the list
B) At the end of the list
C) It can occur at any position
D) There is no bitonic point in a DLL
Correct answer
C) It can occur at any position
3. Segregate even & odd nodes in a
Linked list
1.To segregate even and odd nodes, you need to iterate through the linked list once.
1/1
a) True
b) False
2.Which of the following operations is NOT typically required when segregating even
and odd nodes in a linked list?
0/1
a) Insertion
b) Deletion
c) Swapping
d) Sorting
Correct answer
d) Sorting
3.How can you identify whether a number is even or odd?
0/1
a) Check if it is divisible by 2
b) Check if it is a prime number
c) Check if it is a multiple of 5
d) Check if it is greater than 10
Correct answer
a) Check if it is divisible by 2
4.In an in-place solution for segregating even and odd nodes, what is the primary
goal?
1/1
a) To minimize time complexity
b) To minimize space complexity
c) To create a new linked list
d) To maximize the number of operations
5.Which of the following is NOT an in-place method for segregating even and odd
nodes?
0/1
a) Creating two separate linked lists
b) Rearranging nodes within the existing list
c) Using additional memory for a stack
d) Swapping nodes in place
Correct answer
a) Creating two separate linked lists
6. In the context of segregating even and odd nodes, what is the significance of the
"previous" pointer?
0/1
a) It points to the previous node.
b) It stores the address of the head node.
c) It is not relevant to this operation.
d) It is used for deleting nodes.
Correct answer
a) It points to the previous node.
7.In an in-place solution for segregating even and odd nodes, what is the final step
after rearranging the nodes?
1/1
a) Reversing the entire linked list
b) Swapping the even and odd parts
c) Updating the "tail" pointer of the even part
d) Merging the even and odd parts
8.Which pointer do you need to update when rearranging nodes in an in-place
solution for segregating even and odd nodes?
1/1
a) Only the next pointer
b) Only the previous pointer
c) Both next and previous pointers
d) Neither next nor previous pointers
9. What data structure is commonly used to represent a singly linked list?
1/1
a) Array
b) Stack
c) Queue
d) Linked List
10.In the in-place approach, what is the role of the "evenTail" pointer?
1/1
a) To track the last even node in the list
b) To count the number of even nodes
c) To reverse the order of even nodes
d) To switch the positions of even and odd nodes
4. Merge sort for DLL
1.What is Merge Sort?
0/1
a) A sorting algorithm that operates only on arrays
b) A sorting algorithm that operates only on linked lists
c) A divide-and-conquer sorting algorithm
d) A sorting algorithm that uses a stack data structure
Correct answer
c) A divide-and-conquer sorting algorithm
2. Why is Merge Sort preferred for sorting DLLs?
0/1
a) It has a lower time complexity compared to other sorting algorithms
b) It doesn't require additional memory for sorting DLLs
c) It is easy to implement for DLLs
d) It efficiently utilizes the DLL's bidirectional traversal capability
Correct answer
d) It efficiently utilizes the DLL's bidirectional traversal capability
3. What is the time complexity of Merge Sort for DLLs with 'n' elements?
0/1
a) O(n)
b) O(n * log(n))
c) O(n^2)
d) O(log(n))
Correct answer
b) O(n * log(n))
4. In Merge Sort for DLLs, what is the base case?
0/1
a) When the DLL has a single element
b) When the DLL has two elements
c) When the DLL is empty
d) When the DLL has three elements
Correct answer
a) When the DLL has a single element
5. How is a DLL divided during the Merge Sort process?
0/1
a) By selecting a random pivot element
b) By splitting it into two equal halves
c) By finding the middle element
d) By dividing it into an even and an odd sublist
Correct answer
c) By finding the middle element
6. What is the purpose of the "Merge" function in Merge Sort for DLLs?
0/1
a) To split the DLL into two sublists
b) To reverse the order of elements in the DLL
c) To combine and sort two sorted sublists
d) To find the middle element of the DLL
Correct answer
c) To combine and sort two sorted sublists
7. In Merge Sort for DLLs, which data structure is used to perform the merging of
sublists efficiently?
0/1
a) Array
b) Stack
c) Queue
d) Recursion
Correct answer
a) Array
8. In Merge Sort for DLLs, how do you merge two sorted DLLs?
0/1
a) By using a temporary linked list
b) By using a stack data structure
c) By comparing and rearranging nodes from both DLLs
d) By reversing one of the DLLs
Correct answer
c) By comparing and rearranging nodes from both DLLs
9. In Merge Sort, how is the DLL divided during the recursive process?
0/1
a) Into three equal parts
b) Into two equal parts
c) Into four equal parts
d) It is not divided
Correct answer
b) Into two equal parts
10. Which of the following is true about the stability of Merge Sort for DLLs?
0/1
a) It is always stable
b) It is never stable
c) It depends on the implementation
d) It is stable only for small DLLs
Correct answer
a) It is always stable
5. Minimum Stack
1. What is a stack data structure?
0/1
A) A linear data structure with a FIFO (First-In-First-Out) order.
B) A linear data structure with a LIFO (Last-In-First-Out) order.
C) A hierarchical data structure.
D) A non-linear data structure.
Correct answer
B) A linear data structure with a LIFO (Last-In-First-Out) order.
2.Which operation involves inserting an item into a stack?
0/1
A) Push
B) Pop
C) Peek
D) Swap
Correct answer
A) Push
3.Which operation involves deleting an item from the stack?
0/1
A) Push
B) Pop
C) Peek
D) Swap
Correct answer
B) Pop
4.Which operation involves displaying the contents of the stack without removing it?
1/1
A) Push
B) Pop
C) Peek
D) Swap
5.Which operation allows you to retrieve the minimum element from a stack
efficiently?
0/1
A) getMin()
B) findMinimum()
C) retrieveMinimum()
D) minimumElement()
Correct answer
A) getMin()
6. Which of the following is NOT a valid approach to implement the "get minimum"
operation for a stack?
0/1
A) Using an additional stack to track minimums.
B) Storing the minimum element in a variable.
C) Scanning the entire stack to find the minimum when needed.
D) Using a priority queue.
Correct answer
C) Scanning the entire stack to find the minimum when needed.
7.What is the advantage of using a "get minimum" stack over scanning the entire
stack to find the minimum when needed?
0/1
A) "Get minimum" stack has a smaller memory footprint.
B) "Get minimum" stack has a faster time complexity.
C) "Get minimum" stack allows elements to be in any order.
D) "Get minimum" stack has fewer operations.
Correct answer
B) "Get minimum" stack has a faster time complexity.
8.In a "get minimum" stack, what happens when you pop the minimum element from
the stack?
0/1
A) The minimum element is lost, and you cannot retrieve it.
B) The minimum element is moved to the top of the stack.
C) The minimum element is pushed onto the auxiliary stack.
D) The stack becomes empty.
Correct answer
A) The minimum element is lost, and you cannot retrieve it.
9.What is the time complexity of the "get minimum" operation for a stack
implemented with an additional stack to track minimums?
0/1
A) O(1)
B) O(log N)
C) O(N)
D) O(N^2)
Correct answer
A) O(1)
10.What is the space complexity of a stack without any additional data structures?
0/1
A) O(1)
B) O(N)
C) O(log N)
D) O(N^2)
Correct answer
A)O(1)
      6. THE CELEBRITY PROBLEM
1. What is the Celebrity Problem in computer science?
1/1
A) A problem related to identifying famous people in a social network.
B) A problem related to finding a person who is widely recognized.
C) A problem of identifying a person who is known by everyone but knows no one.
D) A problem of identifying a popular movie star.
2. In the Celebrity Problem, what does it mean for someone to be a "celebrity"?
1/1
A) They have a large social media following.
B) They are famous in their field.
C) They are known by everyone but know no one.
D) They are a popular public figure.
3. Which data structure is commonly used to solve the Celebrity Problem efficiently?
0/1
A) Stack
B) Queue
C) Graph
D) Array
Correct answer
A) Stack
4. In the Celebrity Problem, how many people need to vouch for someone to be
considered a celebrity?
0/1
A) At least one person.
B) At least two people.
C) At least half of the total people.
D) Everyone in the group.
Correct answer
D) Everyone in the group.
5.In the Celebrity Problem, what is the primary goal of the algorithm?
0/1
A) To identify the most famous person.
B) To minimize the number of comparisons.
C) To find a person with the largest social network following.
D) To find a person known by everyone.
Correct answer
D) To find a person known by everyone.
6.How is the Celebrity Problem typically represented?
1/1
A) Using a circular linked list.
B) With a binary search tree.
C) Using a square matrix.
D) Through a hash table.
7. Which factor primarily influences the time complexity of the Celebrity Problem
algorithm?
0/1
A) The number of iterations.
B) The number of comparisons.
C) The number of recursive calls.
D) The number of celebrities.
Correct answer
B) The number of comparisons.
8.How does the time complexity of the optimized Celebrity Problem algorithm scale
with an increase in the number of people in the group?
1/1
A) It remains constant.
B) It decreases.
C) It increases linearly.
D) It increases exponentially.
9. What is the time complexity of the optimized algorithm for solving the Celebrity
Problem?
1/1
A) O(1)
B) O(log N)
C) O(N)
D) O(N^2)
10. What is the space complexity of the optimized algorithm for solving the Celebrity
Problem?
0/1
A) O(1)
B) O(N)
C) O(log N)
D) O(N^2)
Correct answer
B) O(N)
7. Tower of Hanoi
1.In the Tower of Hanoi problem, what is the objective?
0/1
A. To move all disks from one rod to another rod.
B. To sort the disks in ascending order.
C. To find the largest disk.
D. To find the total number of moves required.
Correct answer
A. To move all disks from one rod to another rod.
2. How many rods are used in the classic Tower of Hanoi problem?
0/1
A. 1
B. 2
C. 3
D. 4
Correct answer
C. 3
3.In the iterative solution to the Tower of Hanoi, how is the problem divided into
subproblems?
0/1
A. Divide the disks into two equal parts.
B. Divide the disks into three equal parts.
C. Divide the disks into smaller and smaller subproblems.
D. Divide the disks into four equal parts.
Correct answer
A. Divide the disks into two equal parts.
4.What is the minimum number of moves required to solve the Tower of Hanoi
problem with 4 disks?
0/1
A. 4
B. 7
C. 15
D. 31
Correct answer
B. 7
5.Which data structure is commonly used to implement the iterative solution to the
Tower of Hanoi problem?
0/1
A. Stack
B. Queue
C. Array
D. LinkedList
Correct answer
A. Stack
6.In the iterative Tower of Hanoi solution, how are the disks moved between the
rods?
0/1
A. Using recursion
B. Using a loop
C. Using dynamic programming
D. Using a binary tree
Correct answer
B. Using a loop
7.What is the time complexity of the iterative solution to the Tower of Hanoi problem
with 'n' disks?
0/1
A. O(n)
B. O(2^n)
C. O(log n)
D. O(n^2)
Correct answer
B. O(2^n)
8.In the iterative Tower of Hanoi solution, what is the purpose of using a stack data
structure?
1/1
A. To store the rods.
B. To keep track of the number of disks.
C. To maintain the order of disk movements.
D. To simulate the recursive calls in an iterative manner.
9.How does the iterative Tower of Hanoi solution ensure that the correct disk
movement order is maintained?
0/1
A. By using a queue data structure.
B. By using a depth-first search algorithm.
C. By using a loop and a stack data structure.
D. By using a breadth-first search algorithm.
Correct answer
C. By using a loop and a stack data structure.
10.What is the space complexity of the iterative Tower of Hanoi solution?
0/1
A. O(1)
B. O(n)
C. O(log n)
D. O(n^2)
Correct answer
B. O(n)
8. STOCK SPAN PROBLEM
9. priority queue using doubly linked list
1. What is a Priority Queue?
0/1
A. A queue with fixedsize capacity
B. A queue with variablesize capacity
C. A queue that follows Last In First Out (LIFO) order
D. A queue where each element has an associated priority
Correct answer
D. A queue where each element has an associated priority
2. Which data structure is suitable for implementing a Priority Queue using a DLL?
0/1
A. Stack
B. Queue
C. Linked List
D. Binary Heap
Correct answer
C. Linked List
3. In a Priority Queue implemented with a DLL, which operation takes O(1) time
complexity?
0/1
A. Insertion
B. Deletion
C. Searching
D. Traversal
Correct answer
A. Insertion
4. What is the key feature of a Priority Queue that differentiates it from a regular
queue?
0/1
A. FIFO (First-In-First-Out) behavior
B. LIFO (Last-In-First-Out) behavior
C. Elements are ordered by priority
D. No ordering of elements
Correct answer
C. Elements are ordered by priority
5. How are elements stored in a Priority Queue based on a DLL?
0/1
A. In a random order
B. In ascending order
C. In descending order
D. In order of insertion
Correct answer
B. In ascending order
6. Which operation is used to remove and return the highest-priority element from a
Priority Queue implemented with a DLL?
0/1
A. pop()
B. peek()
C. poll()
D. push()
Correct answer
C. poll()
7.How is the highest-priority element determined in a Priority Queue based on a
DLL?
0/1
A. By its position in the DLL
B. By the value of its key
C. By its index in the DLL
D. By its order of insertion
Correct answer
B. By the value of its key
8.What is the time complexity of inserting an element into a Priority Queue
implemented with a DLL, assuming the DLL is already sorted by priority?
0/1
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Correct answer
C. O(n)
9.What is the space complexity of a Priority Queue implemented with a DLL?
0/1
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Correct answer
B. O(n)
10.Which operation is used to add an element to a Priority Queue implemented with
a DLL?
1/1
A. add()
B. push()
C. insert()
D. enqueue()
10. Sort without extra Space
1.Which sorting algorithm divides the array into a sorted and an unsorted region and
repeatedly selects the minimum element from the unsorted region and moves it to
the sorted region?
0/1
a) Insertion Sort
b) Quick Sort
c) Selection Sort
d) Heap Sort
Correct answer
c) Selection Sort
2.Which sorting algorithm uses a pivot element and partitions the array into two
subarrays such that elements less than the pivot are on the left and elements greater
than the pivot are on the right?
a) Merge Sort
b) Insertion Sort
c) Quick Sort
d) Radix Sort
Correct answer
c) Quick Sort
3. Which sorting algorithm works by repeatedly dividing the input array into two
subarrays, sorting them, and then merging them?
0/1
a) Quick Sort
b) Insertion Sort
c) Merge Sort
d) Selection Sort
Correct answer
c) Merge Sort
4.In the context of "sorting without extra space," which data structure is commonly
used for in-place sorting algorithms?
0/1
a) Linked List
b) Hash Table
c) Binary Tree
d) Priority Queue
Correct answer
a) Linked List
5.In-place sorting means that:
0/1
a) Extra space is not used
b) Extra space is used
c) The algorithm is fast
d) The algorithm is stable
Correct answer
a) Extra space is not used
6.Which sorting algorithm is often used to implement priority queues due to its heap
data structure?
0/1
a) Merge Sort
b) Quick Sort
c) Radix Sort
d) Heap Sort
Correct answer
d) Heap Sort
7.Which sorting algorithm's performance is significantly affected by the choice of the
pivot element?
1/1
a) Insertion Sort
b) Bubble Sort
c) Selection Sort
d) Quick Sort
8.Which sorting algorithm does not perform well with duplicate values in the array
and can be unstable?
0/1
a) Quick Sort
b) Insertion Sort
c) Selection Sort
d) Merge Sort
Correct answer
a) Quick Sort
9.Which sorting algorithm is not a comparison-based sorting algorithm and is
suitable for integers or fixed-length strings?
1/1
a) Insertion Sort
b) Heap Sort
c) Radix Sort
d) Quick Sort
10.What does it mean to "sort without extra space" in the context of sorting
algorithms?
0/1
a) Creating a new array to store the sorted elements
b) Rearranging elements in the original array to achieve a sorted order
c) Using additional memory to speed up the sorting process
d) Sorting elements in a separate data structure
Correct answer
b) Rearranging elements in the original array to achieve a sorted order
11. Max Sliding Window
1. What is the Max Sliding Window problem about?
0/1
a) Finding the minimum element in a sliding window
b) Finding the maximum element in a sliding window
c) Counting the number of elements in a sliding window
d) Summing the elements in a sliding window
Correct answer
a) Finding the minimum element in a sliding window
2. In the Max Sliding Window problem, what is the "window size"?
0/1
a) The size of the entire array
b) The number of windows in the array
c) The number of elements in each window
d) The number of distinct elements in the array
Correct answer
c) The number of elements in each window
3. Which data structure is commonly used to efficiently solve the Max Sliding
Window problem?
1/1
a) Linked List
b) Stack
c) Queue
d) Array
4.What is the time complexity of the Naive Approach for solving the Max Sliding
Window problem, where 'N' is the size of the array, and 'K' is the window size?
1/1
a) O(N)
b) O(N * K)
c) O(N * log(K))
d) O(N^2)
5.Which approach is efficient for small windows or large arrays when solving the Max
Sliding Window problem?
0/1
a) Naive Approach
b) Using Self-balancing Tree
c) Using Max-Heap
d) Using Deque
Correct answer
b) Using Self-balancing Tree
6.When using a self-balancing tree for the Max Sliding Window problem, what is the
primary benefit of this approach?
0/1
a) It has the best time complexity for all scenarios.
b) It requires the least amount of memory.
c) It is simple and easy to implement.
d) It can efficiently handle large windows in large arrays.
Correct answer
a) It has the best time complexity for all scenarios.
7.What is the time complexity of the approach that uses a Max-Heap for the Max
Sliding Window problem?
1/1
a) O(N)
b) O(N * K)
c) O(N * log(K))
d) O(K * log(K))
8.What is the space complexity of the approach that uses a Max-Heap for the Max
Sliding Window problem?
0/1
a) O(N)
b) O(K)
c) O(N * log(K))
d) O(K * log(K))
Correct answer
b) O(K)
9. Which approach is the most efficient in terms of both time and space complexity
for solving the Max Sliding Window problem, particularly when dealing with large
windows?
0/1
a) Naive Approach
b) Using Self-balancing Tree
c) Using Max-Heap
d) Using Deque
Correct answer
d) Using Deque
10.What does the term "sliding window" refer to in this problem?
0/1
a) A visual representation of the array
b) A graphical user interface for data visualization
c) A fixed-size subarray moving through the original array
d) A software window displaying the array's contents
Correct answer
c) A fixed-size subarray moving through the original array