algorithm

How do I find the next multiple of 10 of any integer?

Dynamic integer will be any number from 0 to 150. i.e. - number returns 41, need to return 50. If number is 10 need to return 10. Number is 1 need to return 10. Was thinking I could use the ceiling function if I modify the integer as a decimal...? then use ceiling function, and put back to decimal? Only thing is would also have to kn...

Relating NP-Complete problems to real world problems

I have a decent grasp of NP Complete problems; that's not the issue. What I don't have is a good sense of where they turn up in "real" programming. Some (like knapsack and traveling salesman) are obvious, but others don't seem obviously connected to "real" problems. I've had the experience several times of struggling with a difficult ...

How to combine elements of a list

I'm working in c#. I have a sorted List of structures. The structure has a DateTime object which stores month and year and an integer which stores a value. The list is sorted by date. I need to traverse the list and combine it so that I only have one instance of the structure per date. For example: My initial list would look like this:...

time complexity of Fleury's Algorithm

Hi all could you please help me find out the time complexity of the Fleury' algoritm(which is used to get the Eulerian circuit)? Searched on the web,but no results. thanks/ ...

Efficient algorithm to find a maximum common subset of two sets?

Each set contains bunch of checksums. For example: Set A: { 4445968d0e100ad08323df8c895cea15 a67f8052594d6ba3f75502c0b91b868f 07736dde2f8484a4a3af463e05f039e3 5b1e374ff2ba949ab49870ca24d3163a } Set B: { 6639e1da308fd7b04b7635a17450df7c 4445968d0e100ad08323df8c895cea15 a67f8052594d6ba3f75502c0b91b868f } The maximum common subset ...

Find unique vertices from a 'triangle-soup'

I am building a CAD-file converter on top of two libraries (Opencascade and DWF Toolkit). However, my question is plattform agnostic: Given: I have generated a mesh as a list of triangular faces form a model constructed through my application. Each Triangle is defined through three vertexes, which consist of three floats (x, y & z co...

Is MapReduce just a generalisation of another programming principle?

I'm getting into parallel programming and I'm studying mapreduce and other distributed algorithms. Is it best just to learn mapreduce or is there a more general algorithm that will serve me better? ...

Deleting an element from a kd-tree of two dimensions.

I would like to extend a kd-tree (2D) class to be able to remove nodes (points). This removal should be conducted without having to rebuild large sections of the tree. The algorithm described in these slides, on slide 13 seems to be what I am after. However, I am trouble following the description of "findmin()" found on slide 7, which is...

Pearson correlation in PHP

I'm trying to implement the calculation of correlation coefficient of people between two sets of data in php. I'm just trying to do the porting python script that can be found at this url http://answers.oreilly.com/topic/1066-how-to-find-similar-users-with-python/ my implementation is the following: class LB_Similarity_PearsonCorrelati...

Are there some better ways to implement find as you type in Java with a fairly small data set?

Hi, I've got about 2500 short phrases in a file. I want to be able to find phrases as I type possible substrings of them. My app has a text box and a list of phrases. The text box is initially empty and the list contains all 2500 phrases, since the empty string is a substring of all of them. As I type in the text box, the list updat...

Algorithm ..to find nearest Neighboring Rectangles ..in all 4 directions

Which Spatial Search Algorithm..would help in querying the nearest neighboring rectangle ..for a Given Rectangle ..in all 4 directions(ie Top ,Left,Bottom ,Right). 1: The distance is orthogonal from one side of the rectangle..to the opposite side of the other rect. 2: Rectangles actually represent GUI components on a form. ...

Non-linear counter

So I have a counter. It is supposed to calculate the current amount of something. To calculate this, I know the start date, and start amount, and the amount to increment the counter by each second. Easy peasy. The tricky part is that the growth is not quite linear. Every day, the increment amount increases by a set amount. I need to recr...

What is the name of this sequence generation problem? Any comments?

I need to iterate over an ordered sequence that is defined by an array of numbers ai, i = 1..n, where n is the length of each sequence element, and each ai specifies the max number of possible values at position i in the output sequence. Example: a = {10,10,10} Sequence: 000, 001, 002, ... 999 (the decimal numbers from 000 to 999) a ...

Most elegant way to change 0 to 1 and vice versa

What is the most elegant way to do the next stuff: int i = oneOrZero; if (i == 0) { i = 1; } else { i = 0; } You can assume that i can have only 1 or 0 value. ...

Algorithm for binary arithmetic in Java

On paper, binary arithmetic is simple, but as a beginning programmer, I'm finding it a little difficult to come up with algorithms for the addition, subtraction, multiplication and division of binary numbers. I have two binary numbers stored as strings, assume that any leading zeroes have been dropped. How would I go about performing th...

Algorithm used by browser for searching words in the webpage

Hi, Which data structure or algorithm is used in browsers to search for a word? Will the browsers construct a trie or suffix tree? Thank you Bala ...

Algorithm used for auto-suggest feature

Hi, Which algorithm or data structure is used in auto suggest feature to display list of words. I am thinking that edit-distance will be used to display this, but again frequency or score associated with each word should also be considered. For example, consider the tags option on the ask question page. Thank you Bala ...

Worst case for QuickSort - when can it occur?

When analyzing QS, every one always refers to the "almost sorted" worst case. When can such a scenario occur with natural input? The only example I came up with is re-indexing. ...

How to find a factorial?

How can I write a program to find the factorial of any number? ...

Find unique common element from 3 arrays

Original Problem: I have 3 boxes each containing 200 coins, given that there is only one person who has made calls from all of the three boxes and thus there is one coin in each box which has same fingerprints and rest of all coins have different fingerprints. You have to find the coin which contains same fingerprint from all of the 3 b...