In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n
n - 1
0
It depends on the data type of the array.
You need to search for an element in an array where elements are randomly placed. Which search algorithm is your only option?
Linear Search
Binary Search
Both can be used effectively.
None of the above.
How is an element at row 'i' and column 'j' typically accessed in a 2D array named 'matrix'?
matrix[i, j]
matrix(i)[j]
matrix.get(i, j)
matrix[i][j]
How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
By directly removing the element and leaving the space empty.
By shifting all the elements after the deleted element one position back.
Deletion in a sorted array always disrupts the order.
By swapping the element with the last element and then removing it.
Which of the following sorting algorithms has the best average-case time complexity?
Merge Sort
Bubble Sort
Selection Sort
Insertion Sort
Accessing an element outside the valid index range of an array leads to what kind of error?
IndexError or OutOfBounds exception
TypeError
SyntaxError
ValueError
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
array numbers = [1, 2, 3, 4];
All of the above.
int numbers[] = {1, 2, 3, 4};
numbers = array(1, 2, 3, 4);
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 accessing an element in a 2D array with 'm' rows and 'n' columns?
O(m * n)
O(1)
O(log m + log n)
O(m + n)
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
It depends on the size of the array.
Both are equally efficient in this case.