data-structures

Selectively counting delimited field values and creating a hash using map

I have a pipe delimited text file containing, among other things, a date and a number indicating the lines sequence elsewhere in the program. What I'm hoping to do is from that file create a hash using the year as the key and the value being the maximum sequence for that year (I essentially need to implement an auto-incremented key per y...

Displaying MySQL data into HTML table (clearly explained)

Ok, I have an app as described in this post: http://stackoverflow.com/questions/1623105/good-database-structure-for-a-new-web-app I've prepared a scenario to make my question as clear as possible: Users table: +----------+-----------------+ | user_id | email | +----------+-----------------+ | user_1 | user1...

Problem in understanding XOR linked list.

I am reading XOR linked list (from Wikipedia).But I am having some problems in understanding it. I am not getting following paragraph. To start traversing the list in either direction from some point, you need the address of two consecutive items, not just one. If the addresses of the two consecutive items are reversed, you will en...

Optimizing Data Translation

Our business deals with houses and over the years we have created several business objects to represent them. We also receive lots of data from outside sources, and send data to external consumers. Every one of these represents the house in a different way and we spend a lot of time and energy translating one format into another. I'm loo...

Actual total size of struct's members

Hi guys! I must write array of struct Data to hard disk: struct Data { char cmember; /* padding bytes */ int imember; }; AFAIK, most of compilers will add some padding bytes between cmember and imember members of Data, but I want save to file only actual data (without paddings). I have next code for saving Datas array (in ...

MySQL - DB Design for "has many" issue across tables vs stored lists

Trying to figure out the best way to set up collection "lists" for users given the following data (pseudo code): user table = id, name, email cars table = id, make, model user_cars table = user_id, car_id, rating collections table = id, user_id, name Facts: Users can have many cars Users can have many collections Individual cars ...

Best way to construct a "complex" data structure in Python

Hello guys. I need to construct a tool that will be used to create field mappings (between tables) in the most automated manner possible. Here is the deal: imagine a table being appended to other. (lets ignore field type, just for a second...) CREATE OR REPLACE TABLE fooA( id, name, type, foo) CREATE OR REPLACE TABLE otherFooTable( i...

Scheduling Employees - what data structure to use?

Question I'm trying to write a simple employee Scheduling software for about 10-20 people in my software development company. After some consideration I settled on writing a web app in Python, Ruby or PHP + Postgres/MySQL DB. While designing database models I began to wonder what data structure would actually be the best for that kind o...

Should I implement a constructor or use the default one for data classes?

Data class, in this question scope, is a class with more public properties than methods. Should I: public class Complex { public double Real { get; set; } public double Imaginary { get; set; } } Or: public class Complex { public double Real { get; set; } public double Imaginary { get; set; } public Complex(double...

MPTT ( Modified Preorder Tree Traversal) issue in PHP

Hi guys, My first post here! Seems like this is the place to get wise ;) I am currently in the middle of some testing with my first ever attempt to try the MPTT (Modified Preorder Tree Traversal) approach to storing data in my Mysql database with the help of PHP. However, I am trying to find out the most performance-oriented way to ge...

Data Structure for storing a sorting field to efficiently allow modifications

I'm using Django and PostgreSQL, but I'm not absolutely tied to the Django ORM if there's a better way to do this with raw SQL or database specific operations. I've got a model that needs sequential ordering. Lookup operations will generally retrieve the entire list in order. The most common operation on this data is to move a row to th...

Create groups from sets of nodes

I have a list of sets (a,b,c,d,e in below example). Each of the sets contains a list of nodes in that set (1-6 below). I was wondering that there probably is a general known algorithm for achieving the below, and I just do not know about it. sets[ a[1,2,5,6], b[1,4,5], c[1,2,5], d[2,5], e[1,6], ] I would like to generate a new s...

Self-sorted data structure with random access.

I need to implement self-sorted data structure with random access. Any ideas? ...

How CSS and DOM is implemented in the browser?

This is a pretty academic question. I'm wondering how the browser is implemented as in what data structure or algorithm is used to map a CSS selector to a particular DOM element. Is it accomplished through a hash table? How does DOM child node knows that the style applied to parent also applies to itself etc. I've been looking at Moz...

Dealing with Structs in C

Suppose struct_name is the name of a struct I've defined, and array is a member in the struct defined as char array[o] what does the following line produce? (*struct_name).array an address location? ...

Random-access data object in J2ME

Hello, I'm planning to develop a small J2ME utility for viewing local public transport schedules using a mobile phone. The data part for those is mostly a big bunch of numbers representing the times when the buses arrive or leave. What I'm trying to figure out is what is the best way to store that data. The representation needs to be...

Find the shortest Path between two nodes (vertices)

I have a list of interconnected edges (E), how to find the shortest path connecting from one vertex to another? I am thinking about using lowest common ancestors, but the edges don't have a clearly defined root, so I don't think the solution works. Shortest path is defined by the minimum number of vertexes treversed. Note: There coul...

How would you design this DB?

Hi, We are launching a website (paid subscription) and the sign up process includes entering an activation code. Activation codes are printed on scratch cards and sold via offline channels. Some of these cards are for 1 month access. Others are for 3 months and 1 year. Activation codes are unique 10-digit random numbers. When the acces...

Find the number of unique longest common subsequences

For 2 strings, I want to find the number of distinct LCS's. I read on wiki on how to print all LCS's but how to check that they are distinct? The hash table is not feasible as my input string each can be 1500-2000 characters long so maximum number of LCS's can be 2000 choose 1000 ...

How do I loop through all levels of a data structure to extract all data when I don't know how many levels there will be?

I need to extract data from a structure and put it into a list, but I don't know how many levels the structure has. For each level, I can call level.children(), if there are no levels below the current one, it returns [], if there are, it returns [object, object, ...], on each of which I can call children() on again. I need to drill do...