概率疑点

发布于 2024-10-16 00:24:42 字数 252 浏览 3 评论 0原文

我正在解决一个问题—— 有一组最初无序的数字。目标是对其进行排序。排序应该通过打乱数字直到它们落入正确的位置来完成(是的,Bogosort'ish :))打乱有一个优化,如果打乱后,任何靠近列表开头或结尾的元素都会落入其中它们的正确位置,这些元素将被固定,其余元素将使用上述相同的逻辑进行洗牌。问题是计算对最初无序的一组数字(例如 6)进行排序所需的平均 f 次洗牌次数。 我知道它是沿着概率线的分布序列,但无法将其完全归零。任何正确方向或方法的建议/建议将不胜感激。

谢谢

Im working on a problem that goes as --
There is a an initially unordered set of numbers. and the goal is to sort it. the sorting should be done by shuffling the numbers until they fall into their correct places(Yeah, Bogosort'ish :)) The shuffling has one optimization that if after a shuffling, any elements towards the beginning or towards the end of the list fall in their correct places, these elements will be fixed and the remaining elements will be shuffled using the above same logic. The problem is to calculate the average number f shuffles required to sort an initially unordered set of numbers, say 6.
I know its a distribution sequence along the line of probability but am not able to completely zero in on it. Any suggestions/advise in the correct direction or approach would be greatly appreciated.

Thanks

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

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

发布评论

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

评论(1

屌丝范 2024-10-23 00:24:42

这可以递归计算。

  • 长度为 0 的列表平均需要 0 次洗牌。 f(0) = 0。
  • 长度为 1 的列表平均需要 0 次洗牌。 f(1) = 0。
  • 混洗后长度为 2 的列表有几种可能性:
    • 它已经排序(50% 的机会):0 次洗牌。
    • 尚未排序(50% 的可能性):
      • 随机排序:1 次随机播放。
      • 洗牌没有帮助,我们需要再试一次:1 + f(2) 洗牌。

这可以写成:

f(2) = ((1/2) * 0) + ((1/2) * (1/2) * 1) + ((1/2) * (1/2) * (1 + f(2)).
f(2) = 2/3

您可以通过将输入减少到已经解决的较小输入来继续以这种方式获得更大的输入。

This can be calculated recursively.

  • A list of length 0 requires on average 0 shuffles. f(0) = 0.
  • A list of length 1 requires on average 0 shuffles. f(1) = 0.
  • A list of length 2 after shuffling has a few possibilities:
    • It is already sorted (50% chance): 0 shuffles.
    • It is not already sorted (50% chance):
      • Shuffling sorts it: 1 shuffle.
      • Shuffling does not help, we need to try again: 1 + f(2) shuffles.

This cna be written as:

f(2) = ((1/2) * 0) + ((1/2) * (1/2) * 1) + ((1/2) * (1/2) * (1 + f(2)).
f(2) = 2/3

You can continue in this way to larger inputs by reducing them to the smaller inputs that you have already solved.

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