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.
Use a hash map to store the frequency of each element.
All of the above methods are equally efficient.
Sort the array and use binary search.
Accessing an element outside the valid index range of an array leads to what kind of error?
TypeError
ValueError
IndexError or OutOfBounds exception
SyntaxError
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(log n) - Logarithmic Time
O(n) - Linear Time
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Bubble Sort
Merge Sort
Selection Sort
Quick Sort
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Binary Search
Both are equally efficient in this case.
It depends on the size of the array.
Linear Search
What is a key difference between a 1D array and a 2D array?
1D arrays store numbers while 2D arrays store characters.
1D arrays are static in size, 2D arrays can change size dynamically.
1D arrays represent linear sequences, 2D arrays represent tabular data.
1D arrays can only be accessed sequentially, 2D arrays allow random access.
What is the time complexity of finding the maximum element in a sorted array?
O(n)
O(n log n)
O(log n)
O(1)
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m)
O(m * n)
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(m + n)
O(log m + log n)
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]