algorithm

Gravity Sort : Is this possible programatically?

Hi, I've been thinking recently on using the Object Oriented design in the sorting algorithm. However I was not able to find a proper way to even come closer in making this sorting algorithm that does the sorting in O(n) time. Ok, here is what I've been thinking for a week. I have a set of input data. I will assign a mass to each of t...

Removing the obstacle that yields the best path from a map after A* traversal

I traverse a 16x16 maze using my own A* implementation. All is well. However, after the traversal, I would like to find out what wall would give me the best alternative path. Apart from removing every block and re-running A* on the maze, what's a more clever and elegant solution? I was thinking give every wall node (ignored by A*), a t...

Discrete Curve evolution algorithm

i am trying to implement discrete curve evolution algorithm in c++ do any one help me with psudo code or c code or some simple steps of your understanding ...

Minimizing the number of boxes that cover a given set of intervals

Hi, this is a question for the algorithms gurus out there :-) Let S be a set of intervals of the natural numbers that might overlap and b a box size. Assume that for each interval, the range is strictly less than b. I want to find the minimum set of intervals of size b (let's call it M) so all the intervals in S are contained in the in...

Determine if a day of week and time fall in a custom weekend period

I've been trying to come up with a method, that given a day of week and time of day, it will return if it falls under a custom weekend period. The weekend period is saved in 4 variables as follows: The day of week when it starts (0-6) The time of day when it starts (0-23) The day of week when it ends (0-6) The time of day when it ends...

How to balance number of ratings versus the ratings themselves?

Hello guys, For a school project, we'll have to implement a ranking system. However, we figured that a dumb rank average would suck: something that one user ranked 5 stars would have a better average that something 188 users ranked 4 stars, and that's just stupid. So I'm wondering if any of you have an example algorithm of "smart" rank...

Good websites and/or books to learn game algorithms?

I'm interested in learning video game algorithms. (For iPhone particularly, but generally as well. I assume certain concepts are the same.) I am best off (personally) learning from a book but websites are useful too. What has helped you learn game programming algorithms and concepts? EDIT: As per request, I'll clarify the types of alg...

Can SHA-1 algorithm be computed on a stream? With low memory footprint?

I am looking for a way to compute SHA-1 checksums of very large files without having to fully load them into memory at once. I don't know the details of the SHA-1 implementation and therefore would like to know if it is even possible to do that. If you know the SAX XML parser, then what I look for would be something similar: Computin...

Is this linear search implementation actually useful?

In Matters Computational I found this interesting linear search implementation (it's actually my Java implementation ;-)): public static int linearSearch(int[] a, int key) { int high = a.length - 1; int tmp = a[high]; // put a sentinel at the end of the array a[high] = key; int i = 0; while (a[i] != key) {...

Nesting Patterns Algorithms / Cutting Waste Problem

First off, I'd like to say that I'm already looking into the "Cutting Stock Problem" algorithm, however I feel that I need a bit more clarification, and possibly some help with some of the math (Not my strong point). What I need to do is have an offset pattern that causes the circle to fit in the crevasse created by having the two circu...

Given an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times.

Given an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times. Using hash was not allowed. Complexity of algorithm should be O(n) ...

scrabble algorithm....

I'm making algorithm like crossword, but I dont know how to design the algorithm. For example: there are words like 'car', 'apple' in the dictionary. the word 'app' is given on the board. there are letters like 'l' 'e' 'c' 'r'....for making words. So the algorithm's task is to make correct words which are stored in dictionary. app ...

Image quantization algorithm with clustering properties

Most quantizer algorithms reduce the number of colors in an image, but the colors appear as dots throughout the image. When quantizing images which we know have a fixed number of colors, say, logos, it is desirable that similarly colored pixels are clustered together. Is there a quantizing algorithm that is suitable for this purpose? ...

What is the result of X(X,X)?

A friend who studies pure mathematics ask me to think about the following problem. Suppose that there is an algorithm named X that has 2 inputs: A and a_1...a_n, where 'A' stands for an arbitary algorithm and 'a_1..a_n' are inputs of A. X receives A and its inputs and returns true if A with a_1..a_n could be terminated, and false if A ...

Algorithm video tutorial

There are quite a few algorithm lectures on the web, but what I'm looking for is a video tutorial where I can watch somebody coding on screen, going from a blank document to an algorithm that solves a problem. Language doesn't really matter. There are lots of video tutorials like this about a certain language, but is there one that teach...

count of distinct acyclic paths from A[a,b] to A[c,d]?

I'm writing a sokoban solver for fun and practice, it uses a simple algorithm (something like BFS with a bit of difference). now i want to estimate its running time ( O and omega). but need to know how to calculate count of acyclic paths from a vertex to another in a network. actually I want an expression that calculates count of valid ...

Replacing multiple patterns in a block of data

I need to find the most efficient way of matching multiple regular expressions on a single block of text. To give an example of what I need, consider a block of text: "Hello World what a beautiful day" I want to replace Hello with "Bye" and "World" with Universe. I can always do this in a loop ofcourse, using something like String.repl...

Algorithm: shortest path between all points

Suppose I have 10 points. I know the distance between each point. I need to find the shortest possible route passing through all points. I have tried a couple of algorithms (Dijkstra, Floyd Warshall,...) and they all give me the shortest path between start and end, but they don't make a route with all points on it. Permutations work ...

Number of different elements in an array.

Is it possible to compute the number of different elements in an array in linear time and constant space? Let us say it's an array of long integers, and you can not allocate an array of length sizeof(long). P.S. Not homework, just curious. I've got a book that sort of implies that it is possible. ...

How to judge the relative efficiency of algorithms given runtimes as functions of 'n'?

Consider two algorithms A and B which solve the same problem, and have time complexities (in terms of the number of elementary operations they perform) given respectively by a(n) = 9n+6 b(n) = 2(n^2)+1 (i) Which algorithm is the best asymptotically? (ii) Which is the best for small input sizes n, and for what values of n is this the ...