data-structures

Data model for storing categories (multiple parent nodes)

I've the following category structure: - Transport (10) - Cars (5) - Audi (2) - BMW (3) - ... - Spare Parts (5) - Audi (5) - Audi glass (1) - Carburetors (4) - Mirrors - ... - Buses - Spare Parts (5) - Audi (5) - Audi glass (1...

Sort an array of structures in .NET

This is one of those times when only the hive mind can help - no amount of Google-fu can! I have an array of structures: Structure stCar Dim Name As String Dim MPH As Integer Sub New(ByVal _Name As String, ByVal _MPH As Integer) Name = _Name MPH = _MPH End Sub End Structure How do I sort the array on...

The Fastest DataStructure to Filter with in C#

Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary> /// <param name="dtInput">The dt input.</param> /// <param name="filterExpression">The filter expression.</param> /// <returns></returns>...

What data structures can I use to represent a strongly-typed 2D matrix of data in .Net?

I'm trying to represent a scoreboard for a competition and am struggling with the best data structures to use. I have a list of Player objects, a list of Round objects, and for each combination, I need to store a RoundScore object (there are various parts to the score for a round). What I'd like is some overall Scoreboard object where ...

How to implement a double linked list with only one pointer?

How to implement a double linked list with only one pointer? It takes O(1) time to find the prev and next Node. struct Node { int val; Node* p; }; ...

Alarm history stack or queue?

I'm trying to develop an alarm history structure to be stored in non-volatile flash memory. Flash memory has a limited number of write cycles so I need a way to add records to the structure without rewriting all of the flash pages in the structure each time or writing out updated pointers to the head/tail of the queue. Additionally once...

passing array of structs from c# to regular dll

Hi there I have a regular dll with the followign fucntion exported. extern "C" __declspec(dllexport) int FindNearestStuff(double _latitude, double _longitude , LocationStruct * locations[]) LocationStruct is very simple struct LocationStruct { long positionIndex; long item; }; I'm tryign to call it from c# using [DllIm...

Binary Tree Nodes - Which Way?

For an assignment we were given in Data Structures, we had to create a test class to determine whether the code we were given correctly traversed the binary trees in our test class. These are the 3 constructors for BinaryTreeNode class that was given to us: public BinaryTreeNode(Object theElement, BinaryTreeNode theleftChild, BinaryTre...

Rendering different repeating data

What is the best method to display repeating data with slightly different controls or sub data? For example displaying an expanded list of questions and answers. Some questions will have answers, some will not. Some button controls would show for some items while not for others. In classic ASP I've used XML/XSL quite effectively fo...

How to: Parallel Reduction of many unequally sized arrays in CUDA?

Hi there I am wondering if anyone could suggest the best approach to computing the mean / standard deviation of a large number of relatively small but differently sized arrays in CUDA? The parallel reduction example in the SDK works on a single very large array and it seems the size is conveniently a multiple of the number of threads p...

Most efficient way to insert two rows that depend on each other.

I have a site that is essentially a collection of links. A mysql database which stores users, links and votes. My links table has two foreign keys, user_id and vote_id. When a link is inserted into the database it will start with one vote so that means I need to insert a row into the votes table but they essentially depend on one anot...

Hashtable indexed on several fields

Hello SO, I'm currently programming an OCaml module defining a type corresponding to a CPU register. The interface of this module is the following : (* * Defines a type which represents a R3000 register. *) type t = | R0 (* Always 0 *) | AT (* Assembler te...

How do I determine which kind of tree data structure to choose?

Ok, so this is something that's always bothered me. The tree data structures I know of are: Unbalanced binary trees AVL trees Red-black trees 2-3 trees B-trees B*-trees Tries Heaps How do I determine what kind of tree is the best tool for the job? Obviously heaps are canonically used to form priority queues. But the rest of them j...

Python data structure/object to model static multidimensional table

I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree. Example Form hierarchy: MyForm Question 1 Part 1 Question 1.1 Part 2 Question 2.1 SubPart 1 Question 2.1.1 Question 2.1.2 Q...

Ideal data structure for mapping integers to integers?

I won't go into details, but I'm attempting to implement an algorithm similar to the Boyer-Moore-Horspool algorithm, only using hex color values instead of characters (i.e., there is a much greater range). Following the example on Wikipedia, I originally had this: size_t jump_table[0xFFFFFF + 1]; memset(jump_table, default_value, sizeo...

Is there a .NET data structure with the following characteristics of a Binary Search Tree?

I know that SortedDictionary is a binary search tree (and it can almost do what I need to do!) but I can't figure out how to do everything I need in the correct complexity. So here are the constraints (and the data structure which I know has it) Inserting and Deletion in O(log n) (SortedDictionary) Search in O(log n) (SortedDictionary...

Independent MVC structure... need an advice

hi, I'm tired of looking after a frame work for mvc implementation. i want to build a good MVC based structure of my own that will serve me in my projects. so here is my thinking I'd like to know what do you think. first of all. here is the folder structure: The folder structure the Admin and the Site folders: I assume that the contro...

Do all Hash-based datastructures in java use the 'bucket' concept?

The hash structures I am aware of - HashTable, HashSet & HashMap. Do they all use the bucket structure - ie when two hashcodes are similar exactly the same one element does not overwrite the other, instead they are placed in the same bucket associated with that hashcode? ...

Heap Implementations

In a heap implementation of the ADT priority queue, the item with the highest priority value is always in the front or root of the array? Or is it, where the ADT priority queue that has the highest priority value is in the n-1 slot of the array? ...

Finding the index of an entry in a linked list in better than O(n) time...

I have a scenario where I'm pushing change-lists to another system. Each list contains zero or more inserted, updated or deleted notifications. Inserting is easy; the notification contains the target index and a pointer to the item. Updating is easy; I pass a pointer to the item. Deleting seems straight-forward; I need to pass the ...