首页 \ 问答 \ 渐近预期运行时间(Asymptotic Expected Running Time)

渐近预期运行时间(Asymptotic Expected Running Time)

我在渐近分析问题上遇到了一些麻烦。 该问题要求渐近最坏情况运行时间和函数的渐近预期运行时间。 Random(n)在1和n之间生成一个均匀分布的随机数(1到n之间的每个整数都是相同的。)

Func2(A, n)
/* A is an array of integers */
1 s ← A[1];
2 k ← Random(n);
3 if (k < log2(n)) then
4    for i ← 1 to n do
5       j ← 1;
6       while (j < n) do
7          s ← s + A[i] ∗ A[j];
8          j ← 2 ∗ j;
9       end
10   end
11 end
12 return (s);

我想知道第3行(if(k <log2(n))然后如何影响函数的预期运行时间。 我认为第4-10行在最坏情况下运行cn ^ 2时间,但我不确定如何根据if语句推导出预期的运行时间。 谢谢你的帮助!

-Matt


I'm having some trouble with an asymptotic analysis question. The problem asks for both the asymptotic worst case running time and the asymptotic expected running time of a function. Random(n) generates a random number between 1 and n with uniform distribution (every integer between 1 and n is equally likely.)

Func2(A, n)
/* A is an array of integers */
1 s ← A[1];
2 k ← Random(n);
3 if (k < log2(n)) then
4    for i ← 1 to n do
5       j ← 1;
6       while (j < n) do
7          s ← s + A[i] ∗ A[j];
8          j ← 2 ∗ j;
9       end
10   end
11 end
12 return (s);

I was wondering how line 3 (if (k < log2(n)) then) effects the expected running time of the function. I believe lines 4 - 10 run at worst case cn^2 time, but I am unsure how to derive the expected running time due to the if statement. Thanks for any help!

-Matt


原文:https://stackoverflow.com/questions/14689122
更新时间:2022-02-10 19:02

最满意答案

我觉得找不到:全部。 文件

“使用find方法,您可以检索与所提供的选项匹配的指定主键对应的对象。我认为这就足够了

Article.where('name LIKE ?', "%#{search}%")

或者如果您找到所有文章

Article.all

I think find can not take :all. the documentation says

"Using the find method, you can retrieve the object corresponding to the specified primary key that matches any supplied options. I think this is enough

Article.where('name LIKE ?', "%#{search}%")

or if you find all the articles

Article.all

相关问答

更多
  • 我的猜测是你正在使用带有该函数的主题来计算搜索结果,而该方法未定义,因此错误“”无效方法Mage_Catalog_Block_Layer_Filter_Category :: shouldDisplayProductCount “ 尝试默认主题,看看它是否有效。 My guess is that you are using a theme with the function to count the search results while that method is not defined, hence ...
  • import requests import json from bs4 import BeautifulSoup headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36'} s = requests.get('http://www.google.com/search?q= ...
  • 我觉得找不到:全部。 文件说 “使用find方法,您可以检索与所提供的选项匹配的指定主键对应的对象。我认为这就足够了 Article.where('name LIKE ?', "%#{search}%") 或者如果您找到所有文章 Article.all I think find can not take :all. the documentation says "Using the find method, you can retrieve the object corresponding to the ...
  • 检查search_fields文档, 如上所述 这些字段应该是某种文本字段,例如CharField或TextField。 您还可以使用查找API“跟随”表示法对ForeignKey或ManyToManyField执行相关查找: search_fields = ['foreign_key__related_fieldname'] 所以在你的情况下 search_fields = ['identity__username'] 另请注意,它并没有说您可以使用先尝试过的计算属性 Check search_fie ...
  • 在进行单一模型搜索时,您将结果呈现在受尊重的控制器的相同索引页中,例如,让我们在gem文档( articles_controller.rb )中使用Article模型。 def index @search = Article.search do fulltext params[:search] with(:published_at).less_than(Time.zone.now) facet(:publish_month) with(:publish_month ...
  • i18n-tasks是一个通过静态分析实现这一目标的宝石: i18n-tasks is a gem that does just this with static analysis:
  • 使用 LIKE '%' + @search + '%' 代替 LIKE '%@search%' 完整查询; ... else { sql = "SELECT a.cname,[bid],b.[bname],b.[baddress],b.[bcity],b.[bstate],b.[bpostcode],b.[bphone],b.[bfax],b.[bemail] FROM [CLIENT] a INNER JOIN [BRANCH] b ON a.clientID=b.clientID WHERE ...
  • item不是ElectricSpecifications的属性,而是其子节点,因此不是 [@item='Frequency'] 语法,试试 item[@name='Frequency'] 所以完整的XPath应该是这样的 //product/ElectricSpecifications/item[@name='Frequency' and contains(., ' $value')] item is not an attribute of ElectricSpecifications, but it ...
  • 尝试从首选项中删除所有更新站点,重新启动STS,然后逐步添加它们以查看错误何时开始显示。 Try to delete all the update sites from the preferences, restart STS, and add them back, step by step to see when the error starts to appear.
  • 根据我的评论,错误发生是因为您的文件路径太长。 正如@Richard评论的那样,您可以直接使用Win32 API来绕过此限制。 但是,我个人更喜欢使用TechNet的Delimon.Win32.IO C#库。 该库取代了System.IO的基本文件功能,并支持最多32,767个字符的文件和文件夹名称。 请参阅下面的基本代码示例: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)