简体   繁体   English

简单语言算法的概率分析?

[英]Probabilistic Analysis of Algorithm in simple language?

Could anyone explain the Probabilistic Analysis of Algorithm in simple words? 有人能用简单的词解释算法的概率分析吗? Couldn't find much info in Wiki page. 在Wiki页面中找不到太多信息。

Suppose you want to determine the expected runtime of a comparison-based sort algorithm. 假设您要确定基于比较的排序算法的预期运行时间。 Here's how you would approach this problem: 以下是您将如何解决此问题:

  • Define a distribution over all possible inputs to the algorithm 定义算法的所有可能输入的分布
    • For example, say that all N! 例如,说全N! permutations of ordering N distinct numbers are equally likely (1/N!) 排序的排列N个不同的数字同样可能(1 / N!)
  • Determine the runtime for each possible input 确定每个可能输入的运行时间
  • Compute the expected runtime by summing up over all possible inputs the probability of the input times the runtime for the input 通过对所有可能的输入求和,输入的概率乘以输入的运行时来计算预期的运行时间
    • That is, E[Runtime] = sum i=1,...,N! 也就是说,E [Runtime] = sum i = 1,...,N! { P(i) * Runtime(i) } = sum i=1,...,N! {P(i)* Runtime(i)} = sum i = 1,...,N! { Runtime(i) } / N! {运行时间(i)} / N!

For example, if you do this with the quicksort algorithm (with naive choice of pivot), you will find that the expected runtime of quicksort is O(N log N) while the worst-case runtime is O(N 2 ). 例如,如果使用快速排序算法(通过选择枢轴),您会发现快速排序的预期运行时间为O(N log N),而最坏情况运行时为O(N 2 )。

I found a great presentation which explains this in simplistic terms 我找到了一个很棒的演讲,用简单的术语解释了这一点

http://www.lsi.upc.edu/~conrado/research/talks/survey-Stellenbosch.pdf http://www.lsi.upc.edu/~conrado/research/talks/survey-Stellenbosch.pdf

IMHO, it boils down to "Given an algorithm and "typical input" what would be the performance of a randomized algorithm" 恕我直言,它归结为“给定算法和”典型输入“随机算法的性能是什么”

where, typical input really depends on for what purpose you are evaluating the algorithm, you can provide a uniform or a random distribution for input value and measure performance characteristics 其中,典型输入实际上取决于您评估算法的目的,您可以为输入值提供统一或随机分布并测量性能特征

In simple language: 用简单的语言:

If you want to cook a steak, you'd know that the size of your steak will change the time needed on the grill for it to be ready. 如果你想煮牛排,你就会知道牛排的大小会改变烤架所需的时间。 The raw steak is your input, the grill is your function (ie alg.) and the cooked one is your output. 生牛排是你的输入,烤架是你的功能(即alg。),煮熟的牛排是你的输出。

Now, say that I ask you: "how much time does it take your grill to grill a steak on average?" 现在,我要问你:“你的烧烤平均需要多长时间烤牛排?” how would you go about that? 你会怎么做? Probabilistic Analysis suggests that all possible sizes of steaks could come your way.Therefore, this method produces average running time .This method will provide you a number that represents this situation, so you could perhaps compare different grills. 概率分析表明所有可能的牛排尺寸都可以按照您的方式进行。因此,这种方法可以产生平均运行时间 。这种方法会为您提供一个代表这种情况的数字,因此您可以比较不同的格栅。 Hope that helps! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM