题目
单项选择题
zyBooks_17_algs_1 You are given an alphabetically sorted list of strings read from input. The goal is to complete the find() function, which passes the following test cases ( included in the screen shot) range_size: The total number of elements between low_index and high_index (both inclusive). middle_index: The index calculated by floor division (//) of the sum of low_index and high_index. The element at middle_index in the list. Complete the following code by choosing the correct option for the missing lines of code. Which of the following is the correct code to complete the find() function?
选项
A.range_size = len(all_names) - 1middle_index = high_index // 2
B.range_size = (high_index - low_index) + 1middle_index = (low_index + high_index) // 2
C.range_size = len(all_names)middle_index = (low_index + high_index) / 2
D.range_size = high_index - low_indexmiddle_index = (low_index + high_index) % 2
查看解析
标准答案
Please login to view
思路分析
We start by restating the problem in our own terms: we have a sorted list of strings and need to complete the find() function. The inputs relevant to the missing lines are low_index and high_index, representing a inclusive range within the list. We must compute two quantities: range_size, the total number of elements from low_index to high_index inclusive, and middle_index, the index of the middle element within that range, using floor division.
Option A: "range_size = le......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!