data-structures

Binary trees, construct a tree based on preorder

Hello, constructing a tree given it's inorder is easy enough. But, let's say you are supposed to construct a tree based on it's preorder (+ + y z + * x y z for example). It's easy to see that + is the root, and how to continue in the left subtree from there. But.. how do you know when you are supposed to "switch" to the right subtree? ...

In VB.NET, what data structure to use so that, given two characters, return an integer for optimum performance?

I am finishing up a program that does a large number of calculations and am trying to optimize the innermost loop. The calculation I am currently looking at iterates over a large number of pairs of words and makes a table of the counts of corresponding pairs of characters. For example, one pair of words might be: voice louse and the...

Data structure for recognizing repeat values.

I am running a fairly large search, and am getting a System.OutOfMemoryException. The problem is I am storing a string key for each state I have previously visited as a HashSet<sting>. Once this gets to around 7 million elements, it crashes. My thought is that I don't need to be able to retrieve the strings, only recognize if it exists ...

Populate Nodes with Delimited String

My programmer's block is especially bad today, maybe you can help get me moving again?! Supplement I'm trying to parse out some CSV's from a legacy program we are trying to support. The part I'm trying to abstract is stored by the old program in a string "Channel.Device.Element1.Element2.Tag:Description" I am now storing this data ...

getting rat out of a maze

A rat is placed in a maze at some unknown position in the maze. All we can go is in up, down, right or left directions. And we have two methods: tryMove(<direction>) which returns false if there is a wall and true if we can move. bool hasLadder(): which returns true if there is a ladder to escape. We have to write a function explo...

memory size of Python data structure

How do I find out the memory size of a Python data structure? I'm looking for something like: sizeof({1:'hello', 2:'world'}) It is great if it counts every thing recursively. But even a basic non-recursive result helps. Basically I want to get a sense of various implementation options like tuple v.s. list v.s. class in terms of memory...

Is this code a Circular linkedlist

The following code was been given from our school as a sample for circular linkedlist and told each student to build a own version of circular linkedlist. Now my query is that is the following code is really a circular linkedlist ? // Program of circular linked list #include <stdio.h> #include <malloc.h> struct node { int info; ...

Light C data structures and strings library?

I'm searching for something on the level of GNU extensions for C, but a little beyond (some basic data structure management). Best would be something BSD/MIT licensed. If there is something for just strings containing GNU extensions equivalents plus adding some more it would be great. I would prefer something that can be simply compile...

Need Exercise to solve based on Linear Linked List

I have completed implementing Operation of Linear Linked List using C, Now inorder to test my ability i need to solve some problems based on Linear Linked List, and there you people can help me by suggesting some problems/assignments ... I think there is nothing wrong in asking this type of help from my community members . ...

Find k rectangles so that they cover the maximum number of points

In two dimensional space, given a bunch of rectangles, every rectangle covers a number of points and there may be overlap between two arbitrary rectangles, for a specified number K, how can i find the k rectangles such that their union cover the maximum number of points? In this problem, if a point is covered by more than two rectangles ...

Infix vs Postfix

Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis) or Postfix? State with reason.. I only could tell them that: it is easier for the compilers to process postfix expression for arithmetic evaluations and operator precedence. More memory is used for storing and processing the parenthesis. ...

Data Structure data materials

Possible Duplicate: Good Data Structures text book Hello, Where can i find full title with all the details of dynamic data structures: lists, stack, trees, graphs and etc... Thank you ...

C#: How to fit a structure in an int64 ?

Question: I need to fit the following structure into an int64 day 9 bit (0 to 372) year 8 bit (2266-2010 = 256 y) seconds 17 bit (24*60*60=86400 s) hostname 12 bit (2^12=4096) random 18 bit (2^18=262144) How do I make such a structure fit in an int64 ? All items are numberic, and of the specified bit size. ...

Heuristics for estimating the efficiency of Reduced Ordered Binary Decision Diagrams?

Reduced Ordered Binary Decision Diagrams (ROBDD) are an efficient data structure for boolean functions of multiple variables f(x1,x2,...,xn). I would like to get an intuition for how efficient they are. For instance, for data compression, we know that data with low entropy (some symbols appearing more often than other, many repetitions)...

Idiomatic way to store a single, "first-class" list in MongoDB?

I have a special list (a sort of queue, as in the data structure, not as in a work queue) that I want to store in MongoDB. I need to access and manipulate this single list often in my application - and I don't have several of the same type of list. It would be easiest to store it in a single document, but the problem I'm having is figur...

Best practice for reading csv (with variable number of lines) into data structures

Hey guys, I'm writing a small program to read in a csv with a variable number of lines and have a question about best practices: Is the best way to create storage for the data on each line to make an array that holds the data structures of the csv (one per each line of csv)? Size allocated to the array could be set to a large number (f...

Treap with implicit keys

There's a data structure called treap: that's a randomized binary search tree, which is also a heap on randomly generated so-called "priorities". There's a variation of this structure, where keys are implicit, they aren't stored in the tree, but we consider the ordered index of the node in the tree as this node's key. We need to store s...

Why use binary search if there's ternary search?

Hello, I recently heard about ternary search in which we divide an array into 3 parts and compare. Here there will be two comparisons but it reduces the array to n/3. Why don't people use this much? ...

What situations require me to store different versions of the same data in a database?

This is a shot from Google BigTable paper What can be the kind of scenarios in which instead of having something like Oracle's redo logs, I will need to store multiple versions of the same data within the database? Coming specifically to this example, why do I need to store multiple versions of a html page in my database? It cannot ...

many to many table - 1 seperate field primary key or 2 existed fileds primary key (Example inside)

Hi, I have 2 tables with many to many relation: student ( id int(11) NOT NULL, name varchar(255), primary key(id) ); teacher ( id int(11) NOT NULL, name varchar(255), primary key(id) ); and I should do 3 table - student_has_teacher option add id separate field primary key student_has_teacher ( id int(11) NOT NULL, teacher_i...