如何使用回答是和否的预言机对 N 个元素的数组(其中每个整数属于集合 {1,2,3,,,k})进行排序?

发布于 2025-01-14 20:25:34 字数 119 浏览 2 评论 0原文

数组有 n 个元素,每个元素都是集合 {1,2,3,,,,k} 中的整数。有一个预言机可以以“是”或“否”来回答有关数组的任何问题。您只能访问预言机,而不能访问数组。证明数组最多可以通过 O(klog(n)) 查询进行排序。

An array has n elements and each element is an integer from the set {1,2,3,,,,k}. There is an oracle that answers anything about the array in yes or no. You only have access to the oracle and not the array. Show that the array can sorted by at most O(klog(n)) queries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2025-01-21 20:25:34

由于您知道数组中所有可能的值,因此只需找到每个可能值的频率即可。然后输出正确的 1 的数量、正确的 2 的数量等。

您可以在 Theta(k log n) 查询中实现此目的,所有形式:

  • “是元素 的频率x 大于 c?”

这相当于对每个 k 频率进行二分搜索。由于每个元素的频率都是 [0, n] 中的整数,因此您最多可以使用 log_2(n+1)+1 个查询来执行二分搜索。

Since you know all of the possible values in the array, it suffices to find the frequency of each possible value. Then output the correct number of 1's, the correct number of 2's, etc.

You can achieve this in Theta(k log n) queries, all of the form:

  • "Is the frequency of element x greater than c?"

This amounts to doing a binary search for each of the k frequencies. Since the frequency of each element is an integer in [0, n], you can do this binary search with at most log_2(n+1)+1 queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文