data-structures

How to use KDTree to make top-k query and range query on arbitrary dimensions

Hi, I have used KD-tree(libkdtree++) to store a multi-dimensional data set, and the requirements here is this data set can support top-k/range queries on different dimensions. For example, a KDTree<3, Point> tree: to find the top 100 points whose have highest Point[1](y axis) values. From the implementation of libkdtree++, what's sim...

Algorithm to find top 10 search terms

I'm currently preparing for an interview, and it reminded me of a question I was once asked in a previous interview that went something like this: "You have been asked to design some software to continuously display the top 10 search terms on Google. You are given access to a feed that provides an endless real-time stream of search term...

Multithreaded data structure : concurrent stack

Hi all, I'm looking for a C implementation of a concurrent stack (like Cilk THE protocol) that would allow the main thread to push and pop (the pop operation would be at the begining of the stack for example) and a distant thread to pop (this pop operation would be at the end of the stack) with every precaution that has to be taken. If...

Fastest data structure for contains() in Java?

What's the data structure in Java that has the fastest operation for contains() ? e.g. i have a set of numbers { 1, 7, 12, 14, 20... } Given another arbitrary number x, what's the fastest way (on average) to generate the boolean value of whether x is contained in the set or not? The probability for !contains() is about 5x higher. Do a...

I don't understand this Huffman algorithm implementation

template<class T> void huffman(MinHeap<TreeNode<T>*> heap, int n) { for(int i=0;i<n-1;i++) { TreeNode<T> *first = heap.pop(); TreeNode<T> *second = heap.pop(); TreeNode<T> *bt = new BinaryTreeNode<T>(first, second, first.data, second.data); heap.push(bt); } } In my Funda...

Implement an immutable deque as a balanced binary tree?

I've been thinking for a while about how to go about implementing a deque (that is, a double-ended queue) as an immutable data structure. There seem to be different ways of doing this. AFAIK, immutable data structures are generally hierarchical, so that major parts of it can be reused after modifying operations such as the insertion or ...

Array of undefinite length..

how to find a random element in a sorted array of unknown length. ...

which should be used: array vs linked list ?

I am planning to implement a bounded queue without using the Queue<T> class. After reading pros and cons of Arrays and LinkedList<T>, I am leaning more towards using Array to implement queue functionality. The collection will be fixed size. I just want to add and remove items from the queue. something like public class BoundedQueue<T>...

Is there a way to reduce the memory use of this queue?

In liberal C: /* i'm using this */ struct QueueItem { QueueItem* next; void* data; } struct Queue { QueueItem* head; QueueItem* tail; } /* +---+ +---+ |0 0| |* *| len 1 +---+ +|-|+ v v len +---+ 0 |d 0| +---+ +---+ |* *------...

C double linked list with abstract data type

Hello, i need in double linked list in C, but it must be for different types. In C++ we use templates for it. Where can i find example in C for double linked list with abstract types items. Thank you ...

Relational Data: entity inheritance approaches. Best practice

There are several approaches how to store entities hierarchy in relation database For example there is person entity (20 basic attributes), student entity (the same as person but several new specific fields are present), employee (the same as person but some new fields are present) e.t.c. When you advice to use (and not to use) the fo...

Efficient C# byte queue for parsing stream of bytes for binary message packets

Hi, I'm trying to replace what I would usually implement as a circular-buffer+. The function of the queue is to buffer incoming bytes (eg. from serial port or some other stream of data), whilst a parser examines bytes in the queue and detects and extracts message packets. Criteria: can grow (ie not fixed-sized) >= 1 bytes can be e...

Polymorphism in Clojure

Suppose I have a bunch of Clojure data structures, all of the same type - for example an object type defined by defrecord. What is the best way to get polymorphic behaviour across these structures? Would it be good practice to embed a function within the structure so that I can do something like: ((:my-method my-object) param1 param2)...

Best data structure for nearest neighbour in 1 dimension

I have a list of values (1-dimensional) and I would like to know the best data structure / algorithm for finding the nearest to a query value I have. Most of the solutions (all?) I found for questions here are for 2 or more dimensions. Can anybody suggest to me the approach for my case? My instinct tells me to sort the data and use bina...

How do I modify the Min Heap insert and delete function to accept a second comparison if the primary comparison happens to be equal?

below I have a standard insert and delete function for a Min Heap, what I need to do is add a special case to both the functions when the T.num comparison happen to be equal, I then need to then compare the T.Letter where the lower Ascii value is popped first. Without the comments is the standard insert and delete, add the commented sect...

Representation of a two way linked list

How to represent a two way(doubly) linked list? ...

Array Key in ColdFusion Structure

What is the proper syntax for creating a key within a ColdFusion structure which is an array? Preferably in the cfscript tags. To give a clearer idea of what I'm trying to do, here's what I thought it might be: StructInsert(account[i], "child[numChildren]", z); where "child" was supposed to be an array and numChildren was a counter i...

Data structure to store key-value pairs and retrive the key for the lowest value quickly

I'm implementing something like a cache, which works like this: If a new value for the given key arrives from some external process, store that value, and remember the time when this value arrived. If we are idle, find the oldest entry in the cache, fetch the new value for the key from external source and update the cache. Return the v...

What kind of data structure is this??

I am pulling recent commits from github and trying to parse it using ruby. I know that I can parse it manually but I wanted to see if there was some package that could turn this into a hash or another data structure. commits: - parents: - id: 202fb79e8686ee127fe49497c979cfc9c9d985d5 author: name: This guy login: tguy e...

Algorithm and data structure implementations for C programmers

Possible Duplicate: Are there any open source C libraries with common data structures? What is the best source of algorithm and data structure implementations for C programmers? Links to an open source library or a book will do. (Please don't point to Sedgewick, as I already have his book). ...