548 questions
-1
votes
1
answer
107
views
How to check binary tree symmetry iteratively to avoid stack overflow with deep trees in Python [closed]
I have a working recursive solution to check if a binary tree is symmetric. The code works correctly for my test cases, but I'm concerned about potential stack overflow with deep trees since Python ...
1
vote
1
answer
48
views
Why eta-reduced of genericShow-based show definition overflows stack for recursive types
Consider the following recursive data type:
data Chain a = End | Link a (Chain a)
By deriving a Generic instance for this recursive type, show can be defined in terms of genericShow:
derive instance ...
0
votes
0
answers
52
views
Finding subclusters of a specific cluster
I performed HDBSCAN Clustering
hdbscan_clusterer = hdbscan.HDBSCAN(min_cluster_size=200)
df['Cluster'] = hdbscan_clusterer.fit_predict(data_matrix_for_clustering)
Now, I’m interested in getting the ...
-1
votes
2
answers
83
views
recursive get a list of the stream down dependencies in python
i am trying to get a flatted list of dependencies.
list_of_task_to_generate = [
{"version": "1", "dependency": []},
{"version": "2", "...
0
votes
1
answer
167
views
Proper way of parsing recursive enum with Nom
I want to parse recursive enum representing arithmetic expressions using Nom. I have the following code.
#[derive(Debug, PartialEq, Eq)]
enum ArithExp {
Const(i32),
Add(Rc<ArithExp>, Rc&...
1
vote
0
answers
22
views
Mongoose Nestjs, implement recursive subdocument array
I have the following type:
export type TreeViewBaseItem = {
id: string;
label: string;
editable:boolean;
children?: TreeViewBaseItem[];
files: TreeFile[];
};
and I did my best to ...
-1
votes
1
answer
69
views
DSA swap node pair leetcode problem error
public ListNode swapPairs(ListNode node) {
ListNode head = node;
ListNode cur = node;
while (head != null && head.next != null) {
head = reverseList(head, 0);
head....
1
vote
2
answers
511
views
How does heapify maintain max-heap property when both children are larger than the root and their children are also greater than their parents?
I am currently learning about heap sort and I am having trouble understanding the heapify process, particularly when both children of the root are larger than the root itself, and the sub-children (...
0
votes
2
answers
72
views
How to Optimize a Deeply Nested Object Search for Performance?
I have a deeply nested JavaScript object structure representing a hierarchical data model. The object can have multiple levels of nested children, and I need to search for a specific value within this ...
1
vote
1
answer
299
views
Can someone determine time complexity of this LeetCode solution I made?
I wrote a solution to the problem linked below but I'm not sure about its time complexity. I was thinking it was quadratic but it passed within 0 ms when I submitted, so it might be linear idk. I ...
2
votes
0
answers
94
views
Graph algorithm representation: Breadth-first search data structure [closed]
I'm completing the datastructures and algorithms preparatory course for a masters in data science.
Here, is a breadth-first search algorithm for a graph I wrote based on the pseudocode provided in the ...
1
vote
1
answer
94
views
R Tidyverse recursive function path creation issue
In the context of the bill of materials, I have a tree structure and I want to perform a recursive function to find the different paths of this tree.
I did, however, a mistake when trying to define a ...
0
votes
2
answers
71
views
How can I prevent the stack overflow error?
I am working on a Java project to involving quadtrees.
In this representation of the quadtree, the node with intensity -1 has 4 children and the node with any other intensity does not have children. I ...
1
vote
1
answer
52
views
Wrong output when checking whether binary tree is balanced
I am trying to solve LeetCode problem 110. Balanced Binary Tree:
Given a binary tree, determine if it is height-balanced.
Here is my attempt:
class Solution {
boolean c = true;
public ...
2
votes
1
answer
96
views
Detecting shared structure in tree made of cons cells
I'm writing a programming language (details irrelevant) which uses Lisp-like cons cells to store its data (this makes implementing the garbage collector easy). I'll spare you the details of everything ...
0
votes
1
answer
89
views
How recursion works in case of permutations after the base case reached
When the base case is reached then for next combination call we re-swap how it is taking in to account the not visited or considered cases.
For example
function dfs(i, nums, slate) {
if (i === ...
0
votes
0
answers
99
views
F# recursive bind with "and" gives "null", doesn't work
This is a brief example from the book, by Tomas Petricek, "Functional programming in the real world", chapter 8.
type QueryInfo =
{ Title: string
Check: Client -> bool
...
-2
votes
1
answer
96
views
Is there a way to fix this code or should I ask to change the data structure?
I'm loosing my mind with this (because I'm not a very logic person).
RUST Playground
I cannot change the data part.
The string returned from the below code is A = 1 AND (B = 2 OR C = 3 OR D = 4 OR ) ...
0
votes
1
answer
74
views
instance of parent Class not accessible from subclass? "does not exist in current context"
So I'm fairly new to all this. I've got the beginnings of a simple Octree implementation for a Unity project. This consists of an Octree parent class, an instance of it, and a OctreeNode subclass
I'm ...
0
votes
1
answer
330
views
Some confusion regarding the Binary tree Property about the Number of external nodes = Number of Internal Node + 1
Everybody would agree that this one, shown below, is a valid Binary tree.
* (R)
\
\
* (C)
The above binary tree node marked R, is the root and the node marked C is the child.
This is not a Full ...
0
votes
1
answer
33
views
Implementing a recursive function to execute layered calculations
Apologies for the butchered title.
I have a db of metrics where I have fields like Metric Title, Metric ID, Metric Abbreviation, and Metric Formula. The Metric Formula indicates if the metric requires ...
1
vote
1
answer
347
views
Finding time complexity of T(n) = 2T(n/2) + Logn
T(n) = 2T(n/2) + Logn
This is the given time complexity and I am using recursive tree method to find it's time complexity.
For the first call it is doing : Log(n) work
For second it is doing: Log(n/2) ...
0
votes
3
answers
121
views
Appending two lists mutually to each other gives unexpected results containing "[...]"
I have 2 lists:
a = [1, 2, 3, 4, 5]
b = [9, 8, 7]
I performed the following two operations and tried printing each list
a.append(b)
b.append(a)
print(a) # Expected Result: [1, 2, 3, 4, 5, [9, 8, 7]]
...
0
votes
1
answer
86
views
finding cycles in directed graph using algorithm design manual
so, i am following algorithm design but the below algorithm implemented from the book, fails in the following e.g., is there an issue with this algo -
bool directed = true;
bool dfs(...
0
votes
1
answer
96
views
boost spirit x3 variant Recursive assignment problem
In special scenarios
I have this data structure
namespace x3 = boost::spirit::x3;
struct one;
struct two : x3::variant<x3::forward_ast<one>,int>{
using base_type::base_type;
using ...
1
vote
1
answer
35
views
Python recursive function to generate a specific type of sequence from a specific type of dictionary
I need to write an algorithm where I have a python dictionary like {1: [2, 6], 2: [3], 6: [5], 3: [4], 5: [8, 9], 4: [5, 7]} and generate the sequence like [[1, 2, 3, 4, 5,8],[1, 2, 3, 4, 5,9], [1,2,...
0
votes
1
answer
314
views
Leetcode question: Flatten binary tree into linkedlist
I am trying to solve this problem on leetcode: https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ (Flatten binary tree into linkedlist)
This is my code:
class Solution{
...
0
votes
1
answer
290
views
I can't pinpoint why memory gets corrupted while working with Recursive Tagged Union in Zig
I am working on a small feature-incomplete Lisp interpreter to learn a bit of Zig. My inspiration is this https://norvig.com/lispy.html, this might not be the most idiomatic way of implementing that ...
0
votes
0
answers
43
views
DSA Binary Search Tree - Insert function not working fully
I'm working through binary search trees in The Odin Project (TOP)(https://www.theodinproject.com/lessons/javascript-binary-search-trees) and I'm having trouble with the insert function.
I believe the ...
3
votes
1
answer
683
views
Interface the BTreeMap and HashMap in Rust
I am implementing a tree data structure. My idea to do this is to have a struct Tree that have children:SomeMapType<Tree> field to keep track of its children nodes, where SomeMapType may be ...
-2
votes
1
answer
62
views
How return works in recursion call in python?
I've written a python function to reverse a list, here are the two functions and their respective outputs.
Function 1
a=[1,5]
def rev(k,i):
if i==len(k)-1:
print("in base case {}&...
0
votes
1
answer
71
views
How to save previous "output" or a state of the previous output in a recursive function call in python?
I am using a recursive function to generate text using a RegEx match, where it finds a pattern of words according to a combination of synonyms inside square brackets (pattern = '\[.*?\]') separated by ...
2
votes
1
answer
460
views
having problems inserting words on a patricia/radix tree
i am trying to make a code for a college aplication of a patricia/radix tree that inserts words read from each line in a txt file in the tree, so if i read a file that says
roman
romance
romantic
its ...
1
vote
1
answer
156
views
Mapping recursively from a dataframe to python dictionary
I am struggling to find a recursive mapping to get the end result. Here is the input df
## mapping recursive
import pandas as pd
data = {
"group1": ["A", "A", "B&...
0
votes
1
answer
515
views
Question about Time Complexity analysis of Merge Sort
I'm a student starting to learn about Computer Science, specifically Data Structures and Algorithm.
Been struggling in understanding the Time Complexity of Merge Sort Algorithm, specifically deriving ...
-1
votes
1
answer
115
views
Merge Two Sorted List Leetcode Question 21
So I keep getting a maximum recursion error on line 22, for this test case
list1 is 1,2,4
list2 is 1,3,4
Output is 1,1,2,3,4,4
can someone explain what is causing this infinite loop to occur, python ...
1
vote
1
answer
461
views
How to implement fmt::Display on a recursive data structure in Rust
I tried to provide an implementation of the Display trait on the recursive data structure Tree as defined below.
#[derive(Debug)]
struct Tree <'a> {
node: (&'a str, Vec<Tree<'a>&...
1
vote
1
answer
98
views
Spring Boot : Infinite recursion
I have the following entities in my Spring boot Hibernate project.
Entities
Task - represents the task / job details
Agent - represents the agents available to work on the tasks
TaskAgent - stores ...
0
votes
0
answers
32
views
R Recursive Function and map() for Bill Data Structure
Using R tibbles, I have a df as shown below. It's a BOM data structure.
df <- data.frame(
product_id= c("P1", "P1", "P1", "P1", "P1", "...
1
vote
2
answers
70
views
How do I make this function automatic, it clearly has a pattern
def populate_kids(self, arr, used_Indices):
for a in self.children:
a.get_all_jumps(arr, used_Indices)
for a in self.children:
for b in a.children:
b.get_all_jumps(...
1
vote
1
answer
89
views
Recursive function to restructure array that inside an object
I'm currently working on displaying tables.
But im stuck because the data structure is super nested. This is the original structure:
{
"key": "parent_table",
"...
1
vote
2
answers
100
views
Recursive function to restructure an array of object
I'm currently working on displaying item.
But im stuck because the data structure is super nested.
This is the original structure:
[
{
"key": "name",
"value": &...
0
votes
1
answer
292
views
Inserting a node in a complete binary tree with python
How to insert a node in a complete binary tree without using queue DS? I tried the following code:
class TreeNode:
def __init__(self, value=None) -> None:
self.left = None
self....
1
vote
1
answer
96
views
Is there a way to sort the values of a DataStructure (Key/Value pairs) by first extracting the values (int) to an array, and performing a MergeSort?
I want to simulate an interview scheduler, where the names with the highest scores are called first. It is my priority to make sure I apply the mergeSort algorithm somehow to this implementation.
What ...
0
votes
0
answers
59
views
solution for jump game problem is not running properly
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can ...
0
votes
1
answer
244
views
How to create self-referential AST in Rust?
Let's imagine we have a very simple AST for programming language with only functions and calls
use std::sync::Arc;
struct Function {
pub body: Vec<Call>
}
struct Call {
pub function: ...
1
vote
0
answers
186
views
How do I create an iterator over a recursive data structure in Crystal?
I have a tree structure and currently I am trying to return an iterator that iterates over the elements of the datastructure so that my function can accept a block.
I have currently reduced my code to ...
-1
votes
1
answer
87
views
Inconsistent output in Recursion?
I was solving a question today on Leetcode named Lexicographically Smallest Equivalent String (link) and I came up with a solution of DFS with some customization to solve the problem and here's is my ...
3
votes
2
answers
92
views
Recursive CTE Query to make groups without duplicates
I need to build a sql query to find the least expensive squad (salary-wise) for teams in a European volleyball league.
For each team, the squad consists of 6 players. The entire team has 10 players (...
0
votes
2
answers
301
views
Spy Number using Recursion
def spynum (n,r,sm=0,pd=1):
#s = 0
#p = 1
#b = False
if n == 0:
print (sm==pd)
return sm == pd
else:
rem = n % 10
sm += rem
pd *= rem
print (sm,pd,rem)
spynum(n//10,rem,...