algorithm

What is a good algorithm for getting the minimum vertex cover of a tree?

What is a good algorithm for getting the minimum vertex cover of a tree? INPUT: The node's neighbours. OUTPUT: The minimum number of vertices. ...

Why modulo 65521 in Adler-32 checksum algorithm?

The Adler-32 checksum algorithm does sums modulo 65521. I know that 65521 is the largest prime number that fits in 16 bits, but why is it important to use a prime number in this algorithm? (I'm sure the answer will seem obvious once someone tells me, but the number-theory parts of my brain just aren't working. Even without expertise i...

How to create Alphabetical list with letters?

Hi all I trying to implement alpha ordered list by columns as shown on picture But my algorithm is not clear and maybe someone could help me within string[] letters = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Å", "Ä", "Ö", "0-9...

What does O(log(log(n))))-competitive mean?

I was going through some data structures and I noticed this as a time complexity: O(log(log(n))))-competitive. I read that constant-competitive was the ratio of the expected time/optimal time. But what does it mean to have a set-competitive? ...

given a tree structure, how do you use recursion to make it into a simple linked list in-place?

Given a binary tree (with left and right child only), how do you write a recursive function to make it into a simple linked list in-place? (no new data structure should be created. Pseudo code is ok). Suppose each node has an integer value, like 123, or 2, or 3. The final link list should have all the nodes in the tree. The order is n...

Easy Questions for Teaching Pascal to a kid

I've been asked to tutor Pascal to a kid. Despite never seen Pascal before I did manage to get a tutorial and I now know enough to teach him. I am writing you guys to see if anyone can point me out some basic exercises that involve simple algorithms, Something like: Sort this array, find the average, etc... It can be in any language, I...

Ensuring that items that have been viewed are not seen again

I have a possible solution to a problem I'm trying to address, but I wanted to run it by here just to be on the safe side. The challenge is to ensure that a user that has gone through some test questions in an exam application doesn't encounter them again during a subsequent test. I'm not using a SQL database, which would allow me to u...

How do you calculate floating point in a radix other than 10?

Given Wikipedia's article on Radix Point, how would one calculate the binary equivalent of 10.1 or the hex equivalent of 17.17? For the former, what is the binary equivalent of a tenth? For the latter, the hex representation of 17/100? I'm looking more for an algorithm than for solutions to just those two examples. ...

Is it possible to guess a user's mood based on the structure of text?

I assume a natural language processor would need to be used to parse the text itself, but what suggestions do you have for an algorithm to detect a user's mood based on text that they have written? I doubt it would be very accurate, but I'm still interested nonetheless. EDIT: I am by no means an expert on linguistics or natural language...

Smart progress bar ETA computation

In many applications, we have some progress bar for a file download, for a compression task, for a search, etc. We all often use progress bars to let users know something is happening. And if we know some details like just how much work has been done and how much is left to do, we can even give a time estimate, often by extrapolating fro...

Create your own MD5 collisions

I'm doing a presentation on MD5 collisions and I'd like to give people any idea how likely a collision is. It would be good to have two blocks of text which hash to the same thing, and explain how many combinations of [a-zA-Z ] were needed before I hit a collision. The obvious answer is hash every possible combination until hit two has...

Dijkstra algorithm for 2D array in Java

Hiya guys!! This is my first post, and this is for a school project; I'm running into a huge amount of trouble, and I can't seem to find a understandable solution. a b c d e z a - 2 3 - - - b 2 - - 5 2 - c 3 - - - 5 - d - 5 - - 1 2 e - 2 5 1 - 4 z - - - 2 4 - Thats the two dimensional array. So if you want to find the shortes...

Finding most active topics or games

What's a good metric for finding the most active forum thread or game in your database? Imagine you run a forum like 4chan. You want the most active threads to appear on the first page. You tried sorting topics by last_updated, but the result is chaotic: the threads you see on each refresh are effectively random, and jumping to the se...

Distribution of a sum S over N diffent operands (b1, b2, .., bn), where b1, b2, ... bn are in a fixed ratio, which is determined by another set of operands (a1,a2, .. an)

If the title is completely misleading/unclear please suggest something relevant and better. Consider a situation where: Candidate A gets a total of Ta votes from N constituencies, with distribution: {a1, a2, a3 .. aN} Candidate B gets a total of Tb votes (Ta and Tb are unrelated, which means Ta < Tb, Ta = Tb & Ta > Tb are all possib...

Find images of similar color...

Hello! Based on suggestions here @ SO, I have cataloged the average color for a set of stock images. r,g,b = image.convert("RGB").resize((1,1), Image.ANTIALIAS).getpixel((0,0)) Now, I would like to present a color wheel to the user and run a search against my catalog to find images that are the closest match to the color selected. ...

An algorithm to generate subsets of a set satisfying certian conditions

Suppose I am given a sorted list of elements and I want to generate all subsets satisfying some condition, so that if a given set does not satisfy the condition, then a larger subset will also not satisfy it, and all sets of one element do satisfy it. For example, given a list of all positive integers smaller than 100, determine subsets...

What's the most effective workflow between people who develop algorithms and developers?

We are developing software with pattern recognition in video. We have 7 mathematicians who are creating algorithms. Plus we have 2 developers that maintain / develop the application with these algorithms. The problem is that mathematicians are using different development tools to create algorithm like Matlab, C, C++. Also because the...

Point on non-linear range to linear and back?

Greeting, I'm trying to solve the following puzzle: I have a list of linear ranges which represent one big range. X' 100 200 300 400 500 600 700 | 900 (X) |----------|----------|----------|--------+----------| 0 | 100 (Y) ...

Efficient way to handle adding and removing items by bitwise And

So, suppose you have a collection of items. Each item has an identifier which can be represented using a bitfield. As a simple example, suppose your collection is: 0110, 0111, 1001, 1011, 1110, 1111 So, you then want to implement a function, Remove(bool bitval, int position). For example, a call to Remove(0, 2) would remove all items...

Assembly mod algorithm on processor with no division operator

This is pretty basic, but I figure it should be on SO for posterity. I need to implement a simple macro that finds the modulo of two numbers on a processor that doesn't have a division operator (think ARM). I could use division by repeated subtraction, but I don't know if this was the most efficient or easiest to work with. Any suggest...