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]
524 questions
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…

Aleksandar Dimitrov
- 9,275
- 3
- 41
- 48
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…

lub0v
- 801
- 9
- 17
10
votes
2 answers
Recursively dir() a python object to find values of a certain type or with a certain value
I have a complex Python data structure (if it matters, it's a large music21 Score object) which will not pickle due to the presence of a weakref somewhere deep inside the object structure. I've debugged such problems with the stack trace and python…

Michael Scott Asato Cuthbert
- 3,442
- 2
- 22
- 52
9
votes
3 answers
Parse Directory Structure (Strings) to JSON using PHP
I have an array of file-path strings like this
videos/funny/jelloman.wmv
videos/funny/bellydance.flv
videos/abc.mp4
videos/june.mp4
videos/cleaver.mp4
audio/uptown.mp3
audio/juicy.mp3
fun.wmv
jimmy.wmv
herman.wmv
End goal is to get them to…

Ecropolis
- 2,005
- 2
- 22
- 27
9
votes
2 answers
Scope of mu (μ) bindings in type theory
A list in Haskell might look like this:
data List a = Nil | Cons a (List a)
A type theoretic interpretation is:
λα.μβ.1+αβ
which encodes the list type as the fixed point of a functor. In Haskell this could be represented:
data Fix f = In (f (Fix…

user2023370
- 10,488
- 6
- 50
- 83
9
votes
3 answers
Representing a directory tree as a recursive list
I am stuck with a certain task. What I want is a function that, given a directory path, would return a recursive-list as an output.
The output should be of the form myList$dir$subdir$subdir$fullFilePath
So basically I want to represent a directory…

Karolis Koncevičius
- 9,417
- 9
- 56
- 89
8
votes
2 answers
Recursive data type like a tree as Avro schema
Reading https://avro.apache.org/docs/current/spec.html it says a schema must be one of:
A JSON string, naming a defined type.
A JSON object, of the form:
{"type": "typeName" ...attributes...} where typeName is either a
primitive or derived type…

adelbertc
- 7,270
- 11
- 47
- 70
8
votes
2 answers
PHP RecursiveIterator traversing
I have a structure representing a form and I want to iterate it using RecursiveIterator.
The problem is this only returns the top-level questions. What am I doing wrong?
Whole form:
class Form implements RecursiveIterator{
private $id;
…

cypher
- 6,822
- 4
- 31
- 48
8
votes
2 answers
How to create a recursive data structure value in (functional) F#?
How can a value of type:
type Tree =
| Node of int * Tree list
have a value that references itself generated in a functional way?
The resulting value should be equal to x in the following Python code, for a suitable definition of Tree:
x =…

Muhammad Alkarouri
- 23,884
- 19
- 66
- 101
8
votes
0 answers
Multi-dimensional Dictionary class in VBA
This post is half to share a solution and half to ask if there's a better way to do it.
Problem: how to build a multi-dimensional dictionary in VBA.
It seems there are people out there looking for one, but there isn't an obvious neat solution around…

Bit Rocker
- 777
- 2
- 8
- 13
8
votes
2 answers
What is an infinite scaleless quadtree called?
2D spatial indexing question:
What do you call a data structure that is essentially an infinite* quadtree whose nodes contain neither absolute coordinates nor absolute scales -- in which the coordinate system of each node has been normalized to the…

Todd Lehman
- 2,880
- 1
- 26
- 32
7
votes
3 answers
Recursion versus manual stacks - Which is preferred in which case?
A recursive program creates a stack internally, and causes the users to write less code.
Are there any cases where recursion is actually preferred over manual stacks for the reason other than mentioned above?
EDIT 1:
In what way is dynamic memory…

Aquarius_Girl
- 21,790
- 65
- 230
- 411
7
votes
1 answer
Why do initial algebras correspond to data and final coalgebras to codata?
If I understand correctly, we can model inductive data types as initial F-algebras and co-inductive data types as final F-coalgebras (for an appropriate endofunctor F) [1]. I understand that according to Lambek's lemma the initial algebras (and…

Dan Oneață
- 968
- 7
- 14
7
votes
2 answers
Building a nested tree-like structure in Python using recursive or iterative approach
I have been trying to build a nested tree-like structure for two days and decided to ask here for help. Suppose I have data like this:
rows = [
{'Year': None, 'Region': None, 'Country': None, 'Manufacturer': None, 'Brand': None, 'Sales': 25}, #…

user1330974
- 2,500
- 5
- 32
- 60
7
votes
3 answers
How to use reflect to recursively parse nested struct in Go?
I have a nested three layer struct.
I would like to use reflect in Go to parse it (use recursive function). The reasons to use reflect and the recursive function are
can have various number of fields (but the first two fields are fixed)
the field…

Luffy Cyliu
- 811
- 1
- 9
- 11