algorithm

Ternary Tree Vs Hash Table

I need to know if a ternary tree is better than a hash table. I came across this question in a reply to another question I had where someone said that ternary trees are often faster than hash tables. I found that hard to believe, so I decided to research a little into it. This one website from Princeton appears to be the source of the...

Given numbers from 1 to 2^32-1, one is missing. How to find the missing number optimally?

You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It's impossible to fit all the numbers into memory (thus sorting is not an option). You are asked to find the missing number. What would be the best approach to this problem? Edit: Let's assume you cannot use big-integers and are confined to 32bit ints. ints are passed in...

Address Match Key Algorithm

I have a list of addresses in two separate tables that are slightly off that I need to be able to match. For example, the same address can be entered in multiple ways: 110 Test St 110 Test St. 110 Test Street Although simple, you can imagine the situation in more complex scenerios. I am trying to develop a simple algorithm that will ...

Distribution of user accounts to N tables

There are millions of user accounts, and I want to distribute their data into N tables(user_1, user_2,..., user_N) of a database. User accounts are comprised of 3~8 characters. So, I want a function that returns table suffix like int getTableSuffix(String userAccount); The result is a uniform distribution from 1 to N. Do you kno...

Run time to insert n elements into an empty hash table

People say it takes amortized O(1) to put into a hash table. Therefore, putting n elements must be O(n). That's not true for large n, however, since as an answerer said, "All you need to satisfy expected amortized O(1) is to expand the table and rehash everything with a new random hash function any time there is a collision." So: what ...

Suggestions for KSPA on undirected graph

Hello Group, There is a custom implementation of KSPA which needs to be re-written. The current implementation uses a modified Dijkstra's algorithm whose pseudocode is roughly explained below. It is commonly known as KSPA using edge-deletion strategy i think so. (i am a novice in graph-theory). Step:-1. Calculate the shortest path bet...

Polygon enclosing a set of points

Hello folks, I have a set S of points (2D : defined by x and y) and I want to find P, the smallest (meaning : with the smallest number of points) polygon enclosing all the points of the set, P being an ordered subset of S. Are there any known algorithms to compute this? (my lack of culture in this domain is astonishing...) Thanks for ...

what would you do in a chessboard? (piece position)

would you create 3 list(of coordinate) for empty position black position white position or just looping though the array when needed and play with the result every time? what would be best? (speed wise) ...

Testing for repeated characters in a string

I'm doing some work with strings, and I have a scenario where I need to determine if a string (usually a small one < 10 characters) contains repeated characters. `ABCDE` // does not contain repeats `AABCD` // does contain repeats, ie A is repeated I can loop through the string.ToCharArray() and test each character against every oth...

Clustering Algorithm with discrete and continuous attributes?

Does anyone know a good algorithm for perform clustering on both discrete and continuous attributes? I am working on a problem of identifying a group of similar customers and each customer has both discrete and continuous attributes (Think type of customers, amount of revenue generated by this customer, geographic location and etc..) Tr...

How to get the highest value from a Delphi set?

Is there any way to extract the highest (or lowest) value in a set? For example, if I have the following "set of byte": [0, 1, 2, 4, 5, 28, 199] is there any function I could run on that and get back 199 as the result? EDIT: There's an obvious brute-force solution involving a for..in loop. If possible, I'd like to find a better way...

Making a Grid in GTK+

I'm not asking for a code implementation, but given GTK+'s skillset, what would be from an abstract perspective the best way to implement a grid such that each square is clickable and the like? ...

What's a bubble sort?

What is a bubble sort? Can someone help me? Edit- See also this earlier question: What is a Bubble Sort good for? Although very similar, "What is a bubble sort?" is a more fundamental question and is therefore still useful for beginners to programming. ...

Line intersection

How to find whether a line intercepted in a polygon ...

Controlling the sort order of a list from an admin UI

Hi I have a list of data that users are able to control the sort order of. It looks something like this Apples /\ \/ Oranges /\ \/ pears /\ \/ banana /\ \/ Pineapples /\ \/ etc /\ \/ the /\ and \/ are meant to be up and down arrows When the user clicks up i want to retrieve the current sort order and ta...

Algorithms: Interesting diffing algorithm.

This came up in a real-world situation, and I thought I would share it, as it could lead to some interesting solutions. Essentially, the algorithm needs to diff two lists, but let me give you a more rigorous definition of the problem. Mathematical Formulation Suppose you have two lists, L and R each of which contain elements from some...

What are good books for Computation Geometry?

I am familiar with O'Rourke's Computational Geometry in C, but it feels a little dated. Any recommendations for books, preferably with source code? ...

small cycle finding in a planar graph

I have a geometric undirected planar graph, that is a graph where each node has a location and no 2 edges cross, and I want to find all cycles that have no edges crossing them. Are there any good solutions known to this problem? What I'm planning on doing is a sort of A* like solution: insert every edge in a min heap as a path exte...

Need to store string as id for objects in some fast data structure

I'm implementing a session store for a web-server. Keys are string and stored objects are pointers. I tried using map but need something faster. I will look up an object 5-20 times as frequent than insert. I tried using hash-map but failed. I felt like I got more constraints than more free time. I'm coding c/c++ under Linux. I don't...

Algorithm for finding nearby points?

Given a set of several million points with x,y coordinates, what is the algorithm of choice for quickly finding the top 1000 nearest points from a location? "Quickly" here means about 100ms on a home computer. Brute force would mean doing millions of multiplications and then sorting them. While even a simple Python app could do that in ...