ackermann

Can this implementation of Ackermann function be called tail recursive?

不打扰是莪最后的温柔 提交于 2021-01-27 07:20:14
问题 I have written following code in C. Can we call it a tail recursive implementation? #include <stdio.h> int ackermann(unsigned int *m, unsigned int *n, unsigned int* a, int* len) { if(!*m && *len == -1) { return ++*n; } else if(!*m && *len >= 0) { ++*n; *m = a[(*len)--]; } else if(*n == 0) { --*m; *n = 1; } else { ++*len; a[*len] = *m - 1; --*n; } return ackermann(m, n, a, len); } int main() { unsigned int m=4, n=1; unsigned int a[66000]; int len = -1; for (m = 0; m <= 4; m++) for (n = 0; n <

Why is the Ackermann function related to the amortized complexity of union-find algorithm used for disjoint sets?

…衆ロ難τιáo~ 提交于 2019-12-23 07:56:04
问题 Can anybody give me an intuitive explanation of why the Ackermann function http://en.wikipedia.org/wiki/Ackermann_function is related to the amortized complexity of union-find algorithm used for disjoint sets http://en.wikipedia.org/wiki/Disjoint-set_data_structure? The analysis in Tarjan's data structure book isn't very intuitive. I also looked it up in Introduction to Algorithms, but it also seems too rigorous and non-intuitive. Thanks for your help! 回答1: Applied to Disjoint-set forests

Error in defining Ackermann in Coq

爱⌒轻易说出口 提交于 2019-12-18 21:17:24
问题 I am trying to define the Ackermann-Peters function in Coq, and I'm getting an error message that I don't understand. As you can see, I'm packaging the arguments a, b of Ackermann in a pair ab ; I provide an ordering defining an ordering function for the arguments. Then I use the Function form to define Ackermann itself, providing it with the ordering function for the ab argument. Require Import Recdef. Definition ack_ordering (ab1 ab2 : nat * nat) := match (ab1, ab2) with |((a1, b1), (a2, b2

Why is the Inverse Ackermann function used to describe complexity of Kruskal's algorithm?

妖精的绣舞 提交于 2019-12-08 08:57:01
问题 In a class for analysis of algorithms, we are presented with this pseudocode for Kruskal's algorithm: He then states the following, for disjoint-set forests: A sequence of m MAKE-SET, UNION, and FIND-SET operations, n of which are MAKE-SET operations, can be performed on a disjoint-set forest with union by rank and path compression in worst-case time O(m α(n)) . Used to compute the complexity of Step 2, and steps 5-8 For connected G: |E| ≥ |V| -1; m = O(V + E), n = O(V); So Steps 2, 5-8: O((V

Error in defining Ackermann in Coq

牧云@^-^@ 提交于 2019-12-01 03:50:56
I am trying to define the Ackermann-Peters function in Coq, and I'm getting an error message that I don't understand. As you can see, I'm packaging the arguments a, b of Ackermann in a pair ab ; I provide an ordering defining an ordering function for the arguments. Then I use the Function form to define Ackermann itself, providing it with the ordering function for the ab argument. Require Import Recdef. Definition ack_ordering (ab1 ab2 : nat * nat) := match (ab1, ab2) with |((a1, b1), (a2, b2)) => (a1 > a2) \/ ((a1 = a2) /\ (b1 > b2)) end. Function ack (ab : nat * nat) {wf ack_ordering} : nat