首页 \ 问答 \ 编译器如何理解递归?(How do compilers understand recursion?)

编译器如何理解递归?(How do compilers understand recursion?)

我在c和python编程时遇到了递归问题,我猜它在很多其他语言中也是如此,但编译器如何实际解释递归函数? 它如何在自己的定义中使用函数?


I've delt with recursion when programming in c and python and I'm guessing it's used in many other languages as well, but how does a compiler actually interpret a recursion function? How can it use the function in it's own definition?


原文:https://stackoverflow.com/questions/40796473
更新时间:2023-06-10 16:06

最满意答案

你的算法很好,但你的结果是不可代表的。

特别要注意的是,你的np.unique是无用的,因为每个load[i]包含重复项,所以结果的大小是列表长度乘以列表数目的乘积

>>> np.prod([len(i) for i in second_example], dtype=np.int64) * 9
2498897217529908

假设乐观地认为每个整数都是uint8 ,即2.2 PiB(Pebibytes),远远超过当前的RAM配置。

即使你不试图将整个结果一次写入内存,即使迭代这个过程也需要很长时间 - 假设一个慷慨的4GHz处理器和每个结果的单个时钟周期,你看起来比一个时间长一周完成


Your algorithm is fine, but your result is unrepresentable.

Note in particular that your np.unique is useless, because each load[i] contains no duplicates, so the size of the result is the product of the lengths of the lists times the number of lists

>>> np.prod([len(i) for i in second_example], dtype=np.int64) * 9
2498897217529908

Assuming optimistically that each integer is a uint8, that's 2.2 PiB (Pebibytes), which far exceeds current RAM configurations.

Even if you don't try to put the whole result in memory at once, even iterating over this is going to take a long time - assuming a generous 4GHz processor and a single clock cycle per result, you're looking at longer than a week to finish

相关问答

更多
  • 您是否尝试删除该行并手动输入? 因为据我所见,第12行中的所有内容都很好(以下是来自VMware官方帮助的关于此命令的代码: $vm = Get-View -ViewType VirtualMachine -Filter @{"Name" = "VM"} 所以也许有一些复制\粘贴问题? 另外,你是否尝试在ISE中进行调试? 你会得到什么错误? Did you try deleting that line and typing it in manually? Because as far as I can ...
  • 这是我想出的: func combinations(options: [[T]]) -> AnySequence<[T]> { guard let lastOption = options.last else { return AnySequence(CollectionOfOne([])) } let headCombinations = combinations(options: Array(options.dropLast())) return A ...
  • alko已经为你的计划列出了有用的改革,Tim Peters指出500-choose-6超过21万亿(即21057686727000)。 这个答案将指出原始程序的简单加速。 (我认为与alko的方法相比,这是一个小的加速,但以下值得注意未来的python编程。) 你的选择陈述是 if c1-c2>0 and c2-c3<0 and c3-c4>0 and c4-c5<0 and c5-c6>0 : 这相当于 if c1>c2 and c2c4 and c4c6 : ...
  • 你的算法很好,但你的结果是不可代表的。 特别要注意的是,你的np.unique是无用的,因为每个load[i]包含重复项,所以结果的大小是列表长度乘以列表数目的乘积 >>> np.prod([len(i) for i in second_example], dtype=np.int64) * 9 2498897217529908 假设乐观地认为每个整数都是uint8 ,即2.2 PiB(Pebibytes),远远超过当前的RAM配置。 即使你不试图将整个结果一次写入内存,即使迭代这个过程也需要很长时间 - ...
  • 你可以递归地做到这一点,并避免重复,如果你保持每个递归中的第一个元素被固定,并且只按照顺序对这些值进行组合,例如: {1,2,3,4,5,6,7,8,9} 把最低的元素放在第一个地方(a),并保留在那里: {a,b,c} = {1,*,*} 对于第二点(b),迭代从第二低到第二高的每个值: {a,b,c} = {1,2〜8,*} 对于第三个点(c),迭代每个高于第二个值的值: {1,2〜8,b + 1〜9} 然后递归其余的值。 {1,2,3} {4,5,6} {7,8,9} {1,2,3} {4,5,7} ...
  • 你得到了 未捕获的TypeError:无法设置null time.js:8的属性'innerHTML' 因为 document.getElementById("jstimer") 返回null,表示找不到该元素。 您需要检查您的html并确保在此计时器触发时 ,您的dom中实际上存在一个带有jstime的id (不是类,名称或其他任何内容)的jstime You're getting Uncaught TypeError: Cannot set property 'innerHTML' of null t ...
  • 正如切普纳所说,我正在寻找这个图中的所有周期或集团。 Networkx的enumerate_all_cliques()是一种查找它们的简便方法。 As chepner suggested, i was looking for all cycles or cliques in this graph. Networkx's enumerate_all_cliques() is an easy way to find them.
  • 您必须使用未记录的标志: dartanalyzer --enable-enum enum_demo.dart You have to use an undocumented flag: dartanalyzer --enable-enum enum_demo.dart
  • 对于第一个错误: 实现AVCaptureVideoDataOutputSampleBufferDelegate委托,它将为您提供当前会话的AVCaptureOutput和CMSampleBuffer 。 class YourClass : AVCaptureVideoDataOutputSampleBufferDelegate {} public func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampl ...
  • 在第二个循环中,您将(key, value)元组分配给单个变量, keys : for keys in sorted (Egyptian_Division_dict.items(),reverse = True): 然后尝试将该元组添加到整数: quetient = 0 # in the loop w = keys quetient = quetient + w 这是抛出异常的最后一行。 您似乎忘记在该循环中包含values变量; 将其添加回来至少会使keys再次成为一个密钥: for keys, ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。