47,430 questions
1
vote
2
answers
66
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
3
replies
47
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 ...
2
votes
1
answer
53
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
70
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
313
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 ...
0
votes
0
answers
60
views
Change MySQL RECURSIVE to JOIN Syntax [duplicate]
I'm struggling with some code I can't get my head around. It was handed off to me from a developer running MySQL v.8 and I'm working on a client's server running MySQL 5.5.
The code I'm working with ...
1
vote
2
answers
184
views
Is my recursive CTE failing because of formatting, text encoding or not defined table?
I was reading some stackoverflow question that I thought would be solvable with recursion. So I tried my hand at creating the simplest recursion problem I could envision as a steping stone: the sum of ...
3
votes
1
answer
122
views
Karatsuba Square Root implementation correctness
I'm currently trying to implement Karatsuba Sqrt for my BigInteger module in luau, though I'm having trouble with its accuracy and I don't know what I'm doing wrong.
Karatsuba function:
local function ...
0
votes
1
answer
131
views
Is it possible to fix a recursive Python function within a 12-character edit distance? [closed]
I have the following recursive Python function. The goal is to return the index of the first occurrence of it in the list. Is it possible to fix this code within a maximum of 12 edits?
def index_of(it,...
1
vote
1
answer
294
views
Stuck on Recursive State Design for a Zigzag Alternating-Sum Path in a Binary Tree
I’m trying to reason about a recursive algorithm on trees and I feel like I’m missing something subtle.
I have an immutable binary tree (not a BST) where each node has an int value. I want to compute ...
1
vote
1
answer
180
views
How to insert into a join table with a payload without causing an infinite loop?
I am getting what I believe is an infinite loop happening when I am trying to create view models from my model data, i.e. mapping them. The error I get is a 'stack overflow error'.
I believe the ...
2
votes
1
answer
107
views
How can I validate recursive Pydantic models where the validation rules depend on dynamic nesting depth?
I'm building a FastAPI application and modeling a forum-style comment system using Pydantic v2.
Each comment can contain replies, and those replies can contain more replies, recursively, similar to ...
4
votes
3
answers
198
views
Algorithm to recursively search a dictionary or list and return the path of each found element
I keep almost solving this.
I've got a data set of python dictionaries that contain both lists and dictionaries that also contain lists and dictionaries.
I want to find all instances of a substring in ...
3
votes
2
answers
174
views
Recursive C function for creating number permutations
I do understand I have mistakes in this code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int diziyi_yazdır(int dizi[], int dizi_uzunluğu)
{
for (int i ...
-2
votes
1
answer
203
views
Why does my Quick Sort implementation sometimes cause stack overflow on large arrays with duplicates? [closed]
I’m trying to implement an in-place Quick Sort in Python. I have two slightly different versions of my partitioning logic, and I’m confused because both seem correct on small arrays, but the second ...