Question
In a Ternary Search algorithm, the array is divided into three parts. Complete the calculation for mid1 and mid2. def ternary_search(arr, target): low = 0 high = len(arr) - 1 while low <= high: mid1 = low + (high - low) // 3 # Line to complete mid1 mid2 = high - (high - low) // 3 # Line to complete mid2 if arr[mid1] == target: return mid1 if arr[mid2] == target: return mid2 if target < arr[mid1]: high = mid1 - 1 elif target > arr[mid2]: low = mid2 + 1 else: low = mid1 + 1 high = mid2 - 1 return -1
More IT Operating System Questions
- Packet filtering is responsibility of which layer of OSI model?
- What is a key characteristic of a star topology in networking?
- In open addressing, if a collision occurs and the hash function h(key) maps to an occupied slot, which probing technique attempts to find the next availabl...
- State True or False Kernel level thread cannot share the code segment.
- What is the output of the following Java code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
- What is the primary function of a MAC address in a network?
- The "state-space tree" is a conceptual tool often associated with backtracking. What does it represent?
- What is the purpose of using a profiler in software development?
- What is the recurrence relation for Merge Sort?
- Which evaluation metric is commonly used in machine translation?
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)