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
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…
![](../../users/profiles/249355.webp)
Ecropolis
- 1,885
- 2
- 21
- 26
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…
![](../../users/profiles/2023370.webp)
user2023370
- 9,597
- 5
- 41
- 74
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…
![](../../users/profiles/1953718.webp)
Karolis Koncevičius
- 7,687
- 9
- 48
- 71
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;
…
![](../../users/profiles/371707.webp)
cypher
- 6,574
- 3
- 28
- 46
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 =…
![](../../users/profiles/336455.webp)
Muhammad Alkarouri
- 21,347
- 16
- 59
- 94
8
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…
![](../../users/profiles/1293501.webp)
Michael Scott Cuthbert
- 2,611
- 2
- 18
- 40
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…
![](../../users/profiles/474311.webp)
Dan Oneață
- 948
- 6
- 13
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}, #…
![](../../users/profiles/1330974.webp)
user1330974
- 2,235
- 4
- 24
- 47
7
votes
3 answers
Insert node at the end of linked list
There is a simple iterative solution for these kind of problems.
Node Insert(Node head,int data) {
Node newNode = new Node();
newNode.data = data;
if (head == null) {
return newNode;
}
Node current = head;
while…
![](../../users/profiles/4260745.webp)
CodeYogi
- 1,192
- 1
- 14
- 34
7
votes
3 answers
A data structure for Logical Expressions in Haskell
I try to create a data structure for working with logical expressions. At first glance, the logical expressions look like Trees, so it seems reasonable to make up it from trees:
data Property a = And (Property a) (Property a) |
Or …
![](../../users/profiles/2615160.webp)
Sergey Sosnin
- 1,131
- 10
- 29
7
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…
![](../../users/profiles/267551.webp)
Todd Lehman
- 2,230
- 1
- 22
- 30
7
votes
3 answers
Is there an elegant way to have functions return functions of the same type (in a tuple)
I'm using haskell to implement a pattern involving functions that return a value, and themselves (or a function of the same type). Right now I've implemented this like so:
newtype R a = R (a , a -> R a)
-- some toy functions to demonstrate …
![](../../users/profiles/2072588.webp)
Lily
- 155
- 6
6
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…
![](../../users/profiles/462608.webp)
Aquarius_Girl
- 18,558
- 57
- 191
- 353
6
votes
1 answer
How to create a recursive structure in ASP.NET MVC
I have a categories table which has three fields: Id, Title, and ParentId. I'd like to create a recursive hierarchical structure of my table (a tree) in a cshtml file. I'm new to ASP.NET MVC and I don't know how to do that, because there is no…
![](../../users/profiles/811785.webp)
Saeed Neamati
- 33,583
- 40
- 128
- 183
6
votes
2 answers
How can I walk this type with a recursion scheme instead of explicit recursion?
Consider this code:
import Data.Maybe (fromMaybe)
data MyStructure = Foo Int | Bar String MyStructure | Baz MyStructure MyStructure | Qux Bool Bool MyStructure MyStructure deriving(Eq,Show)
makeReplacements :: [(MyStructure, MyStructure)] ->…
![](../../users/profiles/7509065.webp)
Joseph Sible-Reinstate Monica
- 34,270
- 3
- 35
- 75