All Questions
47,418 questions
-2 votes
2 answers
78 views
Return the depth of an object with multiple properties [closed]
I'm doing a coding exercise. I must create a recursive function that return the depth of an object. Said object has several properties and arrays of children, emulating a family tree: const foo = { ...
0 votes
0 answers
96 views
In backtracking what decides if the next recursive call should move sequentially to the next position/ jump ahead based on the element just processed?
In some problems like permutations, we fill positions one by one, while in others like subsets or partitioning, we move ahead based on the elements we have already chosen. Why do these problems move ...
2 votes
1 answer
69 views
Laravel deleting event prints wrong children titles in recursive tree delete
I have a self-referencing Laravel model for a category tree. Each node can have children, and I want to delete a node together with all of its descendants. My relationship looks like this: public ...
Best practices
0 votes
5 replies
77 views
How to learn and practice recursion?
I have started and stopped DSA multiple times on arrays and Strings but this time I want to do it whatever it takes and someone from my known give me advice that if I get a good hand on recursion and ...
Best practices
0 votes
3 replies
77 views
Stuck on Recursion
I am currently working through a daily DSA challenge using Java, and recursion keeps tripping me up. I've tried learning it a few times, but I lose track of the execution flow, especially when a ...
-3 votes
1 answer
174 views
How to do hierarchical queries with arrays [closed]
I have an JavaScript array like this: let myArray = [ { name: 'Alice', children: ['Bob', 'Bill'] }, { name: 'Bob', children: 'Cindy' }, { name: 'Bill', children: [] }, { name: 'Cindy', ...
0 votes
2 answers
117 views
Bash recursion bug with ghost item in array? [closed]
My script for batch downloading a set of LibreText open textbooks prepares a list of links: #!/bin/bash function recurse_directories { S="$1" echo "S=$S" r="$(echo "$S&...
3 votes
2 answers
171 views
How to get all possible sums of the values of an array without recursion
I'm making a small project to play "escoba", a Spanish card game. I need to get all the ways to sum up to 15 with a number of cards (up to 16) on the table and 1 card from my hand. To save ...
2 votes
3 answers
348 views
Why does my code for finding the max. depth of a tree fail?
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ int maxDepth(struct TreeNode *root) { if (root ...
3 votes
2 answers
86 views
Calculating time elasped in ChezScheme
I am trying to solve the exercise 1.22 in SICP with ChezScheme on my MacOS, I did some reading here and found out I could use time procedure to get the CPU runtime of any other procedure. I couldn't ...
1 vote
2 answers
97 views
Understanding execution order and backtracking in recursive subset generation
I am trying to understand how recursion and backtracking work in the following Java method that prints all subsets of a string. I understand the base case where idx == s.length() and the current value ...
Advice
2 votes
4 replies
76 views
How does DP provide optimization over backtracking in 0-1 Knapsack problem
0-1 Knapsack problem is often used as a starting problem to understand dynamic programming. This problem can also be solved using backtracking. Now, backtracking explores all possible subsets and uses ...
7 votes
1 answer
118 views
Why is a recursive Lua function calling itself via a local alias instead of directly?
Below code is from nmap tableaux.lua script file which is located at /usr/share/nmap/nselib local tcopy_local function tcopy(t) local tc = {} for k, v in pairs(t) do if type(v) == "table&...
-2 votes
1 answer
118 views
Remove Specific Files from Subfolders [closed]
I’ve found a way to remove the annoying thumbs file that prevents me from deleting folders. Currently, I go into a folder, shift-click “run power shell window here and then type: rm thumbs.db -force ...
9 votes
1 answer
347 views
"Aggregate functions are not allowed in recursive common table expression" - but actually, they are?
I have table of structure data in SQL Server. I want to travese the tree and find all nodes with a recursive query. Additionally, the structure data is versioned. I want to always use the latest ...