Question
Complete the while loop condition for an iterative
binary search implementation. def binary_search(arr, target): low = 0 high = len(arr) - 1 while __________: # Line to complete mid = low + (high - low) // 2 if arr[mid] == target: return mid elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return -1Solution
• Code Analysis: o low and high define the current search space. o The loop needs to continue as long as there's a potential range to search, including the case where low and high point to the same element. • Explanation of Correct Answer (B): low <= high o This condition ensures that the loop continues as long as the low index is less than or equal to the high index. This covers cases where low and high are equal (meaning there's one element left to check) and cases where low is less than high (meaning there's a range of elements). If low becomes greater than high, it means the search space has become empty, and the target is not found.
अनुस्वार किसे कहा जाता हैं।
वे (1)/ किसी (2)/ स्वास्थ्य लाभ (3) / रहे हैं (4)/ कर(5) / पहाड़ पर (6)
क्�...
पुस्तकालय का सन्धि-विच्छेद है
दिए गए शब्दांशों के लिए एक शब्द के चार विकल्प दिए हैं उनमे�...
‘जामुन' का तत्सम रूप है।
आज आकाश में ........ छाये हैं , रिक्त स्थान की पूर्ति उचित शब्द स�...
वाक्य संरचना का सही क्रम बताइये ?
1. कुल मिलाकर आत्मरक्षा...
निम्नलिखित शब्दों में से तत्सम शब्द है -
सूची – I को सूची & II से सुमेलित कीजिए और सूचिचों के नीचे दिए ग�...
शुद्ध वर्तनी पहचानिए