In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
It depends on the data type of the array.
0
n
n - 1
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]
What is the primary advantage of using binary search over linear search?
Binary search works on unsorted arrays.
Binary search is generally faster for large arrays.
Binary search is simpler to implement.
Binary search uses less memory.
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?
Binary Search
Quick Sort
Bubble Sort
Depth First Search (DFS)
Imagine a 2D array representing a grayscale image. Each element holds a pixel intensity value. How would you swap two rows 'r1' and 'r2' in this array?
Swapping rows is not possible in a 2D array.
Iterate through columns, swapping elements at 'image[r1][j]' and 'image[r2][j]' for each column 'j'.
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
Create a new 2D array with the swapped rows.
Given an array of integers, how can you efficiently count the occurrences of a specific element?
Iterate through the array and increment a counter for each occurrence.
Sort the array and use binary search.
Use a hash map to store the frequency of each element.
All of the above methods are equally efficient.
What is the time complexity of finding the maximum element in a sorted array?
O(n)
O(log n)
O(1)
O(n log n)
What is the main disadvantage of using bubble sort for large datasets?
It requires additional memory space.
It cannot handle duplicate values.
It has a high time complexity, making it inefficient.
It is difficult to implement.
What is the purpose of having a base address associated with an array in memory?
To store the value of the first element in the array.
To indicate the data type of elements stored in the array.
To identify the starting memory location where the array is stored.
To store the length of the array.
You are given a 2D array representing a matrix. What does transposing this matrix mean?
Reversing all elements in the matrix.
Finding the sum of all elements in the matrix.
Sorting the matrix in ascending order.
Swapping rows and columns of the matrix.