data-structures

how should I structure data for a complex object in ActionScript 3?

I hope this isn't too vague, but I'm stuck on a problem that has put me in an Unfortunate Position. I'm Flash developer getting my feet wet with with AS3 and am trying to build an interior decoration tool for a client. My thinking so far has been: create the basic user interface, get the screen flow down, and then finally use a couple o...

appengine data structure - child, parent or both?

I'm trying my hand at google appengine and using the datastore with php and quercus. I'm not familiar with Java or Python, so lots of learning going on here. I've got pages rendering, and i'm able to get data in and out of the datastore. The app I am building has users, groups, topics and comments. A group has users, and users can bel...

Advantages of linked lists over binary trees?

The title is mostly self-explanatory: what are the advantages of linked lists over binary trees? The only case I can think of in which a linked list is more efficient is for iterating over every element, in which case it's still pretty close. It looks like binary trees are faster at both accessing data and inserting new elements. So why ...

Concatenating/Merging/Joining two AVL trees

Assume that I have two AVL trees and that each element from the first tree is smaller then any element from the second tree. What is the most efficient way to concatenate them into one single AVL tree? I've searched everywhere but haven't found anything useful. ...

randomized binary search trees

Randomized binary search trees like treap give a good performance (in the order of O(log n)) with high probability while avoiding complicated (and costly) rebalancing operations that are needed for deterministic balanced trees like AVL, red-blackm, AA, etc. We know that if we add random keys to a simple BST, we can expect it is reasonab...

java return statement

Hi, I have a question about the following code private void printTree(Node node){ if(node==null) return; printTree(node.left); System.out.print(node.data+" "); printTree(node.right); } I don't really get the point of 'return;' statement there. It looks like if node is null, code returns nothing. but then without that ...

Tree in java to store words from a text

Hi guys! I have a text file where each line is a path of word strings word1/word2/.../wordn and I want to query the file. I need to build a tree which stores the words and each line of the file as a path so that anytime I search for a word, I get the word-node and all the paths this word belongs to. I was wondering if there is a build-in...

Can a variable like 'int' be considered a primitive/fundamental data structure?

A rough definition of a data structure is that it allows you to store data and apply a set of operations on that data while preserving consistency of data before and after the operation. However some people insist that a primitive variable like 'int' can also be considered as a data structure. I get that part where it allows you to store...

"... algorithm follows at most lg N pointers to determine..." What does lg stand for?

In the statement "The weighted quick-union algorithm follows at most lg N pointers to determine whether two of N objects are connected" what does lg stand for? ...

How to Correctly Use Lists in R?

Brief background: Many (most?) modern programming languages in widespread use have at least a handful of ADTs in common, in particular, string (a (sequence comprised of characters), list (an ordered collection of values), and a map-based type (an unordered key-value store). In the R, the first two are implemented as 'character' and 'vect...

Algorithm For Flight Schedules

I have a list of all direct flights. From this I want to get flights from A to B with connections. What will be a suitable algorithm or data structure for this problem? Thanks. ...

Converting an IEnumerable to a lookup with multiple keys per value

What's the best way to transform an IEnumerable into a lookup- or dictionary-like structure, but with multiple keys per value? What I'm looking for is something that does roughly the same thing as this, and in a generic way: var wordsByLetter = new Dictionary<char, HashSet<string>>(); foreach (string word in words) { foreach (char l...

Calculator stack

My understanding of calculators is that they are stack-based. When you use most calculators, if you type 1 + 2 [enter] [enter] you get 5. 1 is pushed on the stack, + is the operator, then 2 is pushed on the stack. The 1st [enter] should pop 1 and 2 off the stack, add them to get 3 then push 3 back on the stack. The 2nd [enter] shouldn't ...

Delete Duplicate from an Array

Hi, I received one question "How to delete duplicate entries from an array" Constrain: No new data structure and same array should return only distinct element. So for example If my array is 1,3,3,3,5,55,67,1 then the result should be 1,3,5,55,67 I have solved the problem public void DeleteDuplicate(int[] array) { int ...

What real world uses of the "Stack" object (.Net) have you used.

We have all read about or heard about the stack class, but many of us have probably never found a reason to use the LIFO object. I am curious to hear of real world solutions that used this object and why. http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx I recently saw an example where a programmer used a stack to ...

How to use previous count of semaphore in ReleaseSemaphore.

Looking for an example of how to read the last semaphore count from ReleaseSemaphore Having problems creating a basic local variable to store LPLONG lpPreviousCount into and print out. Looks like I need a pointer to the variable but not having much luck. If you can point me in the right direction, that would be greatly appreciated. ...

What is the true difference between a dictionary and a hash table?

I've always used dictionaries. I write in Python. ...

Reverse a singly-linked list with and without using recursion

I am new to data structures, and I know this is a very common question to ask. But I know LinkedList in .NET is doubly-linked, so how I will write code for a singly-linked list in C#. Could someone please write sample code? ...

Write a function that compares two strings and returns a third string containing only the letters that appear in both

Hi All, I got this homework. And have solved it in following way. I need your comments whether it is a good approach or I need to use any other data sturcture to solve it in better way. public string ReturnCommon(string firstString, string scndString) { StringBuilder newStb = new StringBuilder(); if (firstString...

What is a good .NET data structure for finding unique items?

I have a large collection of custom objects that I have retrieved from a query in my system. Let's say these objects all have 5 different properties - FirstName, LastName, Gender, ZipCode and Birthday. For each of the different properties I would like to be able to get a list of all of the unique values and their counts and sort them i...