data-structures

N-queens in Haskell without list traversal

I searched the web for different solutions to the n-queens problem in Haskell but couldn't find any that could check for unsafe positions in O(1) time, like that one that you keep an array for the / diagonals and one for the \ diagonals. Most solutions I found just checked each new queen against all the previous ones. Something like thi...

Variable sized structs with trailers

I posted on this topic earlier but now I have a more specific question/problem. Here is my code: #include <cstdlib> #include <iostream> typedef struct{ unsigned int h; unsigned int b[]; unsigned int t; } pkt; int main(){ unsigned int* arr = (unsigned int*) malloc(sizeof(int) * 10); arr[0] = 0xafbb0000; arr[...

What's the simplest and most efficient data structure for building acyclic dependencies?

I'm trying to build a sequence that determines the order to destroy objects. We can assume there are no cycles. If an object A uses an object B during its (A's) construction, then object B should still be available during object A's destruction. Thus the desired order of destruction is A, B. If another object C uses object B during its (...

I need the sum of two fields that are in different DataTables

The problem is that in c# I can't subtract the objects, so I need to figure out how to get the integers out of them and then do the arithmetic? Here's the code.. what am I missing? dsfDataSet.itemTotals.Compute( "SUM(priceSum)", String.Empty ) - dsfDataSet.discountItems.Compute("SUM(totDiscount)", String.Empty) ...

Superset Search

I'm looking for an algorithm to solve the following in a reasonable amount of time. Given a set of sets, find all such sets that are subsets of a given set. For example, if you have a set of search terms like ["stack overflow", "foo bar", ...], then given a document D, find all search terms whose words all appear in D. I have found tw...

Is there an Open Source library of some sort that identifies data patterns in a table?

Okay, here's the situation: We have a table of about 50 columns (created by joining database tables) and several thousand rows. We need to identify a pattern in several known faulty records of that data. Here's a really boiled down example. Given a table: ----------------------- | id | title | date | ----------------------- | 01 | c ...

Methods for storing searchable data in C#

In a desktop application, I need to store a 'database' of patient names with simple information, which can later be searched through. I'd expect on average around 1,000 patients total. Each patient will have to be linked to test results as well, although these can/will be stored seperately from the patients themselves. Is a database the...

How can I create a hash of hashes in Perl?

Hi everyone, I am new to Perl. I need to define a data structure in Perl that looks like this: city 1 -> street 1 - [ name , no of house , senior people ] street 2 - [ name , no of house , senior people ] city 2 -> street 1 - [ name , no of house , senior people ] street 2 - [ name , no of house , senior p...

How can I find the smallest value in a Perl hash of hashes of arrays?

I want to find the easiest way of finding the hash values City { city1 -> Street1 -> [ high_street , 2] street2 -> [ low_street , 2] city2 -> Street1 -> [ high_street1 , 2] street2 -> [ low_street2 , 2] city3 -> Street1 -> [ high_street1 , 1] street2 -> [ low_street2 , 1] } This structure is sor...

How to store linear range of values? Which Data structure to choose?

I need a simple structure to store polygon names based on sides ... so for e.g. 1 side is "monogon", 2 sides is "digon", 3 sides is "triangle" and so on (say for upto 12 sides) What is the simplest way to store these and reuse them in the code dynamically? for e.g. if my polygonShape class has 3 as the number of sides, it should return "...

Knowledge required to build your own integer class?

Upon reaching a brick wall with the .Net framework's lack of a BigInteger class (yet), I've decided I'd like to develop my own as an exercise (I realize open source alternatives exist). What hoops do I need to jump through to be able to develop this? Is there any particuliar knowledge pieces that I probably wouldn't have? edit: side q...

jQuery and International Address Data

I wanted to get opinions on a jQuery plugin I've bee working on to display an international address form. I posted it on my blog at http://weblogs.asp.net/awilinsk/archive/2009/08/13/jquery-amp-international-address-data-collecting-and-storing.aspx. I have searched around here and all over the internet to get some insight on how to solv...

Java Data Structures Reference

Can anyone give me references of a web site containing a summary of the main Java data structures, and their respective complexity in time (for some given operations like add, find, remove), e.g. Hashtables are O(1) for finding, while LinkedLists are O(n). Some details like memory usage would be nice too This would be really helpful for...

Cache like mechanism (which Data Structure) ?

I am fetching some questions from the server (database) and showing it to client (user) in the browser. The client will answer the question and based on his/her answer the next set of questions will be fetched from the database. Now, I want to pre-fetch the next set of questions while the user read the present question so that the waitin...

Where can I learn more about datastructure tricky questions?

I am relatively new to programming (around 1 year programming C#-winforms). Also, I come from a non CS background (no formal degree) Recently, while being interviewed for a job, I was asked about implementing a queue using a stack. I fumbled and wan't able to answer the question. After, the interview I could do it(had to spend some tim...

Data structure for designing a cache with efficient insertion,deletion and the retrieval of highest value

I have to implement a cache with normal cache operations along with the facility of fast retrieval of the maximum element from the cache. Can you please suggest data structures to implement this? I was thinking of using hash map along with a list to maintain the minimum element. Suggest other approaches with better complexity. ...

To combine challenging PHP arrays

How can you combine the two arrays? They are simplified as follows which is enough for this question. This question is based on this answer. 1 [a][b][] and 2 [a][c] where both arrays has one common subarray [a]. I would like to have this [a][c][b][] I have run the following command unsuccessfully array1[a] + array2[a] ...

PHP multidimensional arrays in generating question summaries

The purpose of this question is to find the best way to print data out of PHP multidimensional arrays. How can you complete the following procedure below? I have the following arrays array1['id']['title'] and array2['id']['tags'][] The arrays have been generated by the function pg_fetch_array. This allows you refer to each value ...

What would you call a non-persistent data structure that allows persistent operations?

I've got a class that is essentially mutable, but allows for some "persistent-like" operations. For example, I can mutate the object like this (in Python): # create an object with y equal to 3 and z equal to "foobar" x = MyDataStructure(y = 3, z = "foobar") x.y = 4 However, in lieu of doing things this way, there are a couple of met...

looking for idea to embbed "book like view " in exe file

Hello all i have application that convert data structure from the GUI to doc/pdf/rtf/html ... files the structere logic contains the info about pages and data on each page so basccly i can convert it to every thing . but my problem is that i wish to convert this structure to some kind of book that is exe binary file . and i have no ...