Question
Consider the following Python code snippet for binary search: def binary_search(arr, target): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == target: return mid elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return -1 my_list = [10, 20, 30, 40, 50, 60] result = binary_search(my_list, 30) What is the value of mid in the first iteration of the while loop when searching for 30?
More Algorithms Questions
- Which algorithm is used to detect cycles in a directed graph?
- A greedy MST algorithm repeatedly selects the lightest edge that does not create a cycle. Which idea is this?
- The time complexity of searching in a hash table with chaining is:
- In the context of searching, what is the primary advantage of using hashing?
- Which algorithm finds the longest common subsequence (LCS) of two sequences?
- What is the worst-case time complexity of a linear search algorithm on an array of 'N' elements?
- Which of the following is a critical concern for securing critical infrastructure?
- Output of below code public class Prg { public static void main(String args[]){ System.out.print("A" + "B" + 'A'); } }
- Counting Sort is an efficient sorting algorithm when the range of input elements (k) is not significantly larger than the number of elements (n). What is i...
- Which of the following types of testing is primarily focused on verifying the integration of different modules?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)