0% found this document useful (0 votes)
44 views

CAT1 MCQs

The document contains a series of multiple-choice questions and answers related to various data structures and algorithms, including linked lists, sorting algorithms, stacks, and specific problems like the Celebrity Problem and Tower of Hanoi. Each section provides correct answers to questions about properties, complexities, and operations associated with these concepts. The information is structured in a quiz format, aimed at testing knowledge in computer science topics.

Uploaded by

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

CAT1 MCQs

The document contains a series of multiple-choice questions and answers related to various data structures and algorithms, including linked lists, sorting algorithms, stacks, and specific problems like the Celebrity Problem and Tower of Hanoi. Each section provides correct answers to questions about properties, complexities, and operations associated with these concepts. The information is structured in a quiz format, aimed at testing knowledge in computer science topics.

Uploaded by

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

Ethnus mcq ans

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)

Let me know if you need explanations!


Sort bitonic in DLL
Here are the correct answers:
1. Which of the following data structures is suitable for implementing a bitonic
doubly linked list (DLL)?
B) LinkedList (Since a doubly linked list allows bidirectional traversal, it is well-suited
for bitonic sequences.)
2. What is a bitonic sequence?
B) A sequence of numbers that alternates between increasing and decreasing order
3. Which algorithm is commonly used to sort a bitonic sequence?
C) Bitonic Sort (A specialized sorting algorithm designed for bitonic sequences)
4. In the context of sorting a bitonic DLL, what does "bitonic merging" refer to?
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?
D) Deque (A double-ended queue helps efficiently merge elements from both ends)
6. Which of the following is NOT a step involved in sorting a bitonic DLL?
D) Reversing the sublist before the bitonic point (Reversing is unnecessary; merging
and sorting are key steps.)
7. How many sorting passes are required to completely sort a bitonic DLL?
D) It depends on the size of the list (Bitonic sort is performed in log(n) passes.)
8. Which sorting algorithm is commonly used to sort the two sublists in a bitonic DLL?
C) Merge Sort (Merge Sort efficiently sorts sublists in a bitonic sequence.)
9. What is the space complexity of sorting a bitonic DLL with n elements?
B) O(log n) (Bitonic Sort has O(log n) space complexity.)
10. In a bitonic DLL, where does the bitonic point occur?
C) It can occur at any position (The peak or bitonic point can be at any position in the
list.)

Let me know if you need explanations!


SEGREGATE EVEN AND ODD NODES IN A LINKED LIST
Here are the correct answers:
1. To segregate even and odd nodes, you need to iterate through the linked list once.
a) True (A single pass is sufficient to rearrange the nodes while maintaining relative
order.)
2. Which of the following operations is NOT typically required when segregating even
and odd nodes in a linked list?
d) Sorting (Sorting is unnecessary; we only need to rearrange nodes.)
3. How can you identify whether a number is even or odd?
a) Check if it is divisible by 2 (Even numbers are divisible by 2, odd numbers are not.)
4. In an in-place solution for segregating even and odd nodes, what is the primary
goal?
b) To minimize space complexity (The in-place approach avoids extra memory
allocation.)
5. Which of the following is NOT an in-place method for segregating even and odd
nodes?
a) Creating two separate linked lists (This requires extra space, so it's not an in-place
solution.)
6. In the context of segregating even and odd nodes, what is the significance of the
"previous" pointer?
a) It points to the previous node. (Useful for maintaining connections when
rearranging nodes.)
7. In an in-place solution for segregating even and odd nodes, what is the final step
after rearranging the nodes?
d) Merging the even and odd parts (Once segregated, the even and odd lists need to
be connected.)
8. Which pointer do you need to update when rearranging nodes in an in-place
solution for segregating even and odd nodes?
c) Both next and previous pointers (For a doubly linked list, both need to be
updated.)
9. What data structure is commonly used to represent a singly linked list?
d) Linked List (A linked list is specifically designed for dynamic memory allocation and
efficient insertions/deletions.)
10. In the in-place approach, what is the role of the "evenTail" pointer?
a) To track the last even node in the list (This helps maintain the correct order when
merging even and odd lists.)

Let me know if you need explanations!


Merge sort for DLL

Here are the correct answers:


1. What is Merge Sort?
c) A divide-and-conquer sorting algorithm (Merge Sort recursively divides and
merges sorted sublists.)
2. Why is Merge Sort preferred for sorting DLLs?
d) It efficiently utilizes the DLL's bidirectional traversal capability (The ability to
traverse in both directions makes merging easier.)
3. What is the time complexity of Merge Sort for DLLs with 'n' elements?
b) O(n * log(n)) (Merge Sort has a logarithmic depth of recursion and linear merging
cost.)
4. In Merge Sort for DLLs, what is the base case?
a) When the DLL has a single element (A single element is already sorted, so
recursion stops.)
5. How is a DLL divided during the Merge Sort process?
c) By finding the middle element (Splitting the list into two halves requires finding
the middle element.)
6. What is the purpose of the "Merge" function in Merge Sort for DLLs?
c) To combine and sort two sorted sublists (The merge step ensures the combined
list remains sorted.)
7. In Merge Sort for DLLs, which data structure is used to perform the merging of
sublists efficiently?
d) Recursion (Merge Sort relies on recursion to divide and merge sublists.)
8. In Merge Sort for DLLs, how do you merge two sorted DLLs?
c) By comparing and rearranging nodes from both DLLs (Nodes are merged by
comparing values and adjusting pointers.)
9. In Merge Sort, how is the DLL divided during the recursive process?
b) Into two equal parts (Merge Sort always divides the list into two halves.)
10. Which of the following is true about the stability of Merge Sort for DLLs?
a) It is always stable (Merge Sort maintains the relative order of equal elements,
making it stable.)

