CAT1 MCQs
CAT1 MCQs
Loop detection
1. What is a node in a singly linked list?
C) An individual element
2. In a doubly linked list, each node contains how many pointers?
B) Two (One for the previous node and one for the next node)
3. In which type of linked list is loop detection not applicable?
C) Circular linked list (Since it is inherently circular, loop detection is unnecessary)
4. Which of the following data structures is NOT typically used to implement a linked
list?
A) Array (Linked lists are dynamic and use pointers instead of contiguous memory
like arrays)
5. In a circular linked list, what is the difference between the last node's "next"
pointer and the first node's "next" pointer?
B) The last node points to the first node
6. Which of the following is a drawback of Floyd's algorithm?
B) It has a high space complexity (Incorrect)
Correct Answer: None of the above (Floyd’s algorithm has O(1) space complexity and
efficiently detects loops)
7. What is a common method for detecting loops in a singly linked list?
C) Using two pointers (slow and fast) (Floyd’s cycle detection algorithm)
8. What is the time complexity of Floyd's algorithm for loop detection in a linked list?
B) O(n)
9. What is the space complexity of Floyd's algorithm for loop detection in a linked
list?
A) O(1) (It only uses two pointers, not extra memory)
10. Which of the following statements is true when comparing hashing and Floyd's
Tortoise algorithm for loop detection?
B) Floyd's Tortoise algorithm guarantees linear time complexity for loop detection.
C) Hashing requires additional memory to store hash values. (Both B and C are
correct)
Here are the correct answers for the Celebrity Problem in computer science:
1. What is the Celebrity Problem in computer science?
C) A problem of identifying a person who is known by everyone but knows no one.
2. In the Celebrity Problem, what does it mean for someone to be a "celebrity"?
C) They are known by everyone but know no one.
3. Which data structure is commonly used to solve the Celebrity Problem efficiently?
A) Stack
4. In the Celebrity Problem, how many people need to vouch for someone to be
considered a celebrity?
D) Everyone in the group.
5. In the Celebrity Problem, what is the primary goal of the algorithm?
D) To find a person known by everyone.
6. How is the Celebrity Problem typically represented?
C) Using a square matrix.
7. Which factor primarily influences the time complexity of the Celebrity Problem
algorithm?
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?
C) It increases linearly.
9. What is the time complexity of the optimized algorithm for solving the Celebrity
Problem?
C) O(N)
10. What is the space complexity of the optimized algorithm for solving the Celebrity
Problem?
A) O(1)
Here are the correct answers for the Priority Queue using a Doubly Linked List (DLL):
1. What is a Priority Queue?
D) A queue where each element has an associated priority
2. Which data structure is suitable for implementing a Priority Queue using a DLL?
D) Binary Heap (Although a DLL can be used, a Binary Heap is more efficient for a
Priority Queue)
3. In a Priority Queue implemented with a DLL, which operation takes O(1) time
complexity?
A) Insertion (If inserting at the head or tail, depending on order maintenance)
4. What is the key feature of a Priority Queue that differentiates it from a regular
queue?
C) Elements are ordered by priority
5. How are elements stored in a Priority Queue based on a DLL?
B) In ascending order (or descending, based on priority definition)
6. Which operation is used to remove and return the highest-priority element from a
Priority Queue implemented with a DLL?
C) poll() (Common method for priority queue operations)
7. How is the highest-priority element determined in a Priority Queue based on a
DLL?
B) By the value of its key (Priority is based on key values)
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?
C) O(n) (Since insertion requires finding the correct position in a sorted DLL)
9. What is the space complexity of a Priority Queue implemented with a DLL?
B) O(n) (Each element takes additional space for pointers in a DLL)
10. Which operation is used to add an element to a Priority Queue implemented with a
DLL?
C) insert() (Since elements are inserted based on priority ordering)
Here are the correct answers for your Max Sliding Window problem questions:
1. What is the Max Sliding Window problem about?
b) Finding the maximum element in a sliding window
2. In the Max Sliding Window problem, what is the "window size"?
c) The number of elements in each window
3. Which data structure is commonly used to efficiently solve the Max Sliding Window
problem?
d) Array (but Deque is the best approach, often implemented using an 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?
b) O(N * K) (Checking each window separately leads to this complexity)
5. Which approach is efficient for small windows or large arrays when solving the Max
Sliding Window problem?
d) Using Deque (Deque allows us to efficiently track the max element in O(N) time
complexity)
6. When using a self-balancing tree for the Max Sliding Window problem, what is the
primary benefit of this approach?
d) It can efficiently handle large windows in large arrays. (Since operations in a
balanced tree take O(log K) time, it’s useful for large windows)
7. What is the time complexity of the approach that uses a Max-Heap for the Max
Sliding Window problem?
c) O(N * log(K)) (Each insertion/deletion in the heap takes O(log K), leading to this
complexity)
8. What is the space complexity of the approach that uses a Max-Heap for the Max
Sliding Window problem?
b) O(K) (Since the heap only stores elements within the window, it takes O(K) space)
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?
d) Using Deque (It provides O(N) time complexity and O(K) space complexity, making
it the most optimal solution)
10. What does the term "sliding window" refer to in this problem?
c) A fixed-size subarray moving through the original array