Question
Consider the following Python code snippet for binary search: Â Â def binary_search(arr, target): Â Â Â Â low = 0 Â Â Â Â high = len(arr) - 1 Â Â Â Â while low
Solution
Initial: low = 0, high = 5 Â Â First iteration: mid = (0 + 5) // 2 = 2 Â Â arr[2] is 30, which matches the target. The function would return 2.
More Algorithms Questions
- Which algorithm is best suited for finding a Hamiltonian cycle in an undirected graph?   Â
- Which data structure is most suitable for implementing recursion?
- Which of the following CPU scheduling algorithms is optimal for minimizing average waiting time but requires knowledge of future process execution times?Â
- Which of the following is considered the strongest type of encryption method in modern cyber security practices?   Â
- In Data Structures, which of the following algorithms uses the Divide and Conquer strategy?
- In a Min-Heap, the root node is:
- Which of the following is NOT a greedy algorithm?
- In which case is QuickSort’s performance worst?
- Which sorting algorithm uses the 'Divide and Conquer' strategy and what is its recurrence relation?
- Which algorithm uses a priority queue to repeatedly pick the next closest vertex?