34,110 questions
0
votes
0
answers
111
views
Why does if (x) x->parent = y; execute when deleting a node in Red-Black Tree? [closed]
I am implementing Red-Black Tree deletion (CLRS-style).
I understand the general delete logic, but I am confused about this specific line:
if (y->parent == z) {
if (x) x->parent = y;
}
...
1
vote
1
answer
85
views
How to integrate Dijkstra’s algorithm into a class-based weighted graph in Python?
I am working on a real-world navigation problem where a city road network is represented as a weighted graph (distances in kilometers).
The goal is to compute the shortest path from North Nazimabad to ...
-4
votes
1
answer
94
views
Which shortest path algorithm should I use for a weighted city road network in Python? [closed]
I am working on a real-world navigation problem where a city road network is represented as a weighted graph (distances in kilometers).
The task is to compute the shortest path from North Nazimabad (...
-2
votes
0
answers
124
views
Is it faster to calculate integer exponentiation with binary or ternary chunks? [duplicate]
Code 1
In code one we are using the binary exponentiation.
public class Solution {
public int pow(int A, int B, int C) {
if (C == 1) return 0;
long base = (A % C + C) % C;
...
3
votes
1
answer
143
views
Getting the same result -> hot potato game in C using Deque
I’m currently learning about data structures and algorithms (DSA) by reading the book “Learning JavaScript Data Structures and Algorithms – 2nd Edition” by Loiane Groner. I am implementing the DSAs in ...
2
votes
1
answer
113
views
Confused about implementing degree() and incident_edges() for topological sort in Python
I am a student studying graph algorithms and learning topological sorting of a Directed Acyclic Graph (DAG).
The topological_sort function below is provided in our textbook, and I am not allowed to ...
Advice
1
vote
4
replies
178
views
Best resources to learn Data Structures, Algorithms, and Big-O from scratch (for Python)
I want to learn Data Structures, Algorithms, and Big-O notation from scratch, but there are too many resources online and it’s difficult to determine which ones are trustworthy or widely used by ...
-2
votes
1
answer
78
views
"TypeError: <class> is not reversible" -- what does it mean?
Something called reversed() on an instance of a class of mine, which resulted in the error
TypeError: 'HBox' object is not reversible
What does it mean for an object to be reversible?
-4
votes
0
answers
45
views
Reverse an Array by recursion using swap in python [duplicate]
so I was trying to reverse an array by recursion so the code logic is we are swaping right most end value to the left most end. I have implemented logic but the thing is My recursion function retuns ...
1
vote
1
answer
80
views
During red–black tree insertion fix-up, when (if ever) does the black-height of nodes change?
I’m studying red–black trees (CLRS style) and I’m confused about how black-height behaves during RB-INSERT-FIXUP.
I quote here that procedure from CLRS:
RB-INSERT-FIXUP(T, z)
while z.p.color == ...
0
votes
1
answer
102
views
How can I efficiently map and update frequencies of nested items using dictionaries in Python?
I'm working on a small DSA practice problem involving frequency counting, but with a twist.
I have a list of tuples where each tuple represents a (category, item). Example:
data = [
("fruit&...
Advice
0
votes
1
replies
43
views
Name for this data structure
I'm trying to model a generic "capability" or "permission" structure. The part I'm having trouble with is finding the name of the specific data structure. It's not a formal tree, ...
1
vote
1
answer
221
views
How to implement a list with an efficient "index of" operation?
I'm interesting in possible implementation approaches for a quite special variant of a list, with the following requirements:
Efficient inverse lookup ("index of"): "give me an index ...
0
votes
2
answers
167
views
MRU structure with fixed number of elements, automatically adapting to LINQ queries
I have a folder containing huge numbers of files in many subfolders, and I want to select the files with a name that matches any of a specified list of patterns (regular expressions). My regular ...
-3
votes
1
answer
196
views
Monotonic Stack Algorithm: Is the Average Time Complexity θ(n) or O(n)? [closed]
The algorithm I've written for an assignment is closely related to this monotonic stack approach
https://www.geeksforgeeks.org/dsa/next-greater-element/
Best case:
n pushes → Time complexity: O(n)
...