# Questions tagged [data-structures]

11659 questions

1

votes

0

answer

265

Views

### Priority Queue that uses a comparator and has decrease key operation

So I have a problem where I have a set of objects with two fields. I need to be able to get the min object of the set at a fast time time (using a custom comparator). The problem is, when I get the min object set, it changes the fields of some objects in my original set. Thus, the ordering of the se...

1

votes

0

answer

145

Views

### Both methods have same erasure, yet overrides the other

I'm trying to implement a Queue but my method 'enqueue(E e)' is giving me an error saying that the method clashes with the method in the Queue interface but neither override the other. What is going on?
Here is the Queue Interface
public interface Queue {
/**
* Returns the number of elements in the...

1

votes

1

answer

1.8k

Views

### HashSets and HashTables in Python

Is there any HashSet implementation in Python? I know HashTable can be represented using dictionaries, but how do we represent HashSet implementation.
I am NOT looking for a data structure with the same methods as HashSets but rather someone with a CONSTANT lookup time, or the order of O(1);
Also,...

1

votes

2

answer

83

Views

### How to dynamically insert strings in my linked list?

My C program should read an input file and save it line for line in a linked list, then printing it. But when it's inserting the next line in the list, all elements in the list become the new element.
Input:
abc
def
ghi
Output:
ghi
ghi
ghi
I'm not sure but my guess is that it's not correctly a...

1

votes

1

answer

18

Views

### Designing data structure which can decrease range in lgn

I was asked in an exercise to design a data structure which can handle the following methods in logarithmic time complexity (lgn):
Insert(x): Inserts x to the data structure
Find(x): Finds if x exists in the data structre
Decrease(x, y): Adds negative value y (y

1

votes

0

answer

35

Views

### AVL tree insert case need a clarify

I read several online document about implementing AVL tree using balance factor(Not using a height data field in Node structure), when insert into the tree, there is one case I could not figure out.
The document is from here(also from here has similar function) , the balance factor is defined as hei...

1

votes

0

answer

43

Views

### How to calculate set intersection of items between large number of users in a NoSQL database?

I am facing an efficiency problem trying to calculate set intersection of items between different users. Let's say that a user, called Bob, owns different items he would like to trade with other items other users own. Bob has an inventory and a wishlist. Now if Bob wants to obtain an item, say item...

1

votes

0

answer

51

Views

### Finding subsets of a set of points that are all a maximum distance from each other?

I have a csv file with the following format:
thing1_id, thing2_id, similarity
The similarity is between 50 and 100. I've filtered out all pairs with similarity less than 50, but I do have the full set where the lowest is around 25. There are duplicate comparisons at the moment, i.e. thing1-thing2 is...

1

votes

0

answer

85

Views

### I am getting a Bus Error 10 while implementing a Queue

Can Someone tell me why am I facing a Bus Error 10 in the following code.
The code below implements a Queue using circular linked list.
I am inserting 3 and 5 into the list and later remove thrice from front. I have handled corner cases too.
Thanks,
Priyam Dhanuka
#include
using namespace std;
clas...

1

votes

0

answer

235

Views

### Is there a hash tree designed for complex data structures?

I have a JSON object with private data. It has the following (complex!) structure:
{
name: 'JB',
age: 35,
children:
[ {
name: 'Alice',
age: '5',
favColor: 'pink'
},
{
name: 'Bob',
age: '8',
favColor: 'blue'
},
{
name: 'Charlie',
age: '9',
favColor: 'green'
},
]
}
I want to create a hash tree tha...

1

votes

1

answer

76

Views

### how to get values as per mixed attribute column set for products in sql

I have been struggling to get the desired output from the mysql db. First Please take a look at my table structure
EDIT: HERE IS MY SCHEMA
http://rextester.com/edit/NNCZ7986
Now when i run the below mentioned query, i get the results as below
Select a.prodid,a.product,b.catid,b.category,d.attvalue,...

1

votes

0

answer

37

Views

### Can Merkle tree tell if more than one copy of the object exist in it?

With Merkle root hash, and Merkle path, one can verify if a given object (i.e a transaction) exist in a Merkle tree. But is it possible to tell there is no other duplication of the object in the tree.
For example, if I have the Merkle root of a list of transactions and the Merkle path of one transac...

0

votes

1

answer

28

Views

### Manipulating pointer to array of pointers

Trying to write a C snippet to store and retrieve an array of structure pointers. I have copied my snippet bellow.
What I am trying to do here-
method Xos_get_cb_info_from_handle() should return the pointer to
the base address of the structure localclient.exit_cb. Which seem to
work.
After getting t...

1

votes

1

answer

224

Views

### Circle Packing in R - Data structure

I try to replicate this circle packing example in R: Visualizing hierarchical data with circle packing in ggplot2? on my own data, but I bumped into a problem that I could not comprehend.
The data is:
Religion

1

votes

2

answer

75

Views

### Create Class of Lists in Python

I have to extract patient information from a bunch of XML files for further data analysis.
I have multiple Patients that can have multiple Diseases . For each Diseases there may or may not have been a Treatment or several. Each Treatment may or may not have TreatmentDetails. The TreatmentDetails are...

1

votes

1

answer

38

Views

### How to get links from website, not seen in view source

I am still beginner, I searched in Google but I didnt found what I want,
I have a website http://www.example.com/index.php
On the main page, there is selectio form:
e.g. one selects first country in first field, the the city in the second field then click the button to show the data.
I didnt find th...

1

votes

1

answer

102

Views

### Choose the right data structure for my algorithm in java

Today i need to choose the most efficent data structure for my needs in java.
Basically i have an algorithm that have a set of .
First multiple thread create some of this set, than they get merged,
sorted by the Integer and removed eventual duplicate Object in the
result set.
Than for each element...

1

votes

0

answer

39

Views

### How to organise components of a no framework project?

SHORT VERION: Where is the common place to store the controllers for dependencies in PHP?
LONG VERSION: I need to create a project at a high quality, coming from a framework background my knowledge on directory structure is a bit rusty and I would like some help.
Current Directory Structure: https:/...

1

votes

1

answer

41

Views

### Why would I need stacks and queues for Depth First Search?

I'm working on a project from the Berkeley AI curriculum, and they require me to use stacks, queues, and priority queues in my Depth First Graph Search implementation. I stored my fringe in a priority queue and my already visited states in a set. What am I supposed to use stacks and queues for in th...

1

votes

1

answer

27

Views

### If a string is used as a key in a hashtable , how does it provide O(1) time access to the contents corresponding to that key?

Since we need to traverse the string itself , how can a hashtable provide O(1) access ?

1

votes

1

answer

482

Views

### How to structure Shopify data into a Firestore collection that can be queried efficiently

The Background
In an attempt to build some back-end services for my e-commerce (Shopify based) site I have set up a Firestore trigger that writes order details with every new order created which is updated by a web hook POST function provided by Shopify - (orders/Create webhook).
My current cloud fu...

1

votes

0

answer

37

Views

### Is it possible to use recursion on a Stack to obtain the same functionality of a Dictionary

I'm working on a programming assignment which requires measuring the nested depth of HTML tags. This is an easy task for a dictionary however we are meant to be using Stacks and ArrayLists for learning purposes. I'm wondering if it would be possible to implement a stack with the same functionality o...

1

votes

1

answer

82

Views

### Swap Nodes in Pairs

I am currently brushing up and reviewing my datastructures as I prepare for job interviews. I am currently working on this problem where I have to swap every 2 nodes in a Linked List. My code is as follows:
public ListNode swapPairs(ListNode head) {
ListNode dummy = new ListNode(0);
dummy.next =...

1

votes

2

answer

88

Views

### String class istream issues

I am having trouble getting my string class working. My istream function seems to read the data in, and I confirmed that the += was adding the characters, but after the first character, what is added is garbage. I have tried everything I can think of to get it working. Can someone please provide...

1

votes

2

answer

52

Views

### Linked List - How a single object is storing so many addresses one after other?

I learn about data structures and Linked Lists and I don't understand something. How can a single object store so many addresses and datas. When I learned about object I saw that you need to create new objects if you want to store many datas for a single variable, but now at Linked List, the newNode...

1

votes

0

answer

51

Views

### How can I distribute databases across servers as evenly as possible while minimizing the movements required?

The Problem:
I'm attempting to create a program to redistribute ~1200 databases of various sizes across a finite number of servers to create as even a distribution as possible. The databases are currently on those servers, but the distribution is uneven.
I have looked at quite a few articles and...

1

votes

1

answer

88

Views

### Storing mesh data values

I am creating meshes based off of a CSV files in the format 'x,y,z,dataValue'. Based on the data value, I am coloring the vertex. For example, for data value 10-20, it will be a dark green, and for 20-30 a lighter green, etc... I have this working, but I would like to be able to create an analysis t...

1

votes

0

answer

223

Views

### How to maintain a LRU cache using LinkedHashMap with limited total size?

How to maintain a cache with limited total size?
Let's say the limited size is 10MB, you've already used 10MB(10 * 1 MB file), now you want to add a new file with size 5MB. You need to evict the 5 least used files, but by overriding removeEldestEntry method of LinkedHashMap with 'totalSize() > limi...

1

votes

0

answer

29

Views

### Storing billions of unsigned ints for lookup

I need to store billions of unsigned 64 bit ints in a data structure that supports lookup of these ints. Currently the solution is to use a bloomfilter which generally works, and gives me a probability that a given int is in the stored set. This is working fine for now, however given the error rate...

1

votes

1

answer

409

Views

### delete arbitrary item from heap in python

Is there a binary heap implementation where I can pop other elements than the root in log n time?
I use heapq - but heap.index( wKeys ) in
heap.pop( heap.index( wKeys ) )
is very slow. I need a binary heap for my problem - where I sometime use
heapq.heappop(heap)
but also need to pop other elements...

1

votes

1

answer

61

Views

### How is it possible to have 0 bits per character?

I have an example of a string ABABABAB and I have to calculate an entropy of this string.
It's obvious that i can get different numbers when taking different alphabets. When I took alphabet A={a,b} I got an answer for entropy = 1 bit per character(Using Shannon's formula) => means 8 bits for a whol...

1

votes

0

answer

54

Views

### Populating a vector of objects within a class

and I've hit my first wall on my coding project/assignment.
I'm to implement functionality into code that's been done to some stage, and I cannot alter the given code so I have to work around the given structure.
The code, in a nutshell, reads family relations from a text file and populates databa...

1

votes

0

answer

80

Views

### indexedDb , Storing/updating Objects with set interval to use in web workers.-(memory leak)

Question: How come the code represented below creates a memory leak
Note: My objective is to store updated objects every frame so i can sync these
objects with web workers.
Disclaimer: I am using set interval with it on purpose and if I had any other way of transfering this amount of objects over...

1

votes

0

answer

25

Views

### I am trying to solve this Big theta notations example:

I am trying to solve big theta notation for (n^2+5)^10 is this true for g(n)=n^20. for all n>=1 and so on it true but in all cases it is true?

1

votes

2

answer

37

Views

### What's the behind logic of “stack” (data structure)? [closed]

We all know 'stack' is a data structure that is first in last out.
But what's the behind logic of stack.
We can see application of stack in 'Reverse Polish notation', procedure calls, make recursion not recursive.
How do people think out of such data structure, what's the intuition behind this data...

1

votes

0

answer

63

Views

### pointer increment to array of pointers

can a pointer to an array of pointers which itself points to an array be incremented by post incremented by operator (p++),if yes ,why?And i know that array and pointer are synonym to the first address,so they cannot be treated like variable and assigned a value but a pointer to an array pointers ca...

1

votes

1

answer

110

Views

### delete subtree from bst and balance the tree in logn time

Is it possible that we could perform m insert and delete operations on a balanced binary search tree such that delete operation deletes a node and the whole subtree below it and after that balance it? The whole process being in done in amortized O(log n) time per step?

1

votes

2

answer

62

Views

### Contain method in a Stack Implementation in swift

Here is a stack implementation I found on the web
public struct Stack {
fileprivate var array = [T]()
public var isEmpty: Bool {
return array.isEmpty
}
public var count: Int {
return array.count
}
public mutating func push(_ element: T) {
array.append(element)
}
public mutating func pop() -> T? {
re...

1

votes

0

answer

87

Views

### Fastest way to Dynamic Query on 2 million in memory rows

I have 2 million rows of data in memory and I want to apply dynamic groupby and dynamic where(Dynamic filter) clause. I need records in max 10 seconds. I have tried so for:
Dynamic Linq, it is working fine but returning result in more than 60 seconds and it is not acceptable.
I have used datatable a...

1

votes

0

answer

91

Views

### store hash-map in static array

This question is language agnostic. But let's use C and some pseudo code for demonstration.
I want to store a hash-map / hash-table / dictionary / key-value store inside a static array (or optionally multiple static arrays), i.e. I have some upper limit about the number of entries, and have this dat...