How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
Deletion in a sorted array always disrupts the order.
By directly removing the element and leaving the space empty.
By swapping the element with the last element and then removing it.
By shifting all the elements after the deleted element one position back.
Which of the following sorting algorithms has the best average-case time complexity?
Insertion Sort
Bubble Sort
Selection Sort
Merge Sort
What is the purpose of having a base address associated with an array in memory?
To indicate the data type of elements stored in the array.
To store the value of the first element in the array.
To store the length of the array.
To identify the starting memory location where the array is stored.
Which operation is typically NOT efficient on a standard array?
Retrieving the value at a given index.
Updating an element at a given index.
Finding the length of the array.
Inserting an element at the beginning.
What is the time complexity of finding the length of an array in most programming languages?
O(n^2) - Quadratic Time
O(log n) - Logarithmic Time
O(1) - Constant Time
O(n) - Linear Time
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
numbers = array(1, 2, 3, 4);
int numbers[] = {1, 2, 3, 4};
array numbers = [1, 2, 3, 4];
All of the above.
What is the time complexity of finding the maximum element in a sorted array?
O(n)
O(n log n)
O(1)
O(log 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] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
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};
int grid[3][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
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?
Iterate through columns, swapping elements at 'image[r1][j]' and 'image[r2][j]' for each column 'j'.
Create a new 2D array with the swapped rows.
Swapping rows is not possible in a 2D array.
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
Given an array of integers, how can you efficiently count the occurrences of a specific element?
All of the above methods are equally efficient.
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.