data-structures

Construct a binary tree such that the Post-order traversal should give the sorted result

Hi, I know that In-order traversal(VISIT LEFT, VISIT ROOT, VISIT RIGHT) on a binary search tree gives me a sorted result. But I need to do a Post-order traversal (VISIT LEFT, VISIT RIGHT, VISIT ROOT) on a binary tree and the result should give me sorted values. In order to achieve that, how should I construct my binary tree? ...

Interview question: Design a datastructure to support stack operations and to find minimun

Design a data structure which has the following features push the data pops the last inserted data [LIFO] Gives the minimum All of the above operations should have a complexity of O(1) ...

How are B Tree nodes typically represented?

I've been doing some brushing up on my B-Tree and 2-3-4 tree (B tree with order 4), and I'm attempting to implement this in C#. My question to you is, given that a B-Tree node can contains N-1 number of items and N subtrees, what is the typical representation for one of these nodes? Is it an array, series of linked-lists, or something I...

Need memory efficient way to store tons of strings (was: HAT-Trie implementation in java)

I am working with a large set (5-20 million) of String keys (average length 10 chars) which I need to store in an in memory data structure that supports the following operation in constant time or near constant time: // Returns true if the input is present in the container, false otherwise public boolean contains(String input) Java's ...

Pattern to map Generic Data Structure to a Specific Data Structure

I have a hierarchical generic data structure. There is a root node and under that there can be many tree nodes, or just a single data node, and tree nodes can have more tree nodes. A basic tree structure. All data in my system is persisted in this format. I do however want to have a strongly typed interface to some of the different type...

how to read immutable data structures from file in scala

I have a data structure made of Jobs each containing a set of Tasks. Both Job and Task data are defined in files like these: jobs.txt: JA JB JC tasks.txt: JB T2 JA T1 JC T1 JA T3 JA T2 JB T1 The process of creating objects is the following: - read each job, create it and store it by id - read task, retrieve job by id, create t...

What data-structure should I use to create my own "BigInteger" class?

As an optional assignment, I'm thinking about writing my own implementation of the BigInteger class, where I will provide my own methods for addition, subtraction, multiplication, etc. This will be for arbitrarily long integer numbers, even hundreds of digits long. While doing the math on these numbers, digit by digit isn't hard, wha...

what is the name of this data structure

(10) / \ (9) (8) / \ / \ (7) (5) (4) x x / and \ == x=>y y y thanks in advance ...

Algorithm for pattern matching

Background I am designing an application which will convert text from one language to other. For example, input text hello will be converted to specified language text. This is done by having a lookup table for each language. Conversion algorithm has the following steps. Looks for exact match. The whole word hello will be the pattern....

Parsing of data structure in a plain text file

How would you parse in Java a structure, similar to this \\Header (name)\\\ 1JohnRide 2MarySwanson 1 password1 2 password2 \\\1 block of data name\\\ 1.ABCD 2.FEGH 3.ZEY \\\2-nd block of data name\\\ 1. 123232aDDF dkfjd ksksd 2. dfdfsf dkfjd .... etc Suppose, it comes from a text buffer (plain file). Each line of text is "...

Clever data structure to represent layered circle.

I'm making a game and I need to represent a "layered" circle in some clever datastructure. A circle can have any number of layers. Each layer has a number of "slices", they can be of different lengths and pieces can be missing. The innermost layer is always a full circle. Each segment has a color, multiple segments with the same color c...

Is there a data structure that holds sets of data in .NET?

I'm looking for a data structure similar to a dictionary that returns the set of all related items to a key. For example, I would use it like this: var data = new FancyDataStructure(); data.Add(new string[] {"Elizabeth", "Liz", "Betty"}); data.Add(new string[] {"Bob", "Robert", "Rob"}); string[] alternateNames1 = data["Betty"]; strin...

Data structure that maps unique id to an object

I'm looking for a C++ data structure that will let me associate objects with a unique numeric value (a key), and that will re-use these keys after the corresponding object have been removed from the container. So it's basically somewhat of a hybrid map/queue structure. My current implementation is a std::map<size_t, TObject> and I ins...

PHP - how to access this data structure?

Hi, This is a newbie question - how do I access the value0, value1, ... entities? object(SimpleXMLElement)#43 (2) { ["@attributes"]=> array(3) { ["ABC"]=> string(1) "1" ["DEF"]=> string(14) "recordXYZ" ["GHI"]=> string(1...

Fast two-dimensional pattern matching

Consider a two-dimensional grid (the usual lattice in the plane). For my purposes, a pattern or arrangement is an assignment of the numbers 1 and 2 to some connected subset of the grid points. For example, the following shows three separate arrangements: .......1.....1.... .222...2.....12... .111...2.....2.... .222...22...12211. ........

PHP - how to create this SOAP XML request?

Hi! I'm trying to figure out how to structure data properly in PHP in order to make a SOAP XML request like this: <typ:saveRequest locationName="example.com"> <typ:datatype owner="ME" class="OPEN"> <typ:order>1</typ:order> <typ:datavalue>[email protected]</typ:datavalue> </typ:datatype> </typ:saveRequest> Th...

Copy a linked list

typedef struct Node { int data; Node *next; Node *other; }; Node *pHead; pHead is a singly linked list. The next field points to the next element in the list. The other field may point to any other element (could be one of the previous nodes or one of the nodes ahead) in the list or NULL. How does one write a copy function that...

Nokogiri replace tag values

How to replace "foo" to "bar" ? From <h1>foo1<p>foo2<a href="foo3.com">foo4</a>foo5</p>foo6</h1> to <h1>bar1<p>bar2<a href="foo3.com">bar4</a>bar5</p>bar6</h1> I want only replace tag inner content, without tag attributes. Any ideas ? ...

Need algorithm for Sequence calculation

Hi, I am trying to find the solution for a problem where i have something like A > B B > C B > D C > D And I should get the answer as A > B > C > D. Conditions for this problem The output will involve all the elements. The problem will not have any bogus inputs. for example, (A>B) (C>D) is a bogus input, since we cannot determine...

Trie implementation - Inserting elements into a trie

I am developing a Trie data-structure where each node represents a word. So words st, stack, stackoverflow and overflow will be arranged as root --st ---stack -----stackoverflow --overflow My Trie uses a HashTable internally so all node lookup will take constant time. Following is the algorithm I came up to insert an item into the tr...