In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

learn more… | top users | synonyms (1)

1
vote
1answer
45 views

Is this still a Greedy Algorithm

As a preface I will state this is for a homework assignment. I have already discussed this with the professor and will not be using this design. This purpose of this question is whether or not the ...
3
votes
2answers
119 views

Algorithm for finding automorphisms of a string in O(n) time

I recently stumbled upon this problem, which requires a solution in O(n) time, and I'm struggling to find a correct one. The obvious, naive solution runs in O(n²) time. Any ideas? A string S = ...
5
votes
2answers
740 views

Nearest color algorithm using Hex Triplet

Wikipedia has a list of colors that I am using for a basis of color names. I want to find the nearest named color given an arbitrary RGB value. For example #5D8AA8 hex triplet is "Air Force Blue". ...
1
vote
1answer
125 views

Build a map with city blocks and road

Is there a design pattern or well known algorithm to build a simple map with roads and city blocks? To have an idea of what's my target i describe some of the constraints and the context: a matrix ...
1
vote
7answers
8k views

Merge sort versus quick sort performance

I have implemented merge sort and quick sort using C (GCC 4.4.3 on Ubuntu 10.04 running on a 4 GB RAM laptop with an Intel DUO CPU at 2GHz) and I wanted to compare the performance of the two ...
3
votes
2answers
192 views

Why Do B+ Trees Have a Minimum Occupancy of 50%?

As far as I can tell, the basic operations (add, delete, search) on a B+ Tree would function the same if minimum occupancy was 1, or 1/3, or any other function on node size. All the sources available ...
22
votes
8answers
5k views

Function guaranteed to never return the same value twice

This is a question I was asked at a job interview, and I can't figure out the answer they were looking for, so I'm hoping someone here might have some ideas. The goal is to write a function that is ...
0
votes
0answers
43 views

Find 'Connected Components' in undirected, unweighted graph coded as a 2d array

