data-structures

How to look at the data stored in a QMap?

How to look at the data stored in QMap without iterating through it? I am trying to debug an application using QMap with many keys, do you know a way to look at the data in QMap without iterating through each value? ...

PHP, Array of Arrays vs Array of Objects

I'm in the process of creating a PHP data structure based on some data I'm fetching from somewhere. If I would encode this information in some standard container, like XML or JSON, I would use this structure: [ {'name': 'Lupin', 'age': '13'}, {'name': 'Igor', 'age': '24'}, ... ]; However I'm a bit unsure what to use in PHP ( Array o...

what is a loop invariant ?

I'm reading "Introduction to Algorithm" CLRS. and the authors are talking about loop invariants, in chapter 2 (Insertion Sort). I don't have any idea of what it means. ...

Mutual referencing records in Delphi (Win32)

Is there any work-around to create mutual referencing records in Delphi? Here's the simplified version of the code: MyRec1 = record arr: MyRec2Array; end; MyRec2 = record mr: MyRec1; end; MyRec2Array = array of MyRec2; Apparently forward declaration of record types MyRec2 = record; doesn't work in Delphi for Win32. Switchin...

Drawing Tools for drawing array/linked list images

I'm thinking of writing few blogs on arrays and linked list and for that I need some good drawing tool for drawing images to explain the concept and the logic. I don't want to copy/paste images from other source so if anyone among you knows about any such tool in which I can create images fast and similar to ones given in books and on ot...

C Doubly Linked List Segmentation Fault

I have written my own linked list implementation in C, and it works fine for storing values, but whenever I try to run through the list I get a segmentation fault. I'm not sure why the issue arises, and I spent a decent amount of time trying to run through the program myself but to no avail. Could you guys help me find the reason for the...

How to display flat data structure into hierarchical data structure (Java)?

Hi all , I have recently faced this question in a practical test for a job . Suppose you are given a flat data structure like this : **Category** **Name** **Parent** 1 electronics 0 2 Television 1 3 21inch 2 4 23in...

Predicate Logic in Haskell

I've been using the following data structure for the representation of propositional logic in Haskell: data Prop = Pred String | Not Prop | And Prop Prop | Or Prop Prop | Impl Prop Prop | Equiv Prop Prop deriving (Eq, Ord) Any comments on this structure are welcome. However, now I want to extend ...

What java datastructure/library do you use for a Tree

I have a Region Hierarchy(think State, District, Taluk, etc) that I need to represent using a Tree. I saw a few implementations of a Tree in the public domain BUT not sure how good they are and how well they are maintained. Apache Collections doesn't have one of those NOR do the google collections. I'm wondering if any of you can point m...

Is there an easy way to remember the rotation methods for red-black trees?

Is there an easy way to remember the rotation methods for red-black trees? ...

"Parametrized" database model & backend storage system as well as data mining manipulation

Hi Guys I have implicitly made this a community wiki seeing that the answers can be quite broad. I'm working with a start-up company to accomplish the following goal. In a medical research, a patient medical record can have infinite amount of data regarding a patient for a specific diagnosis, e.g. a smoker has a higher chance of catchi...

Immutable data structures performance

I don't get how can something as a Set be immutable and still have an acceptable performance. From what I've read in F# Sets internally use Red Black Trees as their implementation. If each time we want to add something new to a Red Black Tree we have to basically recreate it, how can it have ever good performance? What am I missing her...

fastest search algorithm

hello I'm trying to implement an algorithm to search multiple XML files for a certain record. known that the records are not sorted ( i don't have an indexed id) . what is the fastest algorithm to search for that record ?. please let me know if anything was unclear thanks in advance ...

Algorithms or theory for merging portions of two graph structures?

I have a directed acyclic graph, an example of which may look like: | (1) / | \ / | \ (3) (2) (4) / / | \ \ / / | \ \ / / | \ \ (6)(7) (5) (8)(9) | | | ...

What's the difference between set<pair> and map in C++?

There are two ways in which I can easily make a key,value attribution in C++ STL: maps and sets of pairs. For instance, I might have map<key_class,value_class> or set<pair<key_class,value_class> > In terms of algorithm complexity and coding style, what are the differences between these usages? ...

Test whether a list contains a specific value in Clojure

What is the best way to test whether a list contains a given value in Clojure? In particular, the behaviour of contains? is currently confusing me: (contains? '(100 101 102) 101) => false I could obviously write a simple function to traverse the list and test for equality, but there must surely be a standard way to do this? ...

Storing vast amounts of (simple) timeline graph data in a DB

I need to store the number of plays for every second of a podcast / audio file. This will result in a simple timeline graph (like the "hits" graph in Google Analytics) with seconds on the x-axis and plays on the y-axis. However, these podcasts could potentially go on for up to 3 hours, and 100,000 plays for each second is not unrealisti...

Java:Internal data structure in Map

I am trying to create a class that implements the Map interface. So I am writing code that will check if the calling object is empty or not. However I am a little confused as to which data structure I should use internally. At present I am using a Hash Table. Thanks in advance ...

Python: Finding a (string) key in a dictionary that contains a substring

In my script I build a dictionary of keys(albums) mapped to artists(values) so that I can do a quick lookup of what artists made what albums. However, I want the user to be able to find all albums which contain a substring. For example a search on "Light" should return [Light Chasers] = Cloud Cult and also [Night Light] = Au Revoir Sim...

Temporary group membership tally - Any clever way to do it?

I'm building a website. It has groups that users can join. The difference between this and "normal" groups is that membership is temporary - when a user joins a group, he decides the length of membership: 5 days, a week, 2 weeks, etc (choices are pre-defined). Or potentially all memberships could be set to be of the same length - say a...