Array Data Structure Quiz (original) (raw)

Given a sorted 1D array, which technique finds whether a pair with sum = X exists in O(n) time ?

What is the minimum number of comparisons required to find both the minimum and maximum element in a 1D array of size n?

Which in-place procedure deletes the element at index k from a 1D array of length n (shifting remaining)?

In a circular buffer of size n, to advance a write index by one modulo n, compute:

Which in-place sequence of operations rotates a 1D array right by k positions?

Reversing a 1D array of length n in place requires how many element swaps?

Which in-place procedure deletes the element at index k from a 1D array of length n (shifting remaining)?

Consider the below program. What is the expected output?

C++ `

void fun(int arr[], int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } }

`

Refer the below diagram and identify the problem.

Fill in the blanks for completing the program to rotate an array by d elements.

C++ `

/Function to left rotate arr[] of size n by d/ void Rotate(int arr[], int d, int n) { int p = 1; while (_______) { int last = arr[0]; for (int i = 0; ______ i++) { arr[i] = arr[i + 1]; } __________ p++; } }

`

There are 26 questions to complete.

Take a part in the ongoing discussion