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.
Refer to the given 3-address code sequence. This code sequence is split into basic blocks. The number of basic blocks is __________. (Answer in integer)
1001: i = 1
1002: j = 1
1003: t1 = 10i
1004: t2 = t1+j
1005: t3 = 8t2
1006: t4 = t3-88
1007: a[t4] = 0.0
1008: j = j+1
1009: if j <= 10 goto 1003
1010: i = i+1
1011: if i <= 10 goto 1002
1012: i = 1
1013: t5 = i-1
1014: t6 = 88t5
1015: a[t6] = 1.0
1016: i = i+1
1017: if i <= 10 goto 1013
A computer has a memory hierarchy consisting of two-level cache (L1 and L2) and a main memory. If the processor needs to access data from memory, it first looks into L1 cache. If the data is not found in L1 cache, it goes to L2 cache. If it fails to get the data from L2 cache, it goes to main memory, where the data is definitely available. Hit rates and access times of various memory units are shown in the figure. The average memory access time in nanoseconds (ns) is __________. (rounded off to two decimal places)
A disk of size 512M bytes is divided into blocks of 64K bytes. A file is stored in the disk using linked allocation. In linked allocation, each data block reserves 4 bytes to store the pointer to the next data block. The link part of the last data block contains a NULL pointer (also of 4 bytes). Suppose a file of 1M bytes needs to be stored in the disk. Assume, 1K = \(2^{10}\) and 1M = \(2^{20}\). The amount of space in bytes that will be wasted due to internal fragmentation is ___________. (Answer in integer)
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?
Three villages P, Q, and R are located in such a way that the distance PQ = 13 km, QR = 14 km, and RP = 15 km, as shown in the figure. A straight road joins Q and R. It is proposed to connect P to this road QR by constructing another road. What is the minimum possible length (in km) of this connecting road?
Note: The figure shown is representative.
For the clock shown in the figure, if
O = O Q S Z P R T, and
X = X Z P W Y O Q,
then which one among the given options is most appropriate for P?