data-structures

New approach for adding a new Node to a Linked List

void addNewNode (struct node *head, int n) { struct node* temp = (struct node*) malloc(sizeof(struct node)); temp -> data = n; temp -> link = head; head = temp; } The code give above is the popularly wrong version of a function for adding a new node at the head of a linked list. Generally the correct versions are like, ...

When I iterate through a Dictionary (.NET generic data structure) will it be in the same order that I added them?

I have a dictionary that I normally access with a key, so I need fast random access reads. However for one function I need to process every item in the dictionary where the order is important. It seems to be working OK in tests. Is it OK to depend on the order of items in a dictionary? ...

Storing large numbers of varying size objects on disk

I need to develop a system for storing large numbers (10's to 100's of thousands) of objects. Each object is email-like - there is a main text body, and several ancillary text fields of limited size. A body will be from a few bytes, to several KB in size. Each item will have a single unique ID (probably a GUID) that identifies it. ...

Converting a List of Tuples into a Dict in Python

Hi, I have a list of tuples like this: [ ('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('c', 1), ] I want to iterate through this keying by the first item, so for example I could print something like this: a 1 2 3 b 1 2 c 1 How would I go about doing this without keeping an item to track whether the first item is the same as I...

Concurrent data structure design

I am trying to come up with the best data structure for use in a high throughput C++ server. The data structure will be used to store anything from a few to several million objects, and no sorting is required (though a unique sort key can be provided very cheaply). The requirements are that it can support efficient insert, ideally O(1),...

How can I get a list of the differences between two JavaScript object graphs?

I want to be able to get a list of all differences between two JavaScript object graphs, with the property names and values where the deltas occur. For what it is worth, these objects are usually retrieved from the server as JSON and typically are no more than a handful of layers deep (i.e. it may be an array of objects that themselves...

What is an "internal node" in a binary search tree?

I'm scouring the internet for a definition of the term "Internal Node." I cannot find a succinct definition. Every source I'm looking at uses the term without defining it, and the usage doesn't yield a proper definition of what an internal node actually is. Here are the two places I've been mainly looking: http://planetmath.org/encyclop...

C# Collection Data Structure With 1:1 Key/Value Mapping

Are there any built-in C# data structures that are like a hash table but requires both the Keys and the Values to be unique among each other? I basically want a way to look up my Key object in a table via a unique Value and vice-versa. Next to maintaining two hash tables or iterating over each key in the hash table (which is slow), I can...

Difference between a HashMap and a dictionary ADT

What is the difference between a Hash Map and dictionary ADT. And when to prefer one over another. For my programming assignment my instructor has asked to use one of them but I don't see any difference in between both. The program is supposed to work with a huge no. of strings. Any suggestions? ...

Default HashMap probing in Java

What does Java use as a default probing method for HashMap? Is it Linear? Chaining or something else? ...

Difference between a LinkedList and a Binary Search Tree

What are the main differences between a Linked List and a BinarySearchTree? Is BST just a way of maintaining a LinkedList? My instructor talked about LinkedList and then BST but did't compare them or didn't say when to prefer one over another. This is probably a dumb question but I'm really confused. I would appreciate if someone can cla...

Data structure for soundex algorithm?

Can anyone suggest me on what data structure to use for a soundex algorithm program? The language to be used is Java. If anybody has worked on this before in Java. The program should have these features: be able to read about 50,000 words should be able to read a word and return the related words having the same soundex I don't want t...

LinkedList remove method

What is a doubly linked list's remove method? ...

What is a data structure kind of like a hash table, but infrequently-used keys are deleted?

I am looking for a data structure that operates similar to a hash table, but where the table has a size limit. When the number of items in the hash reaches the size limit, a culling function should be called to get rid of the least-retrieved key/value pairs in the table. Here's some pseudocode of what I'm working on: class MyClass { ...

what is an rdf triple?

what is an RDF TRIPLE in laymens terms please.... ...

Does a DataTable consume more memory than a List<T>?

Is there a trade off in respect to performance, trade off in respect to memory consumption? ...

What is the best structure to implement an Identity Map?

Although a DataTable is a memory hog, wouldn't a DataTable be the best choice to implement and IdentityMap if the set of objects is very large since retrieval time is O(1)? Update If I decide to use IDictionary, do I sacrifice speed when retrieving my objects? ...

Feasibility of LinkedList vs. Array for sorted vs. unsorted data?

Comparing LinkedLists and Arrays while also comparing their differences with sorted and unsorted data Adding Removing Retrieving Sorting Overall speed Overall memory usage Actual questions Discuss the feasibility of implementing an unsorted data set as a linked list rather than an array. What would the tradeoffs be in terms of...

Hash Functions and Tables of size of the form 2^p

While calculating the hash table bucket index from the hash code of a key, why do we avoid use of remainder after division (modulo) when the size of the array of buckets is a power of 2? ...

What are the benefits of an XML data model over the DataSet model?

At my current job we have a CMS system that is .NET/SQL Server based. While customizing a couple of the modules for some internal use, I was a little surprised to see that instead of having APIs that returned data via your typical result set that was bound to a DataGrid/DataList/Repeater control, that the APIs returned an XML node/collec...