Questions tagged [recursive-datastructures]
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.
486
questions
0
votes
1
answer
54
views
Recursive R function to flatten hierarchical json dataset
I have a json file that looks like this:
{
"data": [
{
"sense": "a_lot.r.01",
"frequency": 20,
"level": 0,
"...
0
votes
1
answer
18
views
How to (efficiently) retrieve the value of a column in a different row based on matching IDs?
I'm trying to do what I did in the example below, but on a large scale so Ideally the solution is as efficient as possible. Thanks in advance!
ID1 <- c("a", "d", "c", &...
0
votes
2
answers
60
views
Forward declare using directive for recursive definitions
I have an array with items of type variant that I want to iterator over using the generic std::array iterator. Now I want to do the management of the array with my own class array2. However, the ...
1
vote
1
answer
31
views
When did CPython's `repr` start handling recursive data structures?
This MWE in the past would cause a stack overflow, as x references y that references x:
class Ref:
def __init__(self, name):
self.name = name
self.value = None
def __repr__(...
0
votes
1
answer
9
views
Why the no. of countNodes always returning as 1?
In "exploreComponent" function count is increasing according to the no. of nodes present in that Component but before returning count decreases to 1, why this happening ?
Defined a Graph ...
0
votes
1
answer
30
views
JavaScript building a breadth-first tree from multimap (which data has cycles)
Prerequisites:
I have a general tree class with: myTree = new Tree(string), appendChildNode(node), createChildNode(string)->node, myTree.print() functions and myTree.name, myTree.children, myTree....
0
votes
1
answer
40
views
Java recursively delete objects and move other objects into their place
I have an unknown depth recursive object and I need to delete specific nodes and bring their children into their place... That might not make sense so here is my best attempt at a representation:
[
{...
1
vote
2
answers
64
views
time complexity recursive function
How can i calculate the time complexity and the t(n) equation of this recursive function?
Function CoeffBin(n,k)
if (n=1) or (k=0) then return(1)
else return (CoeffBin(n-1,k) + CoeffBin(n-1,k-1))
0
votes
0
answers
43
views
Loop ending when I call my method insert(), and can't see why
First of all sorry for my English. Second I'm new in c and data structures.
I created a menu and put it in loop so that I could use it to make operations like insert, remove(all the tree nods), remove(...
-1
votes
2
answers
54
views
How to revert back to original array after updating it in C lang? like using a temp pointer or any other way to revert?
//I want to revert array back to original state after 2nd printf statement OR code any other way such that next code a=++(*p) operates on origianl array not on Update array.
CODE:
#include <stdio.h&...
0
votes
1
answer
22
views
What does the error it is giving me mean? sql recursive
I'm trying to build a table of costars (name1, name2) of names of actors who have acted in the same movie.
For this I make use of three tables: titles(id, titles), names(id, names) and acted(name_id, ...
1
vote
2
answers
47
views
How do python list items change if they are involved in recursive loops?
This function reverses all the items found in the list. Even the inner lists get reversed. My problem is that I do not understand how the reversed_list keeps 7 and 6 after the recursion. Since once ...
1
vote
1
answer
46
views
Cannot retain value in Java recursive call?
I have the following method in my Java app:
public List<UUID> recursiveMethod(UUID productUuid) {
Set<UUID> productUuidSet = new HashSet<>();
productUuidSet.add(productUuid);
...
0
votes
2
answers
61
views
Transform data structure to tree data in JavaScript
I have a data structure like this:
data = [
{
parent: {name: 'Sheet'},
firstArray: [{sampleVar: 0.3, typeName: 'active'}, {sampleVar: 0.4, typeName: 'active'}],
secondArray: [{...
0
votes
1
answer
50
views
Recursive Implementation of a Singly Linked List
Hello I am trying to do this exercise:
Give a recursive implementation of a singly linked list class, such
that an instance of a nonempty list stores its first element and a
reference to a list of ...
0
votes
1
answer
63
views
Get parent from nested Map - Java
I have this json Input
[
{
"id": "32",
"name": "Menu full"
"description": "Here is the object {id} is {name}"
...
0
votes
0
answers
77
views
how to display a nested list
I have a recursive table, of which I want to present the main elements and their sebelements
id
name
parent
order
1
Menu A
1
2
Menu B
2
3
Menu a
1
1
4
Menu b
2
1
5
Menu C
3
6
Menu D
4
7
...
0
votes
0
answers
23
views
Quicksort to generate a nearly sorted output with K error
I need to change the psuedo code
To output a nearly sorted array where an element is at a maximum of K away from it's sorted position.
For example the array 6,1,2,3,4,7 is sorted for K=4, because 7>...
0
votes
0
answers
37
views
In a relaxed radix balanced (RRB) tree, how is the height determined in practice?
In a traditional radix-balanced tree, the height of the tree can be determined quickly by counting the leading zeros of the number of elements of the tree, and indexes to children can be determined by ...
0
votes
1
answer
101
views
Java Filter list object with Recursive Children
Given this obj.
public class Menu {
private String id;
private String matchCode;
private List<Menu> children;
//getters and setters
/**
* Flattened funcition to recursive children list
*...
0
votes
0
answers
40
views
How do Infinite nested tags in Bear note app work, from a programming perspective?
I am a self-taught programmer. Recently I found a note app named Bear, and it organizes notes with a flexible tagging system.
Can you help me understand how this infinite nested tag system works, from ...
-1
votes
1
answer
48
views
For loop is not working inside recursive function
1.I have a use case where i want the parent to be made false if any last child "isSelected" is true. For example the id 4 isSelcted is true so the parents of 4 are 3,2,1 whose key "...
0
votes
2
answers
172
views
How to find indexes of elements in recursive-knapsack?
I'm trying to implement recursive Knapsack which would return 2 things:
Max value we get by filling knapsack.
Indexes of the elements considered for filling the knapsack.
Please note that I don't ...
0
votes
1
answer
19
views
Given a kd tree-like grid, how to find two nearest intersecting lines
Say I have a grid structure like the image here:
Give point D, I want to find the nearest points whose line intersects with the line created by D.
I need a way to find C and E, but not A or B.
A is ...
0
votes
2
answers
71
views
How to implement Linked List Recursion in KOtlin
I am learning linked list and came across a problem where you are required to reverse a linked list using recursion. Here is the code I wrote:
fun reverseRecurseTraverse1(firstNode: Node<Int>?): ...
0
votes
1
answer
63
views
How to recursively create a Modal with an array of data in Swift
I need to recursively add these comments in the correct order.
Currently i get an array of comments that are unsorted.
These comments can be the top level or can be a child of the top level.
I was ...
1
vote
3
answers
117
views
How to see all "ancestors" of a recursive data model?
I am receiving a JSON:
{
"categories":
[
{
"category_name": "example name",
"children":
[
{
...
0
votes
2
answers
101
views
C++: How to pass data from parent to child in a lambda inside a recursive function
I want to iterate over a data structure and collect the paths of the elements. I'd like to do it in a way where the iteration over the structure is as generic as possible (see void ...
0
votes
3
answers
54
views
How can I number my points and subpoints which has an unlimited number of nested objects using recursive function and js
let's say I have data something like this
let data = [
{
subPoint:[
{
point:'point a 1.1',
},
{
point:'point a 1.2',
...
0
votes
0
answers
20
views
Error undefined reference to & Error ld returned 1 exit status [duplicate]
I am trying to make this program work, which was extracted from the book "As a deitel sixth edition C++ program" on pages 778 to 781, but I have corrected some of the errors that appeared ...
1
vote
2
answers
89
views
Recursive query takes too much time to load data in C#
*I have written a recursive query to get unlimited menu layer. The query works fine providing the exact results but it takes too much time to load. It takes probably 10 to 15 seconds. Please help me ...
2
votes
0
answers
84
views
How to sort file path names in hierarchy basis?
I want to sort out file names in hierarchy basis.
Let say I have below list of folders:
D:Movies\Hollywood\Comedy\adultcomedy
D:Movies\Hollywood\Comedy\horrorcomedy
D:Movies\Hollywood\Romantic\ adult
...
0
votes
0
answers
60
views
Can someone explain this piece of code from Cracking The Coding Interview?(All Permutation of a String)
I was going through the Big O section of the book Cracking the Coding Interview and I came by this piece of code. This code takes in a string suppose "abc" and prints all the permutations of ...
-1
votes
2
answers
318
views
Recursion method that finds the sum between two numbers
I want to implement a recursive method that finds the sum of x consecutive integers, starting from a starting number and ending with an end number.
For example, if start = 0 and end = 3, the method ...
0
votes
0
answers
96
views
Returning a constructed recursive data structure in Rust
I've just started learning Rust and am coming from a functional programming background. I'm trying to create a parser in rust and have defined this recursive data structure
enum SimpleExpression<'a&...
1
vote
1
answer
201
views
Largest value in each level of a binary tree
Ok so I am working on my algorithm and data structure knowledge and I am trying to find the largest number in each level of a binary tree. I am not sure what is wrong with my logic here.
class ...
0
votes
1
answer
96
views
How can I return a boolean while traversing a BinaryTree recursivly and checking for a specific Node with matching Value?
I'm currently working on Tree Data Structures and Recursion in Java.
My Plan was to have a recursive method, which traverses the Tree and checks if any Node in the Tree has this certain value. If so, ...
3
votes
0
answers
103
views
How to infer recursive container types (with dependent types) in typescript?
Let's say I can have any of the following values in typescript and I pass it to a function:
[1, [2,3,4], 5]
[1, 2, [3,4,5]]
How can I type the function and the ReturnType of the function so I can ...
1
vote
1
answer
110
views
Programmatically find specific node and add property to deep nested object [duplicate]
Given an array like this, where the maximum depth can be 3 levels and where we don't know at what level the researched item could be:
const data = {
id: '1',
children: [
...
1
vote
1
answer
44
views
Leetcode Combination Sum Problem. Problem understanding the 15th line
Hi I am new to Data Structure and I have some problem understanding the line "ds.remove(ds.size()-1);". Could anyone please help me out here?
class Solution {
private void findCombinations(...
-1
votes
1
answer
76
views
How to print all the ways to cut off a string - combination
input: "abcd"
output: a list of all the ways to cut off the string.
[ ["a", "bcd"],["a", "b", "cd"], ["a", "b", "c&...
15
votes
1
answer
384
views
How can I dynamically allocate cyclic data?
For the sake of example let's define a toy automaton type:
data Automaton =
Auto
{ success ::
Automaton
, failure ::
Automaton
}
This structure is designed to by cyclic, we ...
1
vote
0
answers
87
views
How to recursively transform this object?
I want to recursively traverse an object and modify it.
For the object below, I want to recursively traverse children until I reach a child which has no children and only text property. If the text is ...
3
votes
3
answers
303
views
How to understand the "reflexive aggregation" relationship similar to reflexive association in UML
What does this class diagram mean? The class diagram of reflexive association uses solid lines and arrows, but here is replaced by a hollow diamond. Does it have anything to do with recursion? What ...
1
vote
1
answer
130
views
Extracting confidence intervals and residuals is failing for recursive panel data in modeltime
In a former question of mine, I did achieve the extraction of confidence intervals for recursive ensembles in modeltime. However, if I change the data input to a time series panel, the resulting ...
0
votes
0
answers
26
views
Resolve recursive (n → ∞) Promise(s)
Consider the following recursive parent/child tree-builder pseudo/example. Figuring out what is the best approach to determine when recursion stops so I can resolve the whole of it.
I was thinking in ...
0
votes
0
answers
25
views
How do I work on recursive postorder for this tree?
I am trying to work on the recursive post order and I have got the recursive preorder here and I am trying to make sure if I have got the recursive postorder correct?
For recursive preorder:
void ...
1
vote
3
answers
212
views
A recursive interface for a React Typescript component
The component is a breadcrumb, it must receive as props an object that contains a title and an url and also an option children node. The maximum depth should be 5, in this case this is a props example:...
0
votes
0
answers
22
views
Advice on adding an ancestors ArrayField to a self-referential model in Django
I'm developing a Django app (Django 3.2.8, Python 3.9, PostgreSQL 13.4) that functions very much like an FTP service. For the folder/file structure I've created a self-referential model called "...
2
votes
3
answers
45
views
How to search in a tree?
I have this follow tree implementation:
class Node:
def __init__(self, *, val):
self.val = val
def __repr__(self):
return "{}(val={})".format(type(self).__name__, ...