data-structures

Filling up a TreeView control

OK this is going to sound hilarious but still I have a class like so class TermNode { public string Name; public string Definition; public List<TermNode> Children } So this is a N-Ary non sorted in any way Tree. A node can have 0-N children OK so given this data structure how will you fill up a tree View with it Assume you ...

What algorithm does Excel use to recalculate formulas?

Are the formulas represented in an AST then recalculated using a design pattern like the Visitor pattern? How would you go about reproducing the recalculation process in code? ...

How can I create multidimensional arrays in Perl?

Hello, I am a bit new to Perl, but here is what I want to do: my @array2d; while(<FILE>){ push(@array2d[$i], $_); } It doesn't compile since @array2d[$i] is not an array but a scalar value. How sould I declare @array2d as an array of array? Of course, I have no idea of how many rows I have. ...

LINQ grouping/subquery to fill a hierarchy data strcuture

I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan 3.............4...........Tim What I'm trying to do is write a LINQ statement that will return an array of UserGroup instances. The UserGroup class h...

How do I find all paths through a set of given nodes in a DAG?

I have a list of items (blue nodes below) which are categorized by the users of my application. The categories themselves can be grouped and categorized themselves. The resulting structure can be represented as a Directed Acyclic Graph (DAG) where the items are sinks at the bottom of the graph's topology and the top categories are sourc...

When to use LinkedList<> over ArrayList<>?

I've always been one to simply use List<String> names = new ArrayList<String>(); I use the interface as the type name for portability, so that when I ask questions such as these I can rework my code. When should LinkedList be used over ArrayList and vice-versa? ...

Splitting a linked list

Why are the split lists always empty in this program? (It is derived from the code on the Wikipedia page on Linked Lists.) /* Example program from wikipedia linked list article Modified to find nth node and to split the list */ #include <stdio.h> #include <stdlib.h> typedef struct ns { int data; struct ns *next; /* p...

How to update C# hashtable in a loop?

I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. private Hashtable htSettings_m = new Hashtable(); htSettings_m.Add("SizeWidth", "728"); htSettings_m.Add("SizeHeight", "450"); string sKey = ""; string sValue = ""; foreach (D...

Memory Efficient Alternatives to Python Dictionaries

In one of my current side projects, I am scanning through some text looking at the frequency of word triplets. In my first go at it, I used the default dictionary three levels deep. In other words, topDictionary[word1][word2][word3] returns the number of times these words appear in the text, topdictionary[word1][word2] returns a dictio...

How are Python's Built In Dictionaries Implemented

The topic title pretty much says it all. Does anyone know how the built in dictionary type for python is implemented? My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer. ...

Where can I learn how to combine algorithms and data structures ?

After reading an introductory book on algorithms and data structures I am now craving for examples on how to combine these for optimal efficiency. For instance, you can combine hashmaps with specific sorting algorithms to create a simple text search program. Is there any good book or online resource for this? (I have already ordered P...

Data Structure Brushup (Java)

This should be easy for many of you, but for me it's just another bit of rust needing to be chipped away as I get back into basic Java coding. Using bloody associative arrays for so long in other languages have turned me nice and spoiled. :P My problem is simple: I'm storing a set of objects, each containing a string and a number, in a...

Want to save binary tree to disk for "20 questions" game

In short, I'd like to learn/develop an elegant method to save a binary tree to disk (a general tree, not necessarily a BST). Here is the description of my problem: I'm implementing a game of "20-questions". I've written a binary tree whose internal nodes are questions and leaves are answers. The left child of a node is the path you'd...

Why use hashing to create pathnames for large collections of files?

Hi, I noticed a number of cases where an application or database stored collections of files/blobs using a has to determine the path and filename. I believe the intended outcome is a situation where the path never gets too deep, or the folders ever get too full - too many files (or folders) in a folder making for slower access. EDIT: E...

C data structure to mimic C#'s List<List<int>>?

I am looking to refactor a c# method into a c function in an attempt to gain some speed, and then call the c dll in c# to allow my program to use the functionality. Currently the c# method takes a list of integers and returns a list of lists of integers. The method calculated the power set of the integers so an input of 3 ints would pr...

How to work with pointer to pointer to structure in C?

Hi, I want to change member of structure under double pointer. Do you know how? Example code typedef struct { int member; } Ttype; void changeMember(Ttype **foo) { //I don`t know how to do it //maybe *foo->member = 1; } Thanks for any help. ...

How to find "equivalent" texts?

I want to find (not generate) 2 text strings such that, after removing all non letters and ucasing, one string can be translated to the other by simple substitution. The motivation for this comes from a project I known of that is testing methods for attacking cyphers via probability distributions. I'd like to find a large, coherent plai...

Looking for C++ STL-like vector class but using stack storage

Before I write my own I will ask all y'all. I'm looking for a C++ class that is almost exactly like a STL vector but stores data into an array on the stack. Some kind of STL allocator class would work also, but I am trying to avoid any kind of heap, even static allocated per-thread heaps (although one of those is my second choice). Th...

Reversing a Linked List in Java, recursively

I have been working on a Java project for a class for a while now. It is an implementation of a linked list (here called AddressList, containing simple nodes called ListNode). The catch is that everything would have to be done with recursive algorithms. I was able to do everything fine sans one method: public AddressList reverse() L...

Algorithm for detecting "clusters" of dots

I have a 2D area with "dots" distributed on this area. I now am trying to detect "clusters" of dots, that is, areas with a certain high density of dots. Any thoughts on (or links to articles with thoughts on) how to elegantly detect these areas? ...