Let me know if you need explanations!


Minimum Stack

Here are the correct answers:


1. What is a stack data structure?
B) A linear data structure with a LIFO (Last-In-First-Out) order.
2. Which operation involves inserting an item into a stack?
A) Push
3. Which operation involves deleting an item from the stack?
B) Pop
4. Which operation involves displaying the contents of the stack without removing it?
C) Peek
5. Which operation allows you to retrieve the minimum element from a stack
efficiently?
A) getMin()
6. Which of the following is NOT a valid approach to implement the "get minimum"
operation for a stack?
D) Using a priority queue. (Priority queues have different structures and are not
typically used for this purpose.)
7. What is the advantage of using a "get minimum" stack over scanning the entire
stack to find the minimum when needed?
B) "Get minimum" stack has a faster time complexity. (Finding the minimum in O(1)
instead of O(N) makes it more efficient.)
8. In a "get minimum" stack, what happens when you pop the minimum element
from the stack?
C) The minimum element is pushed onto the auxiliary stack. (An auxiliary stack
helps track the previous minimum.)
9. What is the time complexity of the "get minimum" operation for a stack
implemented with an additional stack to track minimums?
A) O(1)
10. What is the space complexity of a stack without any additional data structures?
B) O(N) (A stack grows linearly with the number of elements.)

Let me know if you need explanations!


Tower of Hanoi

Here are the correct answers:


1. In the Tower of Hanoi problem, what is the objective?
A) To move all disks from one rod to another rod.
2. How many rods are used in the classic Tower of Hanoi problem?
C) 3
3. In the iterative solution to the Tower of Hanoi, how is the problem divided into
subproblems?
C) Divide the disks into smaller and smaller subproblems.
4. What is the minimum number of moves required to solve the Tower of Hanoi
problem with 4 disks?
C) 15 (Formula: 2n−12^n - 1, where n=4n = 4 → 24−1=152^4 - 1 = 15)
5. Which data structure is commonly used to implement the iterative solution to the
Tower of Hanoi problem?
A) Stack
6. In the iterative Tower of Hanoi solution, how are the disks moved between the
rods?
B) Using a loop
7. What is the time complexity of the iterative solution to the Tower of Hanoi
problem with 'n' disks?
B) O(2^n)
8. In the iterative Tower of Hanoi solution, what is the purpose of using a stack data
structure?
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?
C) By using a loop and a stack data structure.
10. What is the space complexity of the iterative Tower of Hanoi solution?
B) O(n)

Let me know if you need explanations!


THE CELEBRITY PROBLEM

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)

Let me know if you need explanations!


priority queue using doubly linked list

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)

Let me know if you need explanations!


Sort without extra Space
Here are the correct answers for your sorting algorithm questions:
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?
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?
c) Quick Sort
3. Which sorting algorithm works by repeatedly dividing the input array into two
subarrays, sorting them, and then merging them?
c) Merge Sort
4. In the context of "sorting without extra space," which data structure is commonly
used for in-place sorting algorithms?
d) Priority Queue (Heap Sort uses a priority queue, but arrays are more commonly
used for in-place sorting)
5. In-place sorting means that:
a) Extra space is not used (Sorting is done within the original array without
additional storage)
6. Which sorting algorithm is often used to implement priority queues due to its heap
data structure?
d) Heap Sort
7. Which sorting algorithm's performance is significantly affected by the choice of the
pivot element?
d) Quick Sort
8. Which sorting algorithm does not perform well with duplicate values in the array
and can be unstable?
a) Quick Sort (It can be unstable unless implemented carefully with a specific
partitioning scheme)
9. Which sorting algorithm is not a comparison-based sorting algorithm and is
suitable for integers or fixed-length strings?
c) Radix Sort
10. What does it mean to "sort without extra space" in the context of sorting
algorithms?
b) Rearranging elements in the original array to achieve a sorted order (Sorting in-
place without using additional memory)

Let me know if you need any explanations!


Max Sliding Window

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

Let me know if you need any explanations!


stack permutation
Here are the correct answers for your Stack Permutation questions:
1. What is a stack permutation?
d) A sequence of elements that can be obtained by rearranging a stack's elements
2. In a valid stack permutation, which operation can be performed at any time
without violating the permutation's order?
a) Push (Push can happen at any time, while Pop must respect the stack order)
3. How many valid permutations can be generated from a stack with three distinct
elements?
5 (There are exactly 5 valid permutations for 3 distinct elements in a stack)
4. In a valid stack permutation, when can you perform a pop operation?
b) Only when the top element of the stack matches the next element in the
permutation
5. If you have a stack with n distinct elements, how many valid stack permutations
can be generated?
b) n! (For n distinct elements, all n! permutations are possible)
6. Which operation is used to reverse a stack's elements, creating a valid stack
permutation?
a) Push (A valid permutation depends on pushing and popping in an orderly fashion,
not reversing directly)
7. What is the minimum number of elements needed in a stack to generate at least
one valid permutation?
1) 3 (A stack with 2 or more elements is needed to start generating valid
permutations, but for 3 elements, there is the possibility of multiple valid
permutations)
8. In a valid stack permutation, what is the position of the maximum element from
the original stack in the permutation?
c) Last (The largest element must always be popped last in a valid stack permutation
because it would be the last item to be placed on the stack and the last to be
removed)
9. Which of the following is a common application of stack permutations?
a) Sorting algorithms (Stack permutations are often used as a way to simulate
sorting operations)
10. In a stack permutation, when is the stack completely empty?
c) After popping all elements (The stack is empty once all elements have been
popped off)

Let me know if you need further clarifications!

You might also like