data-structures

Is there a nearest-key map datastructure?

Hello all, I have a situation where I need to find the value with the key closest to the one I request. It's kind of like a nearest map that defines distance between keys. For example, if I have the keys {A, C, M, Z} in the map, a request for D would return C's value. Any idea? ...

Min Value from Stack

I have a stack which contains some integer data. I want to find out the min value from Stack in O(1) time. Any idea? PS: There is no ordering (increasing/decreasing) of data in Stack. Thanks, Naveen ...

A searchable heap structure

The problem is to access a series of values by two different methods. First, by priority; that is implemented simply enough with a heap. Additionally, it must be possible to "tag" each value with one or more symbols through which a list of items may be accessed. This would be easy enough to implement efficiently by referencing the same ...

How to reduce structure size

I have a class library containing several structures each consisting of several value and reference types. Most of the value types are mandatory, a few value types and all reference types are optional. All structures are XmlSerializable (which is mandatory). As far as the class library is targeted to mobile devices I want to reduce the ...

Streamlining Database/Login Process with PHP/MySQL

Hello all, I'm currently working on a small webapp where I work. I've created this for different departments. So, for example, let's say that: Marketing, Human Resources, and Sales uses it. Right now, as it stands, I have 3 completely different directories for each dept: http://mydomain.com/hr http://mydomain.com/marketing http://...

Python: manipulating sub trees

I'm a nooby. I'd like to acknowledge Allen Downey, Jeffrey Elkner and Chris Meyers and 'How to think like a computer scientist' for what I know. I'm building a genetics inspired program to generate equations that match some provided problem. The node class looks like this: class Node(object): ''' ''' def __init__(self, car...

What is a good data structure to represent an undirected graph?

I need to construct an undirected graph. I don't need it to do anything too fancy, but ideally it would work like this: structure UDG = UndirectedGraph val g = UDG.empty val g = UDG.addEdges(g, n1, [n2, n4, n7]) (* n1 is connected to n2, n4, and n7 *) val g = UDG.addEdge(g, n2, n3) UDG.connected(g, n2) (* returns [n1, n3] *) Is there...

How to save data with Python?

I am working on a program in Python and want users to be able to save data they are working on. I have looked into cPickle; it seems like it would be a fast and easy way to save data, it seems insecure. Since entire functions, classes, etc can be pickled, I am worried that a rogue save file could inject harmful code into the program. ...

Variable-length objects: Ever a good idea?

My application uses a large amount of Panda objects. Each Panda has a list of Bamboo objects. This list does not change once the Panda is initialized (no Bamboo objects are added or removed). Currently, my class is implemented as follows: class Panda { int a; int b; int _bambooCount; Bamboo* _bamboo; Panda (int c...

What data structures can efficiently store 2-d "grid" data?

I am trying to write an application that performs operations on a grid of numbers, where each time a function runs the value of each cell is changed, and the value of each cell is dependent on its neighbours. The value of each cell would be a simple integer. What would be the best way of storing my data here? I've considered both a flat...

Does java have a "LinkedConcurrentHashMap" data structure ?

I need a data structure that is a LinkedHashMap and is thread safe. How can I do that ? ...

What is a good book to study data structures in C?

Please tell me a good book for studying data structures in C. Feel free to post links of good e-books if you have any. What should be the strategy while learning this topic? ...

What is the most comprehensive book on data structures?

I am looking for a comprehensive book on data structures which covers wide range of data structures, both fundamental and advanced, with implementation code. I have consulted a few books but all of them skip some fundamental data structures here and there. For example, I am looking for some book which covers all variants of tree data s...

Efficient Python Data Storage (Abstract Data Types?)

Pardon the ambiguity in the title- I wasn't quite sure how to phrase my question. Given a string: blah = "There are three cats in the hat" and the (I'm not quite sure which data structure to use for this) "userInfo": cats -> ("tim", "1 infinite loop") three -> ("sally", "123 fake st") three -> ("tim", "1 infinite loop") three cats ...

Generic Key/Value pair collection in that preserves insertion order?

I'm looking for something like a Dictionary<K,V> however with a guarantee that it preserves insertion order. Since Dictionary is a hashtable, I do not think it does. Is there a generic collection for this, or do I need to use one of the old .NET 1.1 collections? ...

Graph implementation, functions and parameters. What makes more sense?

Just for kind of "fun" I'm developing almost every algorithm (if possible) shown in the book Introduction to Algorithms (Cormen) in C. I've reached the graphs chapters and I'm not sure how to design my functions, but first take a look at my data structures (hope this will make clear my question). typedef struct s_multi_matrix { ...

Changing one table seems to change the other

I'm writing a lua script, and one of the things it does is copy a table into a table of tables, and apply a couple transformations to it. What's odd though is when i go to use one of those tables later (and modify some of it's properties), changes will also seem to show up in other tables! Code: -- thanks to http://stackoverflow.com/que...

For a char/varchar/text column, why will an index for that column make it faster to search?

If it's an int, I know it will be faster, just cannot understand the string type. notes: most Asian language don't have the space between words. and mysql cannot split the sentence to words. and also, I mean random search, that is, words can appears in any where in a sentence . ...

Most frequently repeated numbers in a huge list of numbers

I have a file which has a many random integers(around a million) each seperated by a white space. I need to find the top 10 most frequently occurring numbers in that file. What is the most efficient way of doing this in java? I can think of 1. Create a hash map, key is the integer from the file and the value is the count. For every numb...

C struct - legal members?

Is this legal and/or good practice? #define SOFTWARE_VERSION_NUMBER "7.0v1.1" Want struct to always contain the version number. typedef struct { char SOFTWARE_VERSION_NUMBER; int a; int b; int c; }mystruct; ...