algorithm

Adding to a bit array

In my program, I am using BitArrays to represent 160 bit numbers. I want to be able to add, subtract, increment and decrement these numbers, what is the algorithm for doing this? At the moment I'm not interested in multiplication and division, but I might be in the future so bonus points for that. I'm implementing in C#, but pseudocode...

sorting using recursion

I have the following function to sort an unordered array to having even numbers in the front and odd numbers in the back. Is there a way to get it done without using any loops? //front is 0, back =array.length-1; arrangeArray (front, back); public static void arrangeArray (int front, int back) { if (front != back || front<back) ...

Complexity in using Binary search and Trie

given a large list of alphabetically sorted words in a file,I need to write a program that, given a word x, determines if x is in the list. Preprocessing is ok since I will be calling this function many times over different inputs. priorties: 1. speed. 2. memory I already know I can use (n is number of words, m is average length of the...

The algorithm used to generate recommendations in Google News?

Hi everyone. I'm study recommendation engines, and I went through the paper that defines how Google News generates recommendations to users for news items which might be of their interest, based on collaborative filtering. One interesting technique that they mention is Minhashing. I went through what it does, but I'm pretty sure that w...

Efficiently remove points with same slope

Hi, In one of mine applications I am dealing with graphics objects. I am using open source GPC library to clip/merge two shapes. To improve accuracy I am sampling (adding multiple points between two edges) existing shapes. But before displaying back the merged shape I need to remove all the points between two edges. But I am not ab...

Graph Algorithm To Find All Paths Between N Arbitrary Vertices

I have an graph with the following attributes: Undirected Not weighted Each vertex has a minimum of 2 and maximum of 6 edges connected to it. Vertex count will be < 100 Graph is static and no vertices/edges can be added/removed or edited. I'm looking for paths between a random subset of the vertices (at least 2). The paths should s...

Algorithm putting point into square with maximal minimum distance

I'm stuck on this: Have a square. Put n points into this square so the minimal distance (not necessary the average distance) is the highest possible. I'm looking for an algorithm which would be able to generate the coordinates of all points given the count of them. Example results for n=4;5;6: Please don't mention computing-power ba...

Data Structures for hashMap, List and Set

Can any one please guide me to look in depth about the Data Structures used and how is it implemented in the List, Set and Maps of Util Collection page. In Interviews most of the questions will be on the Algorithms, but I never saw anywhere the implementation details, Can any one please share the information. ...

Shortest-path algorithms which use a space-time tradeoff?

Problem: finding shortest paths in an unweighted, undirected graph. Breadth-first search can find the shortest path between two nodes, but this can take up to O(|V| + |E|) time. A precomputed lookup table would allow requests to be answered in O(1) time, but at the cost of O(|V|^2) space. What I'm wondering: Is there an algorithm which...

Algorithm that spans two pages in Latex

i have a long algorithm that i need to put in a report. i am using latex for this report. but due to the length of the algorithm it is more than one page but i cannot get it to fit into the next page. i am new to latex. can someone tell me how to do this? i am new to latex. ...

Need XOR Encryption Algorithm Pseudocode

I am trying to find the pseudocode for the XOR encryption algorithm. However I've had no luck so far. Anybody know where I can find it? EDIT: XOR 32 if that helps EDIT 2: For Passwords ...

Return a number between 0 and 4

How do I return a number between 0 and 4, depending the input number? For example if I pass it number 23 it will return 3. The number set should look like 0 5 10 15 20 .. 1 6 11 16 21 .. 2 7 12 17 22 .. 3 8 13 18 23 .. 4 9 14 19 24 What's the math for this? ...

Hashing Algorithm, its uses?

I don't fully understand hashing algorithms. Anybody care to explain it to me in a very simply understandable way. Thanks EDIT: Using it with Usernames from a text file. ...

Generate combinations by order and fixed length.

Suppose there is array main[] = [a,b,c,....z]; a[] = [a1,a2,a3,....] , b[] = [b1,b2,b3,....] and so on. So if we generate combination in main.length of ordered then it looks like ..... a1 b1 c1, a1 b1 c2, a1 b1 c3 ...... a1 b2 c1, a1 b3 c1, ..... a2 b1 c1, a3 b1 c1, ..... and total count will be a.length * b.length * c.length .........

Interview Q: sorting an almost sorted array (elements misplaced by no more than k)

I was asked this interview question recently: You're given an array that is almost sorted, in that each of the N elements may be misplaced by no more than k positions from the correct sorted order. Find a space-and-time efficient algorithm to sort the array. I have an O(N log k) solution as follows. Let's denote arr[0..n) to mean ...

MATLAB postpones disp calls when doing demanding calculations. Why is that?

I am implementing an algorithm in MATLAB. Among other things it calculates the shortest paths etc. so it's quite demanding for my old computer. I've put in disp() calls through out the program to see what's happening all the time. However when starting on a particulary heavy for loop the disp() seemes not to be called until the loop is...

dijkstra/prim's algorithm...a little help?

I was wondering for dijkstra's and prim's algorithm, what happens when they are choosing between more than one vertex to go to ,and there are more than one vertex with the same weight. For example ...

Algorithm design, "randomising" timetable schedule in Python although open to other languages.

Before I start I should add I am a musician and not a native programmer, this was undertook to make my life easier. Here is the situation, at work I'm given a new csv file each which contains a list of sound files, their length, and the minimum total amount of time they must be played. I create a playlist of exactly 60 minutes, from th...

Is there anything available for .NET to get the differences in two strings?

I'm looking for a way to determine the differences between two strings, and highlight them in both strings. I would suspect that most 'diff' libraries won't work since they show differences in lines (I believe). Either an algorithm or library will work. Thanks, Mark ...

bellman forge, dijkstra's, prim's algorithm, kruskals, directed acrylic graph

What are some real life examples where each one of these are used? ...