A recursive datastructure is a datastructure (e.g. a struct or class) that contains one or several references to instances of the same datastructure as a member.
Questions tagged [recursive-datastructures]
402 questions
291
votes
15 answers
What do I use for a max-heap implementation in Python?
Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
![](../../users/profiles/8458.webp)
Douglas Mayle
- 18,173
- 7
- 40
- 57
50
votes
6 answers
Mastering Recursive Programming
I am having trouble in thinking/solving the problem in terms of recursion. I really appreciate the concept and I can understand them like creating base case, exit case & the recursive calls etc. I can solve simple problems like writing factorial or…
![](../../users/profiles/416207.webp)
Hunter
- 2,212
- 2
- 19
- 22
48
votes
4 answers
What does Python mean by printing "[...]" for an object reference?
I'm printing a value of a what I thought was a list, but the output that I get is:
[...]
What does this represent? How do I test for it? I've tried:
myVar.__repr__() != '[...]'
and
myVar.__repr_() != Ellipsis
but no dice...
Here's a cutdown of…
![](../../users/profiles/35961.webp)
Dycey
- 4,251
- 3
- 41
- 66
27
votes
1 answer
What is the difference between Fix, Mu and Nu in Ed Kmett's recursion scheme package
In Ed Kmett's recursion-scheme package, there are three declarations:
newtype Fix f = Fix (f (Fix f))
newtype Mu f = Mu (forall a. (f a -> a) -> a)
data Nu f where
Nu :: (a -> f a) -> a -> Nu f
What is the difference between those three data…
![](../../users/profiles/3986708.webp)
hgiesel
- 4,699
- 1
- 21
- 47
24
votes
7 answers
populate treeview from a list of path
I'm trying to populate a treeview from a list of folder path, for…
Eric
17
votes
9 answers
Confusing [...] List in Python: What is it?
So I was writing up a simple binary tree in Python and came across [...]
I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this…
![](../../users/profiles/40172.webp)
Demur Rumed
- 351
- 3
- 8
16
votes
2 answers
Why inductive datatypes forbid types like `data Bad a = C (Bad a -> a)` where the type recursion occurs in front of ->?
Agda manual on Inductive Data Types and Pattern Matching states:
To ensure normalisation, inductive occurrences must appear in strictly positive positions. For instance, the following datatype is not allowed:
data Bad : Set where
bad : (Bad →…
![](../../users/profiles/1333025.webp)
Petr
- 60,177
- 8
- 136
- 295
16
votes
2 answers
Initializing circular data in C. Is this valid C code according to any standard?
I wanted to see if I could initialize a global variable to point to itself:
#include
struct foo { struct foo *a, *b; } x = { &x, &x };
int main()
{
printf("&x = %p, x.a = %p, x.b = %p\n", &x, x.a, x.b);
return 0;
}
This code…
![](../../users/profiles/810671.webp)
Matt
- 17,895
- 16
- 55
- 102
14
votes
1 answer
Understanding recursion without base case in Julia
This snippet is from the implementation of Rational Numbers in Julia:
# Rational.jl
# ...
Rational{T<:Integer}(n::T, d::T) = Rational{T}(n,d)
Rational(n::Integer, d::Integer) = Rational(promote(n,d)...)
Rational(n::Integer) =…
![](../../users/profiles/858962.webp)
dopatraman
- 11,801
- 22
- 74
- 138
14
votes
3 answers
scalacheck Arbitrary implicits and recursive generators
I'm seeing what seems to be a very obvious bug with scalacheck, such that if it's really there I can't see how people use it for recursive data structures.
This program fails with a StackOverflowError before scalacheck takes over, while constructing…
![](../../users/profiles/107331.webp)
Daniel Martin
- 21,725
- 6
- 46
- 64
13
votes
2 answers
Python hangs indefinitely trying to delete deeply recursive object
I wrote a ternary search tree in Python and I've noticed that when the tree gets very deep, attempting to delete it causes Python to hang indefinitely. Here is a stripped version of the code that produces this behaviour:
import random
import…
![](../../users/profiles/4569000.webp)
Christian Adam
- 187
- 7
13
votes
4 answers
How CSS and DOM is implemented in the browser?
This is a pretty academic question. I'm wondering how the browser is implemented as in what data structure or algorithm is used to map a CSS selector to a particular DOM element. Is it accomplished through a hash table? How does DOM child node…
![](../../users/profiles/199966.webp)
Jlam
- 1,812
- 1
- 19
- 26
10
votes
1 answer
Writing generic instances for Fix/Mu in F-algebras
After reading Milewski's F-algebra article, I tried to implement it and use for a real-world problem. However, I can't seem to figure out how to write instances for Fix,
newtype Fix f = Fx { unFix :: f (Fix f) }
cata :: Functor f => (f a -> a) ->…
![](../../users/profiles/440302.webp)
Rufflewind
- 7,892
- 1
- 32
- 50
10
votes
1 answer
Tying the knot on mutually recursive ADTs with well-typed error handling
(Note: this post is a literate-haskell file. You can copy-paste it into a text
buffer, save it as someFile.lhs, and then run it using ghc.)
Problem description: I want ot create a graph with two different node types that
reference each other. The…
![](../../users/profiles/11797.webp)
Aleksandar Dimitrov
- 8,790
- 3
- 39
- 46
10
votes
2 answers
Gson deserialize complex object with recursive dependencies
I have several classes that contain a recursive dependency on each other and I serialize them to JSON format with Gson GraphAdapterBuilder, and it works perfectly. Now I want to deserialize them into the same structure but can't find out how.
I've…
![](../../users/profiles/2835311.webp)
lub0v
- 591
- 5
- 13