1Which of the following defines the worst-case time complexity of an algorithm?
A.Big O Notation
B.Omega Notation
C.Theta Notation
D.Beta Notation
Correct Answer: Big O Notation
Explanation:Big O notation (O) describes the upper bound of the time complexity, representing the worst-case scenario.
Incorrect! Try again.
2What is the time complexity of accessing an element at a specific index in an array?
A.O(n)
B.O(log n)
C.O(1)
D.O(n^2)
Correct Answer: O(1)
Explanation:Arrays store elements in contiguous memory locations, allowing constant time access O(1) using the index.
Incorrect! Try again.
3Which notation represents the lower bound of an algorithm's running time?
A.Big O Notation
B.Omega Notation
C.Theta Notation
D.Little o Notation
Correct Answer: Omega Notation
Explanation:Omega notation (Ω) represents the lower bound, indicating the best-case running time of an algorithm.
Incorrect! Try again.
4In the context of algorithm analysis, what does the Space-Time trade-off imply?
A.Improving time complexity always improves space complexity
B.Reducing time complexity often increases space complexity
C.Time and space complexity are unrelated
D.Algorithms always require equal time and space
Correct Answer: Reducing time complexity often increases space complexity
Explanation:The Space-Time trade-off suggests that an algorithm can often be made faster by using more memory (space), or can use less memory by running slower.
Incorrect! Try again.
5What is the formula to calculate the memory address of the k-th element in a linear array with base address B and word size W (assuming lower bound is LB)?
A.Address(k) = B + W * (k - LB)
B.Address(k) = B + W * (k + LB)
C.Address(k) = B + (k - LB) / W
D.Address(k) = W + B * (k - LB)
Correct Answer: Address(k) = B + W * (k - LB)
Explanation:The standard formula for 1D array address calculation is Base Address + Word Size * (Index - Lower Bound).
Incorrect! Try again.
6Which of the following is a linear data structure?
A.Tree
B.Graph
C.Array
D.Heap
Correct Answer: Array
Explanation:An array is a linear data structure because elements are arranged sequentially in memory.
Incorrect! Try again.
7What is the worst-case time complexity of inserting an element at the beginning of an array of size n?
A.O(1)
B.O(n)
C.O(log n)
D.O(n log n)
Correct Answer: O(n)
Explanation:Inserting at the beginning requires shifting all existing n elements one position to the right, resulting in O(n) complexity.
Incorrect! Try again.
8Which sorting algorithm works by repeatedly swapping adjacent elements if they are in the wrong order?
A.Selection Sort
B.Insertion Sort
C.Bubble Sort
D.Merge Sort
Correct Answer: Bubble Sort
Explanation:Bubble Sort works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order.
Incorrect! Try again.
9What is the worst-case time complexity of Bubble Sort?
A.O(n)
B.O(n log n)
C.O(n^2)
D.O(1)
Correct Answer: O(n^2)
Explanation:In the worst case (reverse sorted), Bubble Sort requires nested loops iterating n times, leading to O(n^2) complexity.
Incorrect! Try again.
10Which searching algorithm requires the array to be sorted beforehand?
A.Linear Search
B.Binary Search
C.Hashing
D.Breadth-First Search
Correct Answer: Binary Search
Explanation:Binary Search operates by dividing the search interval in half, which mathematically requires the data to be sorted.
Incorrect! Try again.
11What is the worst-case time complexity of Linear Search?
A.O(1)
B.O(log n)
C.O(n)
D.O(n^2)
Correct Answer: O(n)
Explanation:In the worst case, the element being searched for is at the last position or not present at all, requiring n comparisons.
Incorrect! Try again.
12What is the best-case time complexity of an optimized Bubble Sort (using a flag)?
A.O(1)
B.O(n)
C.O(n^2)
D.O(log n)
Correct Answer: O(n)
Explanation:If the array is already sorted, an optimized Bubble Sort with a flag checks one pass (n comparisons) and stops, taking O(n) time.
Incorrect! Try again.
13In Selection Sort, how many swaps are performed in the worst case for an array of size n?
A.O(n)
B.O(n^2)
C.O(log n)
D.O(1)
Correct Answer: O(n)
Explanation:Selection sort performs exactly one swap per pass (placing the minimum found element). For n elements, it performs O(n) swaps.
Incorrect! Try again.
14Which notation represents the tight bound (both upper and lower) of an algorithm?
A.Big O
B.Omega
C.Theta
D.Little o
Correct Answer: Theta
Explanation:Theta notation (Θ) bounds a function from above and below, providing a tight bound on the asymptotic behavior.
Incorrect! Try again.
15What is the time complexity of Binary Search?
A.O(n)
B.O(n^2)
C.O(log n)
D.O(1)
Correct Answer: O(log n)
Explanation:Binary search divides the search space by half in every step, resulting in logarithmic time complexity O(log n).
Incorrect! Try again.
16In Insertion Sort, what is the time complexity when the input array is already sorted?
A.O(n^2)
B.O(n)
C.O(1)
D.O(n log n)
Correct Answer: O(n)
Explanation:Insertion sort is adaptive; if the array is sorted, the inner while loop condition fails immediately, resulting in O(n) comparisons.
Incorrect! Try again.
17Which operation is NOT efficiently supported by a standard array?
A.Random Access
B.Traversal
C.Insertion in the middle
D.Updating an element
Correct Answer: Insertion in the middle
Explanation:Insertion in the middle requires shifting elements to create space, making it an O(n) operation, which is inefficient compared to O(1) access.
Incorrect! Try again.
18What is the space complexity of Bubble Sort?
A.O(n)
B.O(log n)
C.O(1)
D.O(n^2)
Correct Answer: O(1)
Explanation:Bubble Sort is an in-place sorting algorithm requiring only a constant amount of extra auxiliary space.
Incorrect! Try again.
19How is the middle element calculated in Binary Search to avoid integer overflow?
A.mid = (low + high) / 2
B.mid = low + (high - low) / 2
C.mid = low + high
D.mid = (high - low) / 2
Correct Answer: mid = low + (high - low) / 2
Explanation:The formula 'low + (high - low) / 2' is mathematically equivalent to average but prevents overflow if low + high exceeds the maximum integer limit.
Incorrect! Try again.
20Which sorting algorithm is considered 'stable' among the following?
A.Selection Sort
B.Quick Sort
C.Heap Sort
D.Bubble Sort
Correct Answer: Bubble Sort
Explanation:Bubble Sort is stable because it does not swap elements of equal value, preserving their original relative order.
Incorrect! Try again.
21What is the worst-case complexity of Selection Sort?
A.O(n)
B.O(n log n)
C.O(n^2)
D.O(n!)
Correct Answer: O(n^2)
Explanation:Selection Sort involves two nested loops regardless of the data order, resulting in O(n^2) comparisons in all cases.
Incorrect! Try again.
22Which of the following describes an algorithm that runs in constant time?
A.O(n)
B.O(1)
C.O(log n)
D.O(n^2)
Correct Answer: O(1)
Explanation:O(1) denotes constant time complexity, meaning the execution time does not depend on the input size.
Incorrect! Try again.
23Which sorting technique acts like sorting a hand of playing cards?
A.Bubble Sort
B.Merge Sort
C.Insertion Sort
D.Selection Sort
Correct Answer: Insertion Sort
Explanation:Insertion sort works by taking one element at a time and inserting it into its correct position among the already sorted elements, similar to arranging cards.
Incorrect! Try again.
24What is the complexity of merging two sorted arrays of size M and N?
A.O(M * N)
B.O(M + N)
C.O(log(M + N))
D.O(1)
Correct Answer: O(M + N)
Explanation:Merging two sorted arrays involves traversing both arrays once, resulting in a linear time complexity relative to the sum of their sizes.
Incorrect! Try again.
25Traversing an array means:
A.Sorting the array
B.Accessing each element exactly once
C.Searching for an element
D.Deleting an element
Correct Answer: Accessing each element exactly once
Explanation:Traversal involves visiting every element in the data structure exactly once to perform a specific operation (like printing).
Incorrect! Try again.
26In row-major order, elements of a 2D array are stored:
A.Row by row
B.Column by column
C.Diagonally
D.Randomly
Correct Answer: Row by row
Explanation:Row-major order stores consecutive elements of a row next to each other in memory.
Incorrect! Try again.
27The minimum number of comparisons required to find the minimum and maximum element in an array of size n is:
A.2n
B.n
C.1.5n
D.n^2
Correct Answer: 1.5n
Explanation:By comparing elements in pairs, one can find min and max with approximately 3n/2 (1.5n) comparisons, which is more efficient than 2n - 2.
Incorrect! Try again.
28Linear search is highly inefficient for:
A.Small arrays
B.Unsorted arrays
C.Large arrays
D.Linked Lists
Correct Answer: Large arrays
Explanation:For very large arrays, the O(n) complexity of linear search makes it significantly slower than O(log n) binary search.
Incorrect! Try again.
29What does 'n' usually represent in complexity analysis?
A.Number of iterations
B.Input size
C.Number of variables
D.CPU speed
Correct Answer: Input size
Explanation:In asymptotic analysis, 'n' typically represents the size of the input data (e.g., number of elements in an array).
Incorrect! Try again.
30If an algorithm has a time complexity of O(n^2), doubling the input size increases the time by:
A.2 times
B.4 times
C.8 times
D.It remains same
Correct Answer: 4 times
Explanation:Since (2n)^2 = 4n^2, doubling the input size quadruples the running time for a quadratic algorithm.
Incorrect! Try again.
31Which algorithm is generally preferred for small datasets due to low overhead?
A.Merge Sort
B.Insertion Sort
C.Heap Sort
D.Quick Sort
Correct Answer: Insertion Sort
Explanation:Insertion Sort has a small constant factor and low overhead, making it faster than O(n log n) algorithms for very small n.
Incorrect! Try again.
32The operation of processing each element in the list is known as:
A.Sorting
B.Merging
C.Inserting
D.Traversal
Correct Answer: Traversal
Explanation:Traversal is the specific term for visiting and processing every node or element in a data structure.
Incorrect! Try again.
33What is the output of a Binary Search if the element is not found?
A.The middle index
B.The array size
C.A failure indicator (e.g., -1)
D.The last element
Correct Answer: A failure indicator (e.g., -1)
Explanation:Standard searching algorithms return a specific value like -1 or NULL to indicate that the target key was not present in the dataset.
Incorrect! Try again.
34Selection sort is NOT an adaptive sorting algorithm. What does this mean?
A.It uses extra space
B.Its time complexity depends on the initial order of elements
C.Its time complexity is the same regardless of initial order
D.It cannot handle duplicates
Correct Answer: Its time complexity is the same regardless of initial order
Explanation:Non-adaptive means the algorithm performs the same amount of work (O(n^2) comparisons) even if the array is already sorted.
Incorrect! Try again.
35Which of the following is an application of Binary Search?
A.Finding a path in a maze
B.Debugging code (bisecting)
C.Sorting an array
D.Printing all elements
Correct Answer: Debugging code (bisecting)
Explanation:Binary search logic is used in debugging to isolate the section of code causing an error (bisection method).
Incorrect! Try again.
36What is the maximum number of comparisons in a Binary Search for an array of size 32?
A.32
B.16
C.6
D.5
Correct Answer: 6
Explanation:The max comparisons are floor(log2(32)) + 1 = 5 + 1 = 6 (or simply log2(32) comparisons to reach size 1, plus check).
Incorrect! Try again.
37In an array A[1...N], the index of the first element is:
A.
B.1
C.-1
D.N
Correct Answer: 1
Explanation:The notation A[1...N] explicitly specifies a 1-based indexing system.
Incorrect! Try again.
38Deleting an element from the end of a linear array takes:
A.O(n)
B.O(1)
C.O(log n)
D.O(n^2)
Correct Answer: O(1)
Explanation:Deletion at the end simply involves reducing the size counter of the array, requiring no shifting of elements.
Incorrect! Try again.
39Which case typically determines the Big O complexity of an algorithm?
A.Best Case
B.Average Case
C.Worst Case
D.Null Case
Correct Answer: Worst Case
Explanation:Big O provides the upper bound guarantee, so it is defined by the worst-case scenario.
Incorrect! Try again.
40Which data structure is static in nature?
A.Linked List
B.Array
C.Stack (Dynamic)
D.Queue (Dynamic)
Correct Answer: Array
Explanation:Standard arrays have a fixed size defined at compile-time or allocation-time and cannot grow or shrink dynamically.
Incorrect! Try again.
41In Bubble Sort, after the first pass, which element is guaranteed to be in its correct position?
A.The smallest element
B.The largest element
C.The middle element
D.No element
Correct Answer: The largest element
Explanation:Bubble sort pushes the largest element to the end of the array in the first pass (assuming ascending sort).
Incorrect! Try again.
42How many passes are required to sort an array of size n using Insertion Sort in the worst case?
A.n
B.n-1
C.n+1
D.n/2
Correct Answer: n-1
Explanation:Insertion sort starts from the second element (index 1) and iterates to the end, requiring n-1 passes.
Incorrect! Try again.
43What is the average case time complexity of Linear Search?
A.O(1)
B.O(n/2) which is O(n)
C.O(log n)
D.O(n^2)
Correct Answer: O(n/2) which is O(n)
Explanation:On average, the element might be in the middle, requiring n/2 comparisons. Constants are dropped in Big O, so it is O(n).
Incorrect! Try again.
44Space complexity refers to:
A.The amount of hard disk space used
B.The amount of RAM used during execution
C.The number of lines of code
D.The time taken to compile
Correct Answer: The amount of RAM used during execution
Explanation:Space complexity measures the amount of working storage (memory) an algorithm needs to run.
Incorrect! Try again.
45Which of the following algorithms is In-Place?
A.Merge Sort (standard)
B.Insertion Sort
C.Counting Sort
D.Radix Sort
Correct Answer: Insertion Sort
Explanation:Insertion sort rearranges elements within the array itself without needing significant auxiliary storage.
Incorrect! Try again.
46For a sorted array, which operation is slower in a Linear Search compared to Binary Search?
A.Finding the first element
B.Finding a random element
C.Traversing
D.None
Correct Answer: Finding a random element
Explanation:Finding a specific random element in a sorted array takes O(n) in Linear Search but O(log n) in Binary Search.
Incorrect! Try again.
47If Base address is 1000, W=2, and Index=5 (0-based indexing), what is the address?