data-structures

What are some alternatives to a bit array?

I have an information retrieval application that creates bit arrays on the order of 10s of million bits. The number of "set" bits in the array varies widely, from all clear to all set. Currently, I'm using a straight-forward bit array (java.util.BitSet), so each of my bit arrays takes several megabytes. My plan is to look at the cardina...

One or Two Primary Keys in Many-to-Many Table?

I have the following tables in my database that have a many-to-many relationship, which is expressed by a connecting table that has foreign keys to the primary keys of each of the main tables: Widget: WidgetID (PK), Title, Price User: UserID (PK), FirstName, LastName Assume that each User-Widget combination is unique. I can see two...

What are good alternative data formats to XML?

XML, granted, is very useful, but can be quite verbose. What alternatives are there and are they specialised for any particular purpose? Library support to interrogate the contents easily is a big plus point. ...

What are you currently using for data access?

What particular method/application are you using to communicate between your application and a database? Custom code with stored procedures? SubSonic? nHibernate? Entity Framework? LINQ? ...

Fundamental Data Structures in C#

I would like to know how people implement the following data structures in C# without using the base class library implementations:- Linked List Hash Table Binary Search Tree Red-Black Tree B-Tree Binomial Heap Fibonacci Heap and any other fundamental data structures people can think of! I am curious as I want to improve my understa...

Algorithm/Data Structure Design Interview Questions

What are some simple algorithm or data structure related "white boarding" problems that you find effective during the candidate screening process? I have some simple ones that I use to validate problem solving skills and that can be simply expressed but have some opportunity for the application of some heuristics. One of the basics tha...

Linked List in SQL

Whats the best way to store a linked list in a mysql database so that inserts are simple (i.e. you dont have to reindex a bunch of stuff every time) and such that the list can easily be pulled out in order. ...

Tree data structure in C#

I was looking for a tree or graph data structure in C# but I guess there isn't one provided. http://msdn.microsoft.com/en-us/library/ms379574.aspx explains a bit about why. Is there a convenient library which is commonly used to provide this functionality? Perhaps through a strategy pattern to solve the issues presented in the article....

Using Stack as Queue

Suppose we have two stacks and no other temporary variable . Is to possible to use it as a queue provided we have associated API i.e push,pop for stack and insert and remove for queue operations. ...

Deleting a middle node from a single linked list when pointer to the previous node is not available

Is it possible to delete a middle node in the single linked list when the only information available we have is the pointer to the node to be deleted and not the pointer to the previous node?After deletion the previous node should point to the node next to deleted node. ...

Open-source radix/mtrie implementation in C?

I intend to use RADIX / MTRIE as my preferred data-structure for a routing implementation. I would like to know if there's a decent open source implementation available (apart from freebsd-net) which I can use for my purpose, or do I need to write one myself. ...

Spatial Data Structures in C

I do work in theoretical chemistry on a high performance cluster, often involving molecular dynamics simulations. One of the problems my work addresses involves a static field of N-dimensional (typically N = 2-5) hyper-spheres, that a test particle may collide with. I'm looking to optimize (read: overhaul) the the data structure I use ...

Retrieve all nodes in a tree that are children of another one

(Before you down mod it: nope, this is not homework) I have a web system which has a classical parent-children menu saved in a database, with fields id as the PK, and parent_id to pointing to the owning menu. (Yes, I know this doesn't scale very well, but that's another topic). So for these records (id-parent_id pairs): 0-7 0-4 4-9 4...

Is there a more efficient text spooler than TextWriter/StringBuilder

For a situation like capturing text incrementally, for example if you were receiving all of the output.write calls when a page was rendering, and those were being appended into a textwriter over a stringbuilder. Is there a more efficient way to do this? Something that exists in dotnet already preferably? Especially if there's a total si...

'Looser' typing in C# by casting down the inheritance tree

The question I want to ask is thus: Is casting down the inheritance tree (ie. towards a more specialiased class) from inside an abstract class excusable, or even a good thing, or is it always a poor choice with better options available? Now, the example of why I think it can be used for good. I recently implemented Bencoding from the ...

Is there a specific name for the node that coresponds to a subtree?

I'm designing a web site navigation hierarchy. It's a tree of nodes. Nodes represent web pages. Some nodes on the tree are special. I need a name for them. There are multiple such nodes. Each is the "root" of a sub-tree with pages that have a distinct logo, style sheet, or layout. Think of different departments. What should I name...

How to get all datatype sizes and function stack footprint sizes in a C/C++ project?

I have a large inherited C/C++ project. Are there any good tools or techniques to produce a report on the "sizeof" of all the datatypes, and a breakdown of the stack footprints of each function in such a project. ...

The best way to start working on other people's code

I'm looking into adding some features to an open source packages and I would like to know your advices, experiences at "getting into" other people's code. I obviously already did the following, reading the most relevant part of the code, step debugging, having a good knowledge of the data* processed , generated documentation & graph thr...

What's the best way of using a pair (triple, etc) of values as one value in C#?

That is, I'd like to have a tuple of values. The use case on my mind: Dictionary<Pair<string, int>, object> or Dictionary<Triple<string, int, int>, object> Are there built-in types like Pair or Triple? Or what's the best way of implementing it? Update There are some general-purpose tuples implementations described in the answers,...

Priority queue in .Net

I am looking for a .Net (preferably C#) implementation of a priority queue or heap. Unless I am looking in the wrong place, there isn't one in the framework. Is anyone aware of a good one, or should I roll my own? ...