渐近预期运行时间(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

相关问答

更多

Magento在搜索产品目录搜索时出错(Magento giving error on searching product catalog search)

我的猜测是你正在使用带有该函数的主题来计算搜索结果,而该方法未定义,因此错误“”无效方法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, ...

使用bs4使用Python 3.5搜索Google时出错(Error in searching Google with Python 3.5 using bs4)

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/sear...

搜索时出错:全部(Error searching for :all)

我觉得找不到:全部。 文件说 “使用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 t...

在Django admin中搜索时出错(Error searching in Django admin)

检查search_fields文档, 如上所述 这些字段应该是某种文本字段,例如CharField或TextField。 您还可以使用查找API“跟随”表示法对ForeignKey或ManyToManyField执行相关查找: search_fields = ['foreign_key__related_fieldname'] 所以在你的情况下 search_fields = ['identity__username'] 另请注意,它并没有说您可以使用先尝试过的计算属性 Check searc...

使用Sunspot Solr Rails 3搜索多个模型时出错(Error searching multiple models with Sunspot Solr Rails 3)

在进行单一模型搜索时,您将结果呈现在受尊重的控制器的相同索引页中,例如,让我们在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_...

搜索(Searching through)

i18n-tasks是一个通过静态分析实现这一目标的宝石: i18n-tasks is a gem that does just this with static analysis:

SQL LIKE%NOT SEARCHING(SQL LIKE % NOT SEARCHING)

使用 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 ...

xpath搜索属性时出错(xpath Error while searching attributes)

item不是ElectricSpecifications的属性,而是其子节点,因此不是 [@item='Frequency'] 语法,试试 item[@name='Frequency'] 所以完整的XPath应该是这样的 //product/ElectricSpecifications/item[@name='Frequency' and contains(., ' $value')] item is not an attribute of ElectricSpecifications, b...

更新eclipse时出错:搜索备用解决方案(Error while updating eclipse: Searching Alternate solutions)

尝试从首选项中删除所有更新站点,重新启动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.

directory.getfiles在出错时停止搜索(directory.getfiles stops searching when error)

根据我的评论,错误发生是因为您的文件路径太长。 正如@Richard评论的那样,您可以直接使用Win32 API来绕过此限制。 但是,我个人更喜欢使用TechNet的Delimon.Win32.IO C#库。 该库取代了System.IO的基本文件功能,并支持最多32,767个字符的文件和文件夹名称。 请参阅下面的基本代码示例: using System; using System.Collections.Generic; using System.Linq; using System.Te...

相关文章

更多

HDFS patch前后Ganglia看到running processes变化的分析

Ganglia running processes是怎么算出来的?ganglia是通过 cat /pr ...

Real-Time Rendering 笔记 --- 1-4章

里面有些公式和矩阵无法在电脑上书写, 故用纸笔记录了一些笔记, 比如公式的推算, 注意要点等. 由于电 ...

Running Solr with Maven

Solris an open source search server which is built ...

Python IndentationError:expected an indented block的解决方案

在编译时会出现这样的错IndentationError:expected an indented bl ...

Another MySQL daemon already running with the same unix socket.

两个方法解决: 第一个是立即关机 使用命令 shutdown -h now 关机,关机后在启动,进程就 ...

Hadoop HDFS Wrong FS: hdfs:/ expected file:///

HDFS是一个分布式文件系统,然而对于程序员来说,HDFS就是一个普通文件系统,Hadoop进行的底层 ...

运行时编译执行一段代码

String abc = &quot;看看&quot;; String something = &q ...

C程序访问Hadoop运行时遇到的各种问题以及解决方案

C程序访问Hadoop运行时遇到的各种问题以及解决方案 问题1:当编译通过后,运行时,会出现: had ...

Hadoop运行时错误:Task process exit with nonzero status of 1

之前写好的一个 Hadoop代码,昨天晚上执行时报错了,查了半天没查出来,网上的方法都试了还是不行 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本