34,108 questions
1 vote
1 answer
38 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
95 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
39 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, ...
0 votes
1 answer
206 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
153 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
165 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) ...
Advice
1 vote
1 replies
38 views
Why do B-tree disk optimizations work when the OS controls physical disk layout?
I understand the standard explanation for why B-trees are used in databases: they minimize disk seeks by packing many keys into each node, keeping the tree shallow (3-4 levels), and enabling efficient ...
1 vote
1 answer
106 views
Sometimes wrong output in Java queue simulation
Problem summary: Each person in line has tickets[i] tickets to buy. Every second The person at the front buys one ticket. If they still need more tickets, they move to the end of the queue. We need ...
-2 votes
1 answer
36 views
Maximize Score based Prime Score Algorithm
Consider the following LeetCode problem: You are given an array nums of n positive integers and an integer k. Initially, you start with a score of 1. You have to maximize your score by applying the ...
1 vote
1 answer
157 views
How can I update values in a nested JSON file using Python? [closed]
I have a JSON file with nested objects, and I want to update specific values inside it using Python. The structure can vary, but it usually looks something like this: { "user": { "...
-4 votes
1 answer
62 views
How to precompute nested date ranges efficiently to optimize range filtering and pagination? [closed]
📝 Body I have a Mongo collection CollectionA where each top-level object contains a nested array of meetings now each meetings have start and end times, for example: CollectionA = [ { &...
-1 votes
1 answer
133 views
How can I merge two lists in Python while removing duplicates but preserving the original order? [duplicate]
I have two lists in Python: list1 = [1, 2, 3, 4] list2 = [3, 4, 5, 6] I want to merge them into a single list such that: No duplicates remain The original order of elements is preserved For the ...
1 vote
1 answer
53 views
Is circular linked list needed for "Circular" queue?/
I am learning about queue data structure in python. I learnt the implementation of a queue using list in python and the issue of memory wastage when we dequeue a few elements from the front. We use a ...
2 votes
2 answers
95 views
Mutual Friends using Graph Data Structure
I’m trying to implement a mutual friends feature using a graph data structure represented as an adjacency list in Python. Each node represents a person, and each edge represents a friendship (an ...
1 vote
2 answers
101 views
Is there a bug in the method below (Data Structures & Algorithms by Robert Lafore)
The method below has been taken from the book Data Structures & Algorithms by Robert Lafore. This method is used to bubble sort a given array. nElems is the number of elements in the array. In my ...