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

A mid1 = low + (high - low) / 3, mid2 = high - (high - low) / 3
B mid1 = (low + high) / 3, mid2 = 2 * (low + high) / 3
C mid1 = low + (high - low) // 2, mid2 = high - (high - low) // 2
D mid1 = low + (high - low) // 4, mid2 = high - (high - low) // 4
E mid1 = (low + high) // 3, mid2 = (low + high) * 2 // 3
Practice Next

Hey! Ask a query

🎓
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)