34,107 questions
0
votes
0
answers
140
views
How to implement a list with an efficient "index of" operation? [closed]
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 ...
-3
votes
1
answer
133
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)
...
1
vote
1
answer
98
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 ...
1
vote
1
answer
150
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": {
"...
-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 ...
2
votes
2
answers
89
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
1
answer
34
views
Looking for a generic data structure being able to describe complex domain specific filters ( or standardized query language )
I'm searching for a very flexible data structure being able to describe what data to fetch from an API ( assuming I would own that API by creating a custom wrapper plugin ). The data itself is quite ...
4
votes
2
answers
399
views
Number of lexicographical swaps to make the array non decreasing
A lexicographical swap is defined as:
At each step, pick the earliest possible inversion (i, j) (smallest i, then smallest j > i with a[i] > a[j]) and swap them.
Repeat until the array is sorted....
2
votes
1
answer
201
views
Subset data structure with O(1) insert, find, and delete_greater_equal
An abstract data type maintains a subset of numbers {0,1,2,...,n-1}. The operations allowed on this are:
insert(i) - Insert element i in the subset if not already present.
find(i) - Return True iff ...
4
votes
2
answers
272
views
Answering Subarray H-index Queries Efficiently
I'm working on an interesting question about answering range h-index queries.
Fyi h-index is the max integer h that an author has published at least h papers that each are cited at least h times.
You ...
5
votes
1
answer
268
views
TypeCasting Math.pow(2,31) to int is not wrapping around as expected? [duplicate]
I was trying to check for wrap around property when the value is greater than the container that can hold it.
public class Main {
public static void main(String[] args) {
double value = ...
0
votes
0
answers
63
views
Database or data structure for fast exact counting
In databases such as PostgreSQL, doing exact counts like select count (*) from table where condition perform a full table scan.
PostgreSQL will need to scan either the entire table or the entirety
of ...
0
votes
0
answers
32
views
How to implement FIFO queue operations in DolphinDB similar to Python’s deque?
In Python, we can use collections.deque to implement FIFO queue operations. For example:
from collections import deque
queue = deque([1, 2, 3])
print("Initial queue:", queue) # ...
0
votes
0
answers
74
views
Non-bitwise move or `Move` trait? [duplicate]
In Rust, how can I define&manipulate objects that cannot be just copied bit-by-bit when they're moved?
For example, an object that contains a relative pointer (i.e. a pointer whose target is ...
0
votes
2
answers
264
views
RocksDB for efficient storage and retrieval of keys only (no values)
I have a use case requiring the reliable, durable storage, and efficient retrieval, of a large number of index entries (for which I've an application-specific serialization to bytes that preserves ...
0
votes
0
answers
84
views
How to construct an AVL tree from a set of keys: 10, 20, 5, 4, 3, 2, 30, 40?
I'm trying to understand how an AVL tree is built from a sequence of integer keys. The keys I have are:
10, 20, 5, 4, 3, 2, 30, 40
I want to construct the AVL tree step by step and see how rotations ...
1
vote
2
answers
183
views
Does the type information of an object also take up space in memory?
I'm trying to understand how type information is stored in memory.
We often say that an 8-bit value can store 2⁸ = 256 different values. But I'm wondering — when we create an object of that type, ...
0
votes
0
answers
119
views
Skip List with each column having an integer instead of copying objects
I tried my best implementing a Skip List in C++ in which I had a particular idea that I wanted to try out. Instead having every element in the base level be a column vector, I only only have a singly-...
2
votes
4
answers
185
views
How can I efficiently maintain median in a dynamic data stream with support for deletions?
I'm working on a problem where I need to maintain the median of a data stream, but unlike typical implementations that only support insertions, I also need to support deletions of arbitrary values.
...
-1
votes
1
answer
110
views
Kruskal's Algorithm Minimum Spanning Tree (Disjoint Set data structure)
I would like to generate a minimum spanning tree for the following graph:
I am using the disjoint set data structure and I am having trouble with the union (Union Rank) operation.
The edges get ...
1
vote
3
answers
113
views
Is this doubly linked list function implemented correctly?
I was watching a youtube video on doubly linked lists in C. One of the functions made for the doubly linked list was an "insert_after_node" function, which as the name suggests inserts a new ...
0
votes
0
answers
27
views
Constrained Character List Type
Are there any commonly used implementations of a restricted string (or string-like) type that sets constraints on the range of characters allowed at different positions?
A simple example would be US ...
0
votes
2
answers
92
views
Can a red-black tree initialized by a list just make all its nodes Black?
If I have a list of values to insert into a new red-black tree, I could do an empty-tree initialization then do individual inserts. I wonder if I can take the list, sort it, then manually build the ...
1
vote
1
answer
197
views
How can I store ids in Python without paying the 28-byte-per-int price?
My Python code stores millions of ids in various data structures, in order to implement a classic algorithm. The run time is good, but the memory usage is awful.
These ids are ints. I assume that ...
2
votes
1
answer
103
views
shared red black tree among processes
I want to create a red-black tree that it is shared among different forked processes.
Linking to an old question of mine old_question there cannot be resizable data structures in the shared memory (...