data-structures

How to implement three stacks using a single array.

Hi, I came across this problem in an interview website. The problem asks for efficiently implement three stacks in a single array, such that no stack overflows until there is no space left in the entire array space. For implementing 2 stacks in an array, it's pretty obvious: 1st stack grows from LEFT to RIGHT, and 2nd stack grows fro...

What are the fastest-performing options for a read-only, unordered collection of unique strings?

Disclaimer: I realize the totally obvious answer to this question is HashSet<string>. It is absurdly fast, it is unordered, and its values are unique. But I'm just wondering, because HashSet<T> is a mutable class, so it has Add, Remove, etc.; and so I am not sure if the underlying data structure that makes these operations possible make...

Python what's the data structure for triple data

I've got a set of data that has three attributes, say A, B, and C, where A is kind of the index (i.e., A is used to look up the other two attributes.) What would be the best data structure for such data? I used two dictionaries, with A as the index of each. However, there's key errors when the query to the data doesn't match any insta...

How is vector implemented in C++

I am thinking of how I can implement std::vector from the ground up. How does it resize the vector? realloc only seems to work for plain old stucts, or am I wrong? ...

Defining your own Ord for a data type (Haskell)

I am attempting to make some data structures to solve a graph puzzle. I am trying to define an edge's comparison criteria, but I am not sure how. So far: data Edge = Edge (Set String) Bool How do I tell let the compiler know that I want edges to be declared equal if they have identical sets of strings, and not have equality have anyth...

about Randomized-select algorithm

Hi I have this array A = <3,2,9,0,7,5,4,8,6,1> and I want to write all its worst partitions are these correct?thanks a1 = <0,2,9,3,7,5,4,8,6,1> a2 = <1,9,3,7,5,4,8,6,2> a3 = <2,3,7,5,4,8,6,9> a4 = <3,7,5,4,8,6,9> a5 = <4,5,7,8,6,9> a6 = <5,7,8,6,9> a7 = <6,8,7,9> a8 = <7,8,9> a9 = <8,9> a10 = <9> ...

about Select algorithm

Hi I have read about the selection algorithm and I have a question maybe it looks silly!!! but why we consider the array as groups of 5 elements ?? can we consider it with 7 or 3 elements??thanks also is there any link to help me for understanding this aim better? also this is my proof when we consider the array with 3 elements and it s...

what are the recent dataStructure and algorithms that one should know?

Recently I came across the SkipList data structure. It really helped me to solve one otherwise critical problem to be solved. I was struggling to solve the same problem with Balanced Binary tree but it became very complex as the tree needs to be always balanced and I wanted to know the existence of not only a particular value but values ...

list or container O(1)-ish insertion/deletion performance, with array semantics

I'm looking for a collection that offers list semantics, but also allows array semantics. Say I have a list with the following items: apple orange carrot pear then my container array would: container[0] == apple container[1] == orangle container[2] == carrot Then say I delete the orange element: container[0] == apple cont...

How do I save tabular data in rails?

I'm writing and app to let the production people estimate costs for building some products, they want to be able to give the product's base data (name of the product, client, etc) plus make the recipe for it (which materials are needed in order to build it) in the same page, and I was wondering how do I save tabular data in my rails co...

Best Data Structure to Store Large Amounts of Data with Dynamic and Non-unique Keys?

Basically, I have a large number of C structs to keep track of, that are essentially: struct Data { int key; ... // More data }; I need to periodically access lots (hundreds) of these, and they must be sorted from lowest to highest key values. The keys are not unique and they will be changed over the course of the progr...

What datastructure should I use to calculate the factorial of a more than 50 digits long number?

What are some data structures that help me storing and calculating the factorial for numbers with more than 50 digits? ...

What problems have you solved using bloom filters?

I'd like to know about specific problems you - the SO reader - have solved using bloom filters and what libraries/frameworks you used if you didn't roll your own. Questions: What problems have you used bloom filters to solve? What libraries/frameworks did you use? I'm looking for first-hand experiences, so please do not answer unles...

Best Data Structure for list of parts with assemblies, sub-assemblies, and such in VBA?

I'm working on a project that is basically a hack on top of a hack on top of an excel sheet and unfortunately we don't have time to re-factor but the core code simply isn't fast enough. We have assemblies which are made out of sub-assemblies and parts. So an assembly is the super structure and a part is the smallest structure. We have ...

Implementing custom STL-like data structures

I have already implemented and tested the data structure and would now like to make it compatible with the collection of STL algorithms. Guidelines for implementing a custom iterator and the like. Specifically: What is the minimum set of operations that must be supported? (e.g. ++, +=, ==, !=?) Are there any properties of these operati...

Best approach to separate Model View and Controler

I'm thinking about the best approach to separate Model View and Controler - for Java and using Eclipse, if if it makes any difference. I used to separate each type's MVC inside its own package, but I'm start to think that this is not the best approach: com.company.client (controler) com.company.client.model com.company.client.view com...

Efficient natural language data structure, persistence and querying

Hello all, For use in a language-learning web application, do you know of data structures and underlying database schema/ layout that would allow efficient storage, processing and querying of sentences, verbs, nouns etc. for different natural languages? For example I would like to store each verb only once and link sentences to a verb o...

What collection supports multiple simultaneous insertions?

Hi, We are developing a Java application with several worker threads. These threads will have to deliver a lot of computation results to our UI thread. The order in which the results are delivered does not matter. Right now, all threads simply push their results onto a synchronized Stack - but this means that every thread must wait for...

Any idea how to transform this O(n^2) algo into a O(n)

I have the following algorithm which scan a large circular array (data). At certain point in the array, I need to take a look at the past values (0 = newest data point, n = oldest data point) and determine if there was a value 5% below the current value. I ended up writing a O(n^2) algorithm which works okay, but this doesn't scale. ...

How to traverse a binary tree in a thread safe way?

I need a way to traverse a binary tree, using multiple threads and store elements that matches a criteria into a list. How do I do that, in a thread safe way? ...