编译器如何理解递归?(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
最满意答案
你的算法很好,但你的结果是不可代表的。
特别要注意的是,你的
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 eachload[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 ...
-
如何创建懒惰组合(How to create lazy combinations)[2023-03-22]
这是我想出的: 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 c2
c4 and c4 c6 : ... -
你的算法很好,但你的结果是不可代表的。 特别要注意的是,你的np.unique是无用的,因为每个load[i]包含重复项,所以结果的大小是列表长度乘以列表数目的乘积 >>> np.prod([len(i) for i in second_example], dtype=np.int64) * 9 2498897217529908 假设乐观地认为每个整数都是uint8 ,即2.2 PiB(Pebibytes),远远超过当前的RAM配置。 即使你不试图将整个结果一次写入内存,即使迭代这个过程也需要很长时间 - ...
-
算法,可以创建所有组合和所有组合(Algorithm that can create all combinations and all groups of those combinations)[2022-01-20]
你可以递归地做到这一点,并避免重复,如果你保持每个递归中的第一个元素被固定,并且只按照顺序对这些值进行组合,例如: {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} ... -
控制台erros innerHTML(Console erros innerHTML)[2023-06-03]
你得到了 未捕获的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 ... -
有效的组合组合(Efficient combinations of combinations)[2022-05-22]
正如切普纳所说,我正在寻找这个图中的所有周期或集团。 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
-
Swift 3中的AVCaptureSession到UIImage的Erros(Erros with AVCaptureSession to UIImage in Swift 3)[2023-09-14]
对于第一个错误: 实现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, ...