algorithm

Java MD5 which one of these is correct?

I am trying to Sip Register and I get the challenge from the server. So I need to use the MD5 algorithm on the nonce and then send that to the server to authenticate. I have come across two examples of MD5 encryption and I have tried both and each one gives a different string back to me, so I was wondering which one is the correct one ...

Seeking algo for text diff that detects and can group similar lines

I am in the process of writing a diff text tool to compare two similar source code files. There are many such "diff" tools around, but mine shall be a little improved: If it finds a set of lines are mismatched on both sides (ie. in both files), it shall not only highlight those lines but also highlight the individual changes in these l...

Simplest path between points

I have a list of points (x, y coordinates) and a list of connections between them. Examples: Points A B C D E Connections AB BC CE BD D E | | A-B-C Of course, there are many more points and connections than this... What I need to do is find out the simplest path between some of these points. For example, if I wanted to go to A,...

JavaScript DEFLATE Implementation

Are there any open source DEFLATE encoder implementations for JavaScript? I need it to generate a binary format on the client-side that requires DEFLATE. ...

Computing Algorithm Complexity - Confusion

I have the following code snippet: sum = 0; for (i = 0; i < n; i++) for (j = 0; j < i; j++) sum++; The complexity would be O(n^2), but if I want to dig a little more for the internal loop complexity then would it be (n (n-1))/2 or (n-1)!? ...

Solving recurrences

Am trying to solve the given recursion, using recursion tree, T(n) = 3T(n/3) + n/lg n. In the first level (n/3)/(log(n/3)) + (n/3)/(log(n/3)) + (n/3)/(log(n/3)) = n/(log(n/3)). In the second level it turns out to be n/(log(n/9)). Can I generalize the above equation in the form of n.loglogn This is a general doubt I've, I need an in...

RC4 encryption - CommonCrypto (Objective-C) vs PHP

Hi, I have a XML file on a server encrypted with the RC4 algorithm (http://rc4crypt.devhome.org) function encrypt ($pwd, $data, $ispwdHex = 0) { if ($ispwdHex) $pwd = @pack('H*', $pwd); // valid input, please! $key[] = ''; $box[] = ''; $cipher = ''; $pwd_length = strlen($pwd); ...

Find an algorithm in RBTREE in O(logn)

I need to find a data structure which I can do with the following actions: Build(S,k) - O(nlogn) Search(S,k) - O(logn) Insert(S,k) - O(logn) Delete(S,k) - O(logn) Decrease-Upto(s,k,d) - O(logn) - this method should subtract d(d>0) every node which is <=k The obvious first choise was RedBlackTree. However, I can't come to a solution ...

How a marker-based augmented reality algorithm (like ARToolkit's one) works?

Hi all, For my job i've been using a Java version of ARToolkit (NyARTookit). So far it proven good enough for our needs, but my boss is starting to want the framework ported in other platforms such as web (Flash, etc) and mobiles. While i suppose i could use other ports, i'm increasingly annoyed by not knowing how the kit works and beyo...

Miller-Rabin scheme implementation unpredictable output

Greetings everyone, I am new to scheme. I have tried and implemented probabilistic variant of rabin-miller algorithm using plt scheme. I know it is probabilistic and all, but I am getting the wrong results most of the time. I have implemented the same thing using C, and it worked well(never failed a try). I get the expect...

How to convert Java long's as Strings while keeping natural order

I'm currently looking at a simple programming problem that might be fun to optimize - at least for anybody who believes that programming is art :) So here is it: How to best represent long's as Strings while keeping their natural order? Additionally, the String representation should match ^[A-Za-z0-9]+$. (I'm not too strict here, but a...

How can I compute the number of characters required to turn a string into a palindrome?

I recently found a contest problem that asks you to compute the minimum number of characters that must be inserted (anywhere) in a string to turn it into a palindrome. For example, given the string: "abcbd" we can turn it into a palindrome by inserting just two characters: one after "a" and another after "d": "adbcbda". This seems to b...

Gettting all permutations of a word or number

Using LINQ or the old-fashioned approach, how can I get all permutations of a word/number (without using an external API)? Eg ab = ab, ba, abc = acb, bac, etc Is this a specific computer science problem like image recognition, etc? Thanks ...

Optimisation of Ruby algorithm for grouping and counting colours.

Hi, i have what seems on the surface a simple problem which i wish to solve using ruby, i have a bunch of colours with associated photo id's, e.g [[1,"red"],[1,"green"],[2,"red"],[3,"yellow"],[4,"green"],[4,"red"]] and i wish to process the data so that it is in this format: 2 photos for red,green 3 photos for red 1 photo for yellow ...

Recommended Big O Notation book with .NET examples

Does anyone know of any good .NET books that focus on algorithmic complexity specifically looking at Big O Notation? The only book I have found is Data Structures and Algorithms Using C# by Michael McMillan but unfortunately (based on Amazon reviews) this does not appear to be the greatest.... Any other suggestions would be much apprec...

Google transit is too idealistic. How would you change that?

Suppose you want to get from point A to point B. You use Google Transit directions, and it tells you: Route 1: 1. Wait 5 minutes 2. Walk from point A to Bus stop 1 for 8 minutes 3. Take bus 69 till stop 2 (15 minues) 4. Wait 2 minutes 5. Take bus 6969 till stop 3(12 minutes) 6. Walk 7 minutes from stop 3 till point B for 3 minutes. To...

Fast two-dimensional pattern matching

Consider a two-dimensional grid (the usual lattice in the plane). For my purposes, a pattern or arrangement is an assignment of the numbers 1 and 2 to some connected subset of the grid points. For example, the following shows three separate arrangements: .......1.....1.... .222...2.....12... .111...2.....2.... .222...22...12211. ........

Compare different search algorithms

In what ways are DFS and Best-first search similar? How are BFS and Best-first similar? To me, to better decribe how DFS and BestFS are similar, it might be easier to point the difference,which is that in BestFS we chose as the next to expand the one that seems closest to the goal using the heuristi function. In almost all other wa...

how to efficiently get the k bigger elements of a list in python

Hi! What´s the most efficient, elegant and pythonic way of solving this problem? Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume k<n/2 without loss of generality, I guess) For example, if the list were: l = [9,1,6,4,2,8,3,7,5] n = 9, and let's say k = 3. What's the most efficient a...

Distributing appointments over a date range

I am trying to generate some test data. Say I have 1000 appointments that I need to allocate over a date range. Now I need to distribute these appointments such that there are twice as many appointments per day at the end of the month as there are at the start of the month. The increase in appointments needs to increase with a consist...