algorithm

Text difference patch

Hello, Am trying to write a piece of code which will allows the user to type text into a textbox which then gets saved on the server. When the user types some more text in the textbox, I want only the difference to be sent to the server. Is there a difference algorithm for JS which I can use to send only information about the differen...

Algorithm to find the duplicate numbers in an array ---Fastest Way

Hi, I need the fastest and simple algorithm which finds the duplicate numbers in an array, also should be able to know the number of duplicates. Eg: if the array is {2,3,4,5,2,4,6,2,4,7,3,8,2} I should be able to know that there are four 2's, two 3's and three 4's. Thanks in advance. ...

Please explain the algorithm for this problem from code jam 2009

This is problem from round 1B 2009 Problem C "Square Math". I know contest analysis is posted. But I am not getting on how to implement BFS when a node can be visited more than once. I could only implement using DFS. (because context is saved implicitly in recursive DFS). How to do that using BFS? ...

Algorithm that Generates Unique Serial Number for Each English Word

Hi All, For an application I need to generate unique serial numbers for each English word. What would be the best approach? One constraint is serial number generation algorithm should be very effective in an ordinary desktop computer. Thanks ...

Quicksort superiority over Heap Sort

Heap Sort has a worst case complexity is O(nlog) n wnile Quicksort is O(n^2). But emperical evidences say quicksort is superior. Why is that?? ...

Modified preorder tree traversal - finding the next node

Hi, I have this data: id | parent_id | lft | rgt | name ===================================== 1 | 0 | 1 | 8 | abc 2 | 3 | 5 | 6 | jkl 3 | 1 | 2 | 3 | def 4 | 0 | 9 | 10 | mnno 5 | 1 | 4 | 7 | ghi I need to traverse this hierarchy in this order (ids): 1 > 3 > 5 > 2 > 4 H...

algorithm to traverse points horizontally and vertically

There are n points in the 2D plane. A robot wants to visit all of them but can only move horizontally or vertically. How should it visit all of them so that the total distance it covers is minimal? ...

what is the idea behind scaling an image using lanczos?

Hi, I'm interested in image scaling algorithms and have implemented the bilinear and bicubic methods. However, I have heard of the lanczos and other more sophisticated methods for even higher quality image scaling and I am very curious how they work. Could someone here explain the basic idea behind scaling an image using lanczos (both...

Which Sorting Algorithm used in .NET Array's Sort method ? (Array.Sort( ))

Which sorting algorithm is used in .NET's Array Sort method ? (Array.Sort( )) ...

How to check a Graph if a Planar Graph or not?

I'm learning about the Planar Graph and coloring in c++. But i don't know install the algorithm to do this work. Someone please help me? Here i have some information for you! This is my code! And it still has a function does not finish. If someone know what is a "Planar Graph", please fix the Planar_Graph function below! :D thanks so mu...

Algorithm needed in any laguage - Related to Arrays...

I have a question where there are four arrays, two for men and two for women. One of the men array is the age in increasing order and the other array is the height of men in increasing order. The two arrays for women are also the same. Now if one of the men marries a women, then form the age array, the men to the left of this man should...

algorithm for getting time zone from geo coordinates

Hi, I want to write app where user can point any place on map (not only cities) and get timezone in that place. What data structure (app will not have Internet connectivity) and algorithm should I use? Where I can obtain needed data (I wont more accuracy then divining map into 24 rectangles)? I will write my app in Java ME. ...

Implementing Wilson Score in SQL

We have a relatively small table that we would like to sort based on rating, using the Wilson interval or a reasonable equivalent. I'm a reasonably smart guy, but my math fu is nowhere near strong enough to understand this: The above formula, I am told, calculates a score for a positive/negative (thumbs up/thumbs down) voting system. ...

Curving from one point to another

I have tiles that are in random spots, and they wind up at x',y' (to make a nice 2d array) by doing : Xt = (((X-X)/T)*t)+X , Yt = (((Y-Y)/T)*t)+Y This works well, but it is linear. I'm looking for something curvier. A little bit like a parabola works. Basically instead of getting to X' in a straight line, I'm looking for an algor...

Determine font color based on background color

Given a system (a website for instance) that lets a user customize the background color for some section but not the font color (to keep number of options to a minimum), is there a way to programmatically determine if a "light" or "dark" font color is necessary? I'm sure there is some algorithm, but I don't know enough about colors, lum...

implementing kruskal's algorithm utilizing threads

I'm implementing Kruskal's algorithm and I'd like to utilize threads. However I am not sure I know enough about the algorithm to do this. What I imagine is that I'd different parts of the graph would be solved for and connected at the end. Can anyone point me in the right direction? Thanks. ...

NP vs NP-Complete vs NP-Hard

What are the differences between NP vs NP-Complete vs NP-Hard ? I am aware of many resources all over the web. I d like to read your explanations, and the reason is they might be different then what s out there, or it s out there and i m not aware. ...

What's an efficient algorithm to make one list equal to another one?

Let's say I have a list A that needs to look exactly like list B. All the objects that B has but A does not have need to be added to A. And all the objects that A has but not B, need to be removed from A. The reason why I need this is because I have an ArrayList of Players that I'm saving to a file. Every time I update an attribute of a...

circle-circle collision problem

I have a problem with circle-circle collision detection.I used the following algorithm func collision(id,other.id) { var vaP1,vaP2,dis,va1,vb1,va2,vb2,vp1,vp2,dx,dy,dt; if (id!=other.id) { dx=other.x-x; dy=other.y-y; dis=sqrt(sqr(dx)+sqr(dy)); if dis<=radius+other.radius { /...

Displaying topic specific tweets in Twitter

I'd like to integrate Twitter into my app but keep the tweets specific to the app topic. For example, if the app is about recipes, all tweets on the built in Twitter client will be about recipes. Basically acting like a chat client about recipes. However, I don't think Twitter works that way. You basically follow someone (say the a...