Which of the following sorting algorithms has the best average-case time complexity?
Merge Sort
Selection Sort
Insertion Sort
Bubble Sort
Accessing an element outside the valid index range of an array leads to what kind of error?
IndexError or OutOfBounds exception
ValueError
TypeError
SyntaxError
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(n)
O(1)
O(m * n)
O(m)
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(log m + log n)
O(m + n)
Which code snippet correctly initializes a 2D array named 'grid' with 3 rows and 4 columns, all filled with zeros?
int grid[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) grid[i][j] = 0;
int grid[3][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
int grid[3][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int grid[3][4] = {0};
What is the time complexity of finding the maximum element in a sorted array?
O(log n)
O(n log n)
Consider a 2D array storing characters to represent a word search grid. You want to check if a given word exists in the grid horizontally or vertically. Which algorithm would be suitable for this task?
Quick Sort
Depth First Search (DFS)
Binary Search
What is the time complexity of finding the length of an array in most programming languages?
O(n^2) - Quadratic Time
O(1) - Constant Time
O(n) - Linear Time
O(log n) - Logarithmic Time
What is the primary advantage of using binary search over linear search?
Binary search uses less memory.
Binary search works on unsorted arrays.
Binary search is simpler to implement.
Binary search is generally faster for large arrays.
What is the main disadvantage of using bubble sort for large datasets?
It cannot handle duplicate values.
It requires additional memory space.
It is difficult to implement.
It has a high time complexity, making it inefficient.