algorithm

stability of quicksort!

Dont you peaple think that quicksort is stable if follow following algo for partitioning the array: partition(A,p,r) { x=A[r]; i=p-1; for j=p to r-1 if(A[j]<=x) i++; exchange(A[i],A[j]) exchang(A[i+1],A[r]); return i+1; } Regards!! ...

Natural sort algorithm implementation woes

I have Googled ASP Classic implementations of the natural sort algorithm to no avail. Best I was able to find was from Dave Koelle, which was from a question on SO. Issue is that since I need to implement this algorithm in ASP Classic, I don't have access to certain functions such as Collections.sort(your list, new AlphanumComparator())...

Algorithm to map Numbers to Hex Colors

Hi all, Here's my situation. Say I have two columns of data containing different elements. I'd like to highlight with a different color, all matching elements between those two columns. Each of those elements has an ID, so I was thinking of creating a mapping function to tie an ID to a hex color. Any suggestions? This is what I...

Algorithm for determining Alignment of elements in C/C++ structs

Okay, Allow me to re-ask the question, as none of the answers got at what I was really interested in (apologies if whole-scale editing of the question like this is a faux-paus). A few points: This is offline analysis with a different compiler than the one I'm testing, so SIZEOF() or similar won't work for what I'm doing. I know it's i...

Distribution algorithm for given set of numbers and intervals

I'm in search of an algorithm, which can handle the problem described below. I already have written an algorithm (which is too specialised to post, I think), optimised as much as I could think of, but on larger sets of numbers it still is too slow (as the costs rise exponentially). The solution should take no longer than 5s on a decent c...

Mysql results sorted by list which is unique for each user

Ive got a table of thousands of products and 50 or so authenticated users. These users all show the products on their own web sites and they all require the ability to have them ordered differently. Im guesing i need some kind of seperate table for the orders which contains the product_id, user_id and order column? How do i do this t...

Algorithms for finding similar questions based on another question's title?

For example, every time I post I question on stackoverflow.com, the UI suggest me plenty of similar questions. How is it functionality implemented? Are there some well-written algorithms about this? ...

how to test a prime number 1000 digits long?

Hi, I am trying to find whether number is prime or not for 1000 digit long. Algorithm i am thinking to use is 6k+/-1 problem i am facing is how can i store such a long number in java, it is taken string as input. or for doing divisibility should is consider only the last few digits of the number. please advise ...

Where can I learn more about datastructure tricky questions?

I am relatively new to programming (around 1 year programming C#-winforms). Also, I come from a non CS background (no formal degree) Recently, while being interviewed for a job, I was asked about implementing a queue using a stack. I fumbled and wan't able to answer the question. After, the interview I could do it(had to spend some tim...

Data structure for designing a cache with efficient insertion,deletion and the retrieval of highest value

I have to implement a cache with normal cache operations along with the facility of fast retrieval of the maximum element from the cache. Can you please suggest data structures to implement this? I was thinking of using hash map along with a list to maintain the minimum element. Suggest other approaches with better complexity. ...

Algorithm for copying N bits at arbitrary position from one int to another

An interesting problem I've been pondering the past few days is how to copy one integer's bits into another integer at a given position in the destination integer. So, for example, given the destination integer 0xdeadbeef and the source integer 0xabcd, the idea would be to get a result of 0xabcdbeef (given a destination position of 16 bi...

Give array of numbers, find out if 3 of them add up to 0

Do it in N^2, how would one do this ...

What do i need to know about dynamic programming?

Started up solving UVa problems again as a way to pass time (going to the army in 6 weeks). I love writing Java, but end up using C / C++. It's not because IO is faster, no need to box data, more memory or use of unsigned, because its algorithm efficiency that counts. In short i am slowly constructing how to/article/code base for differ...

Searching a nested set

I've got a MySQL table that acts like a nested set in order to contain a hierarchy of categories. The table schema looks like: CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL auto_increment, `name` varchar(200) NOT NULL, `parent_id` int(11) default NULL, `lft` int(11) default NULL, `rgt` int(11) default NULL, ...

What's the optimal way to compute a hashcode for a set of points?

I'm looking for the optimal way to compute a hashcode for a set of bi-dimensional points (so that I can store polygons in a hashtable). There are some obvious ways to do that, such as concatenating all the points coordinates in a string and its hashcode, but this would be very slow. On the other end of the speed/collision spectrum, I c...

Efficient Algorithm for String Concatenation with Overlap

We need to combine 3 columns in a database by concatenation. However, the 3 columns may contain overlapping parts and the parts should not be duplicated. For example, "a" + "b" + "c" => "abc" "abcde" + "defgh" + "ghlmn" => "abcdefghlmn" "abcdede" + "dedefgh" + "" => "abcdedefgh" "abcde" + "d" + "ghlmn" => "abcdedghlmn" "abcdef...

how do you remove a cycle in a single linked list?

I am not sure how would I find the start of the cycle without using O(N) memory and flags ...

Manhattan layout algorithm

I am looking for any of the following (in order of preference): A Manhattan layout EdgeRenderer for prefuse. A Manhattan layout for prefuse. An algorithm to produce Manhattan layouts for hierarchical, directed acyclic graphs. An organizational chart implementation. Sample implementations include: NodeLinkTreeLayout (for prefuse) is...

How can I find islands in a randomly generated hexagonal map?

I'm programming a Risk like game in Codigniter and JQuery. I've come up with a way to create randomly generated maps by making a full layout of tiles then deleting random ones. However, this sometimes produces what I call islands. In risk, you can only attack one space over. So if one player happens to have an island all to them self, t...

Where can i find sample alogrithms for analyzing historical stock prices?

Hi guys, Can anyone direct me in the right direction? Basically, I'm trying to analyze stock prices and see if I can spot any patterns. I'm using PHP and MySQL to do this. Where can I find sample algorithms like the ones used in MetaStock or thinkorswim? I know they are closed source, but are there any tutorials available for beginners...