Which of the following is true about the binary search algorithm when applied to a sorted array?
Binary search only works on sorted arrays. It divides the search space in half each time, making it an efficient O(log n) algorithm. Always ensure that the array is sorted before applying binary search.
It always has a time complexity of O(n)
It works on unsorted arrays
It divides the search space into two equal halves on each iteration
It requires that the array be sorted in descending order
Understanding Binary Search
- Binary search works by dividing the search space in half at each step.
- It requires the array to be sorted in ascending order for proper functioning.
Thus, the correct statement is: "It divides the search space into two equal halves on each iteration.
Consider the following operations on an initially empty stack:
Push 10
Push 20
Pop
Push 30
Pop
Push 40
What is the final content of the stack?
Given a pipeline with 5 stages, the delay for each stage is as follows:
\[ \begin{array}{|c|c|} \hline \textbf{Stage} & \textbf{Delay (ns)} \\ \hline 1 & 250 \\ 2 & 150 \\ 3 & 100 \\ 4 & 200 \\ 5 & 50 \\ \hline \end{array} \]The buffer delay is 10 ns. Find the time for \( n = 1000 \) instructions.
What is the output of the following C code?
void foo(int *p, int x) { *p = x; } void main() { int *z; int a = 20, b = 25; z = a; // Incorrect: Should be z = a; foo(z, b); printf("%d", a); }
Issue: The statement z = a;
is invalid because a
is an integer, and z
is a pointer.
Which of the following is the greatest? \[ 0.6, \ 0.666, \ \frac{5}{6}, \ \frac{2}{3} \]
Consider the following C code:
int main() { sum = 0; for (n = 1; n < 3; n++) { n++; sum += g(f(n)); } printf("%d", sum); } int g(n) { return 10 + n; } int f(n) { return g(2 * n); }
What is the output?