Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 分而治之-查找数组的中值_Algorithm_Proof_Divide And Conquer - Fatal编程技术网

Algorithm 分而治之-查找数组的中值

Algorithm 分而治之-查找数组的中值,algorithm,proof,divide-and-conquer,Algorithm,Proof,Divide And Conquer,假设我们有一个大小为2n的数组,包含所有唯一的元素 假设我们将数组拆分为2个大小为n的数组,如果在Olog n时间内无法解决中值计算为特例的1选择,则我们有一个特殊的常数时间查找来查找该特定数组的第k个最小元素。您可以使用一种算法来及时解决它,例如。假设[…]我们有一个特殊的常数时间查找来查找该特定数组的第k个最小元素,如果1如果您将数组拆分为[1 2 6][3 4 5],则您的算法返回5。所以它不可能是正确的。哦,你是对的,@HugoRune。如果你用这个来选择支点,你会得到前面一个更大的常数

假设我们有一个大小为2n的数组,包含所有唯一的元素


假设我们将数组拆分为2个大小为n的数组,如果在Olog n时间内无法解决中值计算为特例的1选择,则我们有一个特殊的常数时间查找来查找该特定数组的第k个最小元素。您可以使用一种算法来及时解决它,例如。

假设[…]我们有一个特殊的常数时间查找来查找该特定数组的第k个最小元素,如果1如果您将数组拆分为[1 2 6][3 4 5],则您的算法返回5。所以它不可能是正确的。哦,你是对的,@HugoRune。如果你用这个来选择支点,你会得到前面一个更大的常数。这是因为中位数算法保证返回第30和第70百分位之间的值,因此最坏情况下的性能是Tn=On+Tn/5+T0.7n=On。
2n = 6  [1 2 3 4 5 6]
n = 3   [1 2 3] [4 5 6] (not necessarily sorted, but we have the constant time lookup, so sorting is irrelevant)
Step 1) use lookup where k = n to find the kth smallest element for each array
[1 2 3] [4 5 6]
     ^       ^ (if k = 3, we get 3 for the first array, 6 for the second array)
Step 2) compare the 2 values we got and choose the smaller one. 3 is the median where median is defined as the nth lowest element between the 2 arrays.