data-structures

the best way to store my statistics (ruby)

I want to display some statistics of data stored in array of arrays. I have three categories (video,article,webinar) but it could expand later on. The structure of statistics per category will be almost the same. Like: total number of videos, last date when added new record in category, etc. So far I can think of a hash of an array to s...

Python equivalent of std::set and std::multimap

I'm porting a C++ program to Python. There are some places where it uses std::set to store objects that define their own comparison operators. Since the Python standard library has no equivalent of std::set (a sorted key-value mapping data structure) I tried using a normal dictionary and then sorting it when iterating, like this: def __...

What is the closest thing in Erlang to hashes?

What I wanted was a way to pass arguments into functions which resembled a ruby hash map. Although maybe this is a bad fit for Erlang, I'm not sure yet In Ruby I often used hashes like: {"a"=>100, "b"=>200} : What is the closest thing in Erlang? Update: I have since found this: http://20bits.com/articles/erlang-an-introduction-to-r...

ArrayList of arrays vs. array of ArrayLists vs. something similar

I'm creating a TableModel which will have a fixed number of columns, but the number of rows will be changing (mostly, increasing as function of time). Which would be better approach to store the data, ArrayList[] columns = new ArrayList[numberOfColumns]; // Each array element is one column. Fill each of them with a new ArrayList. ... pu...

How to use attribute value as a discriminator for XML polymorphic type selection?

I am trying to write XML Schema by existing XML format description (i.e. document - free form description of elements multiplicity and types). My final idea is to feed such XSD to code generator and get binding classes. Here is an example I cannot cope with: packet1.xml: <?xml version="1.0" ?> <packet kind="type1"> <field1>value1<...

Design Question: How can I maintain a stack of object

I have a struct call 'A', which has an attribute 'i', like this: typedef struct a { a() { i = 0;} int i; } A; And I would like to maintain a stack of A in my Main class: class Main { public: void save(); void doSomethingToModifyCurrentA(); void restore(); private: A currentA; stack<A> aStack...

Graph data representation in text form

What would be the best way to visualize DAG's nodes and edges in a text form/file? The node can be referred by its name. ...

Union/find algorithm without union by rank for disjoint-set forests data structure

Here's a breakdown on the union/find algorithm for disjoint set forests on wikipedia: Barebone disjoint-set forests... (O(n)) ... with union by rank ... (now improved to O(log(n)) ... with path compression (now improved to O(a(n)), effectively O(1)) Implementing union by rank necessitates that each node keeps a rank field for com...

Best datastructure for a heightmap

I have a heightmap (a 2D array of floating point values) and I wish to find the highest point on the map, once I have found this point, I want to change its value, and the values of all nearby points. What's the best datastructure to use for efficient retrieval of the highest point? Requirements: Find the highest point efficiently Cha...

What sort of things should an amateur programmer concentrate on?

For example... I'm learning Java and have started working on a tetris clone to help consolidate my new knowledge. I'm also slowly working through Project Euler to help beef up my problem solving and basic ability to cut some code. I've just started reading through Robert Lafores, Data Structures and algorithms in 24 hours to get a bas...

Array of strings in C

I'm trying to create a structure storing strings and I'm getting an error incompatible types when I try and insert as string into the array. This my first time working with a program in C. Could somebody help spot my problem. This is my implementation of list.c struct list *init_list(int num) { struct list *p; p = malloc(LIS...

Find kth smallest element in a binary search tree in Optimum way

Hi, I need to find the kth smallest element in the binary search tree without using any static/global variable. How to achieve it efficiently? The solution that I have in my mind is doing the operation in O(n), the worst case since I am planning to do an inorder traversal of the entire tree. But deep down I feel that I am not using the ...

Hashset vs. IQueryable

Recently I was working on implementing a small snippet that caches my results and the way I was doing it was using a Dictionary as follows: private Dictionary<ID, IQueryable<Results>> _simpleCache; The idea was to search for all the results that have the id specified by 'ID' and if the Dictionary contains the key == id, we simply sea...

Please suggest some algorithm to find the node in a tree whose distance to its farthest node is minimum among all the nodes

Please suggest some algorithm to find the node in a tree whose distance to its farthest node is minimum among all the nodes. Its is not a graph and it is not weighted. ...

Is there pointer in C# like C++? Is it safe?

Hi, I write an application that work with tree data structure. I written it with C++, now i want to write it by C#. I use pointers for implementing tree data structure. Is there pointer in C# too? Is using of that safe? ...

Which tree-based dictionary is the easiest to implement functionally?

I'm looking for a tree-based dictionary data structure which is easy to implement in Haskell. Do you have any experience with implementing AVL trees or RB trees? I'm also thinking about splay trees, but don't see how they could be implemented using immutable data. ...

Implementing separate overflow chaining

I am solving a problem of getting the top K frequency from an array of structure containing value and frequency sorted by value ascending. The data size is really huge say a million entries. After discussing this with my friend, we shortlisted hash bucket approach with separate overflow chaining. Here’s my approach: Since the number of ...

What Are The Best Practices For String Data Field Sizes?

Are there any recomended field sizes for commonly used string data storage types? For example things like FirstName, LastName, AddressLine1, AddressLine2, City, State, PostalCode, EmailAddress etc. I am sure anyone who has created a table to store these commonly used data fields has had to make a decision as to what maximum size to use. ...

ByteBuffer recycling class

Hi everyone, I'm wonder how I'd code up a ByteBuffer recycling class that can get me a ByteBuffer which is at least as big as the specified length, and which can lock up ByteBuffer objects in use to prevent their use while they are being used by my code. This would prevent re-construction of DirectByteBuffers and such over and over, inst...

Confusion in finding the order of the data structure

Hi, Today I attended a written test conducted by a company. The overall test was focussed on data structures. I got a problem which I thought I solved. But I had a tough time in calculating the Big O function for the data structure. I will provide the question and the answer I came up with. Given a document you need to store and the...