Given an undirected, unweighted graph coded as a 2d array, how can I find the number of different connected components? Example There is the following 2d array (I'm not putting any brackets to ...
2
votes
2answers
113 views

Finding shortest path between nodes with a twist

Note: if you feel that I should include code, please tell me. I am solving a problem of finding shortest path between nodes. I am given the vertices between nodes, however they are one sided (ie you ...
3
votes
2answers
428 views

What makes for a bad case for quick sort?

I am learning about quicksort and want to illustrate different arrays that quicksort would have a hard time on. The quicksort I have in mind does not have an initial random shuffling, does 2 ...
0
votes
1answer
47 views

Simulated Annealing Contradiction?

The entire idea of simulated annealing is to avoid getting stuck in local optimums, which is why sometimes, a worse solution is accepted. However, simulated annealing will automatically accept a ...
0
votes
1answer
138 views

Why does this evaluation function work in a connect four game in java

I am exploring how a Minimax algorithm can be used in a connect four game. I was looking through a program and found this evaluation function. private static int[][] evaluationTable = {{3, 4, 5, 7, ...
0
votes
1answer
51 views

Rideshare algorithm to be used for scheduled and adhoc journeys

I need some help writing some pseudo code for a rideshare system for taxi drivers. The idea behind it is that it would combine real-time incoming taxi journeys and pre-bookings in real-time. The ...
2
votes
2answers
169 views

An algorithm that spreads similar items across a list

I need an algorithm that distributes same items across a list, so maximizing the distance between occurrences. E.g. I have a list of 15 items: {a,b,c,c,c,d,e,f,f,f,g,h,h,i,j} The algorithm should ...
1
vote
1answer
61 views

Find common ancestor

Given X number of leaves (the ringed leaves in the picture) in an unbalanced tree with depth aroun 100-1000 and total number of nodes around 15 000 000. I'm looking for the first common ancestor for ...
2
votes
2answers
195 views

How deep is enough to represent an algorithm in UML sequence diagram?

I have three simple classes. LoginController, UsersCatalog and User. UsersCatalog has an array of User. I have to represent a simple process of login. LoginController has a method login(username, ...
1
vote
4answers
262 views

Application qos involving priority and bandwidth

Our manager wants us to do applicaiton qos which is quite different from the well-known system qos. We have many services of three types, they have priorites, the manager wants to suspend low priority ...
-5
votes
1answer
75 views

What is the time complexity for the following program? [closed]

I really don't know if this is the lame question, but please tell me the time complexity of the following code. for(i=0;i<n;i*=2){ // will each stmt gets executed O(log n) times? }
11
votes
6answers
4k views

Can we technically un-blur images?

Since there is an algorithm to blur images, so that part of it cannot be recognised, can we reverse the algorithm and unblur part of than image? Is there a program that already does that, is that ...
1
vote
1answer
148 views

Algorithm for rating books: Relative perception

So I am developing this application for rating books (think like IMDB for books) using relational database. Problem statement : Let's say book "A" deserves 8.5 in absolute sense. In case if A is ...
0
votes
1answer
129 views

What is the justification for the running time of this loop?

I don't understand why the running time of the following loop is n+2 ? Also why the running time of the statements inside the loop is n+1 ? Double test(int n){ int sum=0; -> 1 time ...
606
votes
9answers
188k views

Which hashing algorithm is best for uniqueness and speed?

Which hashing algorithm is best for uniqueness and speed? Example (good) uses include hash dictionaries. I know there are things like SHA-256 and such, but these algorithms are designed to be ...
-3
votes
0answers
66 views

Python algorithms for poker hands? [closed]

I am in the middle of writing a Texas Hold'Em poker program in Python and need some algorithms. I'm sure I can write these but I'd like to see if someone already has something similar to this. NOTE I ...
3
votes
4answers
288 views

Mark x% items in stream

There are n items (n is known and > 1,000,000,000). I want to randomly 'mark' x% of n-items in stream. (n and x are known) Items are in stream ,one directional (you can't go back) processed item ...
2
votes
1answer
84 views

Finding the fewest sets which contain all items

I am wondering if there is a known algorithm for solving the following. Data: There is a number of sets containing items. An item can be a member of more than one set. Aim: return the minimum number ...
1
vote
0answers
64 views

Walk Tree vs Zhang and Sasha Algorithms

I need some help understanding how two tree comparing algorithms differ. I am working with Microsoft's XmlDiffPatch (http://msdn.microsoft.com/en-us/library/aa302294.aspx) which compares two xmls. The ...
4
votes
2answers
173 views

Extracting first and last name from a single name field

I'm working with the Twitter API which provides only a single field called name, which includes the full name of a person. The application that we're constructing requires a first name and a last ...
0
votes
1answer
131 views

Which algorithm best fits the following problem [closed]

I'm looking for the right algorithm to solve a specific problem. I hope that there are known algorithms that can be used. The problem definition Given a set of 'options' (~10) A session is defined ...
-3
votes
0answers
76 views

Alphanumeric addition [closed]

Suppose I have the following problem: ZEROES + ONES = BINARY where every letter stands for a different decimal digit. Such problems are known as "alphanumerics". Does anyone know an algorithm for ...
0
votes
1answer
82 views

Handling the process of large-scale lists [closed]

What are the efficient ways to process huge lists (+10 millions), and things to consider while manipulating huge lists. First question, when should I use recursion, and when I shouldn't. In both ...
-5
votes
0answers
57 views

Pseudo code of 3 digits reversed [closed]

Pseudo code is one of the way of algorithm representation. It have its own procedure to write a program using this method. Let us say we are expected to write a program that finds the product of two ...
1
vote
2answers
172 views

How to construct a cubie representation of a rubik's cube, given an array

Just to get this out of the way, I have seen this, and it is not what I'm looking for. So, let's say you are programming a Rubik's Cube. (I know, very unoriginal, but bored programmers have to do ...
0
votes
0answers
58 views

How to verify external process succeeded completely [closed]

I am developing a web application, where users can take surveys. However, the surveys are run by other websites. Therefore I cannot verify if the user has finished the survey. How can I approach ...
2
votes
3answers
151 views

Count unique visitors by group of visited places

I'm facing the problem of counting the unique visitors of groups of places. Here is the situation: I have visitors that can visit places. For example, that can be internet users visiting web pages, ...
0
votes
2answers
150 views

How are the tiles in WORDAMENT organized?

I'm trying to create a word game, just like WORDAMENT, in my spare time. In order to present a new round, I need to create a board with 16 letters organized in a 4*4 grid. Currently, I'm generating ...
0
votes
0answers
13 views

Python: algorithm for describing chess positions [migrated]

I have an interesting problem with my chess application. The application reads PGN files, and at any time while viewing a game from the file, the function below, when called, iterates over the ...
7
votes
1answer
4k views

What is the best “bucket-fill” algorithm?

I'm pretty new to image processing, and I am currently working on a paint-like application that will feature a bucket-fill. However, I have no idea what the best algorithm for a bucket-fill is. I ...
12
votes
2answers
879 views

How to calculate figure rotation efficiently?

I have a Figure represented through a matrix of bytes (bitmap-like matrix). Example Figure is shown on the Picture 1. The goal is to find the best rotation angle of some given Figure. When Figure ...
2
votes
1answer
102 views

Need help identifying a league scheduling algorithm

I am trying to create a sports league scheduler. I am having trouble identifying an algorithm to help me efficiently fill in each slot. Sample data to build the schedule would be: 10 teams Each ...
1
vote
1answer
166 views

How to find duplicate strings

I allow my user to create profiles, meaning they potentially could create some with duplicate names. This can be problematic so I want to prevent them from doing so. I coded up this first pass ...
1
vote
2answers
116 views

Finding common prefixes for a set of strings

I am trying to find common prefixes for a sorted set of strings. i.e. if the following strings are given: AB123456 AB123457 ABCDEFGH ABCDEFGX1 ABCDEFGY XXXX then my function should return three ...
1
vote
1answer
200 views

Assembly vs. algorithmic languages (like C, Algol, etc)

Usually, computer science papers describe algorithms in Algol-like pseudolanguage, similar to Pascal or even C/C++. But Donald Knuth uses his own assembly language (MMIX). Are there any good known ...
3
votes
1answer
145 views

What advantages are there to using Flex/Bison over just writing a compiler straight in a programming language?

I have written an Interpreter / Compiler simply as a programming algorithm using features such as recursive functions and concepts from finite-State machines. To me, these things are ideally suited to ...
0
votes
0answers
55 views

Does multiple Bloom filters make sense?

In order to decrease the number of false positives, I came up with a couple of possible solutions. Create two different types of Bloom filters; eg. filter1 using 3 different hash algorithms, filter2 ...
0
votes
1answer
160 views

How can I rank teams based off of head to head wins/losses

I'm trying to write an algorithm (specifically in Ruby) that will rank teams based on their record against each other. If a team A and team B have won the same amount of games against each other, then ...
-4
votes
1answer
97 views

how to write example code for this sequence number? [closed]

I want to ask you a question. How is the example code (just an algorithm in any language programming) for this sequence: 1, 2, 3, 1, 4, 2, 5, 3, 4, 5, 1, 6, 2, 7, 3, 6, 4, 7, 5, 6, 7, 1, 8, ... It ...
2
votes
1answer
180 views

Quickest sorting algorithm for sorting a low number of integers

I am making a program on my spare time that I want to run as quickly as possible. The program is written in C. A large set of the procedures operate on pointers to 7 integers that are sorted by their ...
1
vote
1answer
62 views

How to do “image shifting” faster?

I have a grayscale matrix (implemented as a simple array) to be shown on a display: line 1: | a | b | c | line 2: | d | e | f | a-f are grayscale values. This pattern has to be shifted by a ...
1
vote
2answers
60 views

multiple comparison sorting

I have a set of songs where I want to sort them by a particular quality. In order to do this (by crowdsourcing) I will present users with a comparison between two songs. The user will then choose ...
1
vote
2answers
190 views

Best practices for geolocation

We are writing a flight search engine. We want to pre-fill the departure airport for mobile users with the closest one to their location. To do that, our plan is to Find a list of airports with ...