Questions tagged [data-structures]
A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.
data-structures
34,000
questions
1
vote
1
answer
11
views
Finding the subsequence with the least median given a size K and an array of length N
I have been struggling the past month with this problem that was given to us on our course while I was upsolving it. The task is to find the window of size K with the least median in an array of ...
1
vote
0
answers
43
views
How can I have a better implementation of an unknown tree I wrote myself?
I am converting a X509 certificate management code from C++ to C, but C lacks many features that C++ has. So I wrote a data structure myself. Is there a similar data structure implemented in the ...
0
votes
1
answer
38
views
Design a Data Structure for Efficient Key-Value Operations with Top K Check in c++
Data Structure Requirements
Design a data structure that supports the following operations:
Insertion: Insert a key-value pair.
Deletion: Delete a key-value pair.
Check Top K: Given an integer k and ...
0
votes
1
answer
73
views
Mergesort for singly-linked lists gives correct results but leaks memory
I'm working on an assignment to implement mergesort for singly-linked lists in C++. The merge function needs to merge two sorted lists in-place without creating new nodes. The mergesort function ...
0
votes
3
answers
100
views
Unordered map not updating
I was cloning a graph (deep copy) and the only problem in my code is in the BFS() function inside the if statement, when I'm updating the visited hashmap, it's not updating.
Node* cloneGraph(Node* ...
-1
votes
0
answers
29
views
How to remember DSA concepts [closed]
I have started DSA last month and when I revisit those questions now I get completely blank. Even the easiest sorting algorithms seems as if I'm doing them for the first time.
A strategy to remember ...
1
vote
1
answer
51
views
Where to store display data in a C Project
I am writing a C-Program for an Esp32, to display some Images on a 8x32 LED-Matrix.
I struggle to store the Image Data in a way, that different .cpp files have access to it, but it won't lead to ...
-1
votes
1
answer
19
views
Minimum numbers of operation required to make an array bitonic with steep descend and steep ascend and palindrome
I am trying to solve this code challenge:
Given an array arr of n integers, in a single operation, one can reduce any element of the array by 1. Find the minimum number of operations required to make ...
0
votes
1
answer
51
views
Time Complexity for finding k smallest elements in an array of size n
I came across 3 approaches for the problem.
Sort the array and find the k elements O(nlog(n))
Using minHeap, heapify in O(n) time and extract k elements O(klog(n)); total = O(n + klog(n))
Using ...
0
votes
0
answers
35
views
Finding Top Users with Common Records in a Growing Dataset
I’m working on a project where I have a large dataset containing billions of records. Each user can have one or more records, and each record can be associated with multiple users.
Given a specific ...
0
votes
1
answer
77
views
Best data structure for storing 2048 minecraft ItemTags? [closed]
Context, I'm working on a Minecraft mod (1.21, so Java 21), the purpose of which is to:
Use the max_stack_size data component to drive the apparent default max-stack-size of items in an straight-...
0
votes
3
answers
87
views
Why using else if instead of if here when building a binary tree?
When building the insertion function in binary tree, I use two if statement to track the node( if the value is smaller than the current node,go left;if bigger,go right) .
I know the difference between ...
3
votes
0
answers
197
views
Finding repeating sequences with less than O(n^2) time complexity
Is it possible to find repeating sequences of any length (without complete overlaps) with an average time complexity less than O(n^2) ?
For example, take a string like this:
0 1 2 ...
-1
votes
1
answer
33
views
Linked Lists: AttributeError: 'int' object has no attribute 'next' [duplicate]
class ListNode:
def __init__(self, val=0, next=None) -> None:
self.val = val
self.next = next
def list_link(nums):
dummy = ListNode()
curr = dummy
for i in ...
0
votes
1
answer
66
views
Constructing Linked List in Rust from head to tail without unwrap
It is said that unwrap is unsafe and it should be avoided if possible.
While I was constructing a linked list, I found an unwrap inevitable.
My question is, is it possible to remove this unwrap or is ...