algorithm

Mauritus national flag problem

I've made a solution for the Dutch national flag problem already. But this time, I want to try something more difficult: the Mauritus national flag problem - 4 colours, instead of 3. Any suggestions for an effective algorithm? Basically, The Mauritius National Flag Problem focuses on how you would be able to sort the given list of pair...

find duplicates in integer array with boundaries.

Below is the problem description and algorithm that I have written. Is there anything to be done to improve this algorithm? Given an integer array of unknown size, containing only numbers between 0 and 30, write a function to return an integer array containing all of the duplicates. int[] findDupes(int[] array) { int[] found = new ...

What is the most efficient way to generate unique pseudo-random numbers?

Possible Duplicate: Create Random Number Sequence with No Repeats I'm trying to generate unique session IDs. Each session ID is a random integer. The main requirement is that each session ID is unique. I'm trying to find the most efficient algorithm to do this. Scenario: Generate 10 random numbers from 1 to 10 inclusive. My...

HDR image creating algorithm

Hi Do you know any algorithm to create HDR images, like photomatix or photoshop "merge hdr" function? ...

best search algo

What is the best search algo that has least worst case of execution time and is memory efficient. I'm looking for a data structure that can store lots of data within least memory possible and also is quickest to search for any item. This is for a scenario where i have few entries of form say A(name,value) pairs. and there are other entri...

insert, delete, max in O(1)

Can someone tell me which data structure supports insert/delete/maximum operation in O(1) ? Thanks Ram ...

Need advice on how to better code this function for frequent re-use and adding new functionalities

Hi, I need help to better simplify this process. In order to fully comprehend how everything fits together please refer to my previous post - My Web based system Basically, I want to send more commands to this procedure that I have written. Write now there is only one function I have implemented, detect, but I want to add more in the fu...

Performance Characteristics of Fundamental Operations for Computational Estimation of Algorithmic Complexity

I've made a compiler for a general-purpose programming language. As part of the toolchain, I'd like to include a profiler with the ability to estimate the time complexity of a given expression. It seems fairly straightforward to calculate the algorithmic complexitythat is, assuming all constant-time operations take the same amount of tim...

Calculate coordinates of a regular polygon's vertices

I am writing a program in which I need to draw polygons of an arbitrary number of sides, each one being translated by a given formula which changes dynamically. There is some rather interesting mathematics involved but I am stuck on this probelm. How can I calculate the coordinates of the vertices of a regular polygon (one in which all ...

evaluate whether a number is integer power of 4

The following function is claimed to evaluate whether a number is integer power of 4. I do not quite understand how it works? bool fn(unsigned int x) { if ( x == 0 ) return false; if ( x & (x - 1) ) return false; return x & 0x55555555; } ...

Finding the correlation matrix

Hi, I have a matrix which is fairly large (around 50K rows), and I want to print the correlation coefficient between each row in the matrix. I have written Python code like this: for i in xrange(rows): # rows are the number of rows in the matrix. for j in xrange(i, rows): r = scipy.stats.pearsonr(data[i,:], data[j,:]) ...

.NET Framework - Any way to get Dictionary<> to be a little faster?

I'm doing a Dictionary<> lookup in an O(n^2) loop and need it to be ridiculously fast. It's not. Does anyone have any insight into how Dictionary<> is implemented? I'm testing Dictionary performance with an isolated test case after running my code through a profiler and determining Dictionary lookups are the bulk of the CPU time.. My...

Complex process of making a typical Housie/Bingo game ticket?

Hello Everyone, I'm trying to create a typical Housie/Bingo Game ticket in Asp.net 2.0 (VB). But, not being succeeded. Ticket contains 3 row with 9 columns. Total 27 blocks, and it must be only 15 should be fill outta those 27. and each column contains value like 1st column should be between 1-10 and 2nd must have random values between 1...

Video Url Resolver for dailymotion and blip.tv

I'm stuck in getting the direct link of the video file on dailymotion and blip.tv website. Ex: direct video url of http: //www.dailymotion.com/video/x96bku_the-forest-short-animation-film_shortfilms is http: //proxy-36.dailymotion.com/video/684/114/15411486%3amp4_h264_aac_hq.mp4?auth=1281348558-2a834e9c8537ef9c8301dcae7c5c565a http: //b...

Determining whether point A needs to cut a corner to get to point B

I am looking for an efficient way to check if an object will cut a corner to get from point A to point B or prevent the object from moving from point A to point B if there is a diagonal unwalkable position in between. What is known: Every point is a square of width and height 1 Every point has a list of its 8 adjacent points A point c...

Algorithm for calculating result of multi-choice quiz

I'm struggling with the edge cases of an algorithm for calculating the result of an A, B, C style quiz. The quiz is made up of an arbitrary number of questions, each having exactly 3 answers corresponding to A, B and C. Each question is displayed on its own with a continue button, once all questions have been answered the result is disp...

Finding the lowest unused unique id in a list

Say there's a list. Each item in the list has a unique id. List [5, 2, 4, 3, 1] When I remove an item from this list, the unique id from the item goes with it. List [5, 2, 3, 1] Now say I want to add another item to the list, and give it the least lowest unique id. What's the easiest way to get the lowest unique id when adding ...

Where has this cluster search algorithm been presented before?

See: http://kks.cabal.fi/GoodEnoughSearch I have gone through quite many papers and sites. I have not found where this algorithm has been presented before, or that someone has made something similar, but better or more general. The algorithm is pretty simple and thus should be found quite easily by anyone facing the same kind of problem...

What is the difference in rebuilding an index on index-organized table and an ordinary table?

From this article about index organized tables, Note that rebuilding a secondary index on an index-organized table involves reading the base table, unlike rebuilding an index on an ordinary table. Why does rebuilding of an index on an ordinary table not require reading the base table? ...

Finding text content references in MySQL database.

Hi. There's a site containing dozens of text snippets, each of them may have links and I need to build connections between snippets. Snippets are stored in database, database layout is following: snippet: id primary key, title varchar(255), url varchar(400), body text references: snippet_id, crc32_sum backlinks: snippet_id, links_to p...