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)

481
votes
8answers
146k 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 ...
128
votes
14answers
9k views

Is it just me or is this a baffling tech interview question?

Background I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C. That's it. That is ...
124
votes
14answers
6k views

Simple method for reliably detecting code in text?

GMail has this feature where it will warn you if you try to send an email that it thinks might have an attachment. Because GMail detected the string see the attached in the email, but no actual ...
60
votes
1answer
3k views

What task did Dijkstra give volunteers, which was mentioned in his paper “The Humble Programmer”?

In Dijkstra's paper "Humble Programmer", he mentions that he gave some volunteers a problem to solve: “I have run a little programming experiment with really experienced volunteers, but something ...
58
votes
12answers
6k views

Why is the use of abstractions (such as LINQ) so taboo?

I am an independent contractor and, as such, I interview 3-4 times a year for new gigs. I am in the midst of that cycle now and got turned down for an opportunity even though I felt like the ...
55
votes
30answers
20k views

What is your favorite whiteboard interview problem? [closed]

Just as the title says, what is your favorite whiteboard interview problem, and why has it proven effective for you? Junior, senior, Java, C, Javascript, PHP, SQL, pseudo-code, etc.
53
votes
11answers
3k views

Should a competent programmer be able to come up with his own shortest path algorithm?

I'm suffering a crisis of confidence in my ability as a computer programmer. Yesterday I tried to come up with my own shortest path algorithm for a graph and after some hours I simply threw in the ...
51
votes
11answers
3k views

Writing my problem solving approach on paper?

I'm a freshman Computer Science student and we just started doing some actual projects in Python. I have found I'm very efficient when I use the pen and paper method that my professor suggested in ...
50
votes
8answers
10k views

I'm a CS student, and honestly, I don't understand Knuth's books

I stumbled upon this quote from Bill Gates: "You should definitely send me a resume if you can read the whole thing." He was talking about The Art of Programming books. So I was pretty curious and ...
46
votes
16answers
3k views

Is big-O really that relevant when working in industry?

In every interview I have been in, I have been quizzed on mathematical analysis of complexity, including big-O notation. My question is, how relevant is this test to development in industry? How often ...
44
votes
7answers
3k views

How important is it for a programmer to know how to implement a QuickSort/MergeSort algorithm from memory?

I was reviewing my notes and stumbled across the implementation of different sorting algorithms. As I attempted to make sense of the implementation of QuickSort and MergeSort, it occurred to me that ...
37
votes
20answers
3k views

Do real-world algorithms that greatly outperform in the class below exist?

Last night I was discussing with another programmer that even though something may be O(1), an operation which is O(n) may outperform it if there are is a large constant in the O(1) algorithm. He ...
34
votes
4answers
4k views

Which algorithms/data structures should I “recognize” and know by name? [closed]

I'd like to consider myself a fairly experienced programmer. I've been programming for over 5 years now. My weak point though is terminology. I'm self-taught, so while I know how to program, I don't ...
31
votes
13answers
3k views

Unit-testing of inherently random/non-deterministic algorithms

My current project, succinctly, involves the creation of "constrainably-random events". I'm basically generating a schedule of inspections. Some of them are based on strict schedule constraints; you ...
31
votes
5answers
2k views

I'd like to write an “ultimate shuffle” algorithm to sort my mp3 collection

I'm looking for pseudocode suggestions for sorting my mp3 files in a way that avoids title and artist repetition. I listen to crooners - Frank Sinatra, Tony Bennett, Ella Fitzgerald etc. singing old ...
30
votes
7answers
5k views

When to use DAG (Directed Acyclic Graph) in programming?

I recently found a framework named ecto. In this framework, a basic component named "plasm", which is the ecto Directed Acyclic Graph.In ecto, plasm can be operated by ecto scheduler. I am ...
30
votes
3answers
1k views

How will quantum computing change programming? [closed]

How is programming a quantum algorithm different? What would a C like language look like if it was designed for qubits? Would types change?
29
votes
9answers
4k views

Why is it impossible to produce truly random numbers?

I was trying to solve a hobby problem that required generating a million random numbers. But I quickly realized, it is becoming difficult to make them unique. I picked up Algorithm Design Manual to ...
29
votes
5answers
3k views

Programming interview question on Trees

I was asked this interview question at a top internet website company recently. Certain empty glasses of water are arranged in the following order When you pour liquid into the 1st glass if ...
28
votes
11answers
3k views

Random number generation algorithm for human brains? [closed]

Are you aware of, or have you devised, any practical, simple-to-learn "in-head" algorithms that let humans generate (somewhat "true") random numbers? By "in-head" I mean.. preferrably without any ...
27
votes
8answers
2k views

What is beautiful code? [closed]

I often read that developers must write beautiful code, but for a beginner as I am it remains obscure of what is beautiful code and how do you recognize it? The corollary question is: How to write ...
27
votes
4answers
2k views

What's the difference between recursion and corecursion?

What's the difference between these? Recursion Corecursion On Wikipedia, there is little information and no clear code explaining these terms. What are some very simple examples explaining these ...
26
votes
8answers
4k views

Is the algorithm more important than the programming language?

During the current (2013) Google Code Jam contest, there was a problem that took C++ and Java people 200+ lines of code as compared to Python people that solved the same problem only using 40 lines of ...
26
votes
4answers
2k views

Can you use Pi as a crude random number generator?

I recently saw this question over at math.SE. It got me thinking. Could Pi be used as a crude random number generator? I mean the results are well known(how long has pi been computed to now?) but, Pi ...
26
votes
9answers
9k views

Color schemes generation - theory and algorithms

I will be generating charts and diagrams and I am looking for some theory on color schemes and algorithm examples. Example questions: How to generate complementary or analogous colors? How to ...
24
votes
9answers
4k views

How to check if 4 points form a square?

Assume I have 4 points (they are 2-dimension), which are different from each other, and I want to know whether they form a square. How to do it? (let the process be as simple as possible.)
23
votes
6answers
10k views

Can an algorithm be patented?

So can an algorithm be patented? I saw this statement which made me think: Everybody would abstain from patenting the improvements of contour dot algorithm for at least several years, say ...
22
votes
12answers
6k views

Do I need to understand algorithms and data structures to be called a programmer? [closed]

It has been six years since I have been coding. Coding into all kinds of things like ActionScript, JavaScript, Java, PHP, Ajax, XML HTML, ASP, etc. I have used arrays, maps, linked lists, sets, etc ...
22
votes
5answers
1k views

Can someone else patent my open-sourced algorithm?

I've written a recursive search algorithm to find the boundaries of a voxel data structure in order to render it more efficiently. I've looked around, and either it's such a simple and obvious ...
21
votes
7answers
3k views

Should I keep investing into data structures and algorithms?

These days, I'm investing heavily in data structures and algorithms and trying to solve some programming puzzles. I'm trying to code and solve with Java and Clojure. Am I wasting my time? should I ...
21
votes
3answers
1k views

What are the data structures behind a spreadsheet?

I would like to understand how a spreadsheet (a group of named or otherwise identified cells containing values or formulas referencing other cells) is solved. I have tried looking at existing ...
20
votes
3answers
2k views

Divide and Conquer algorithms – Why not split in more parts than two?

In divide and conquer algorithms such as quicksort and mergesort, the input is usually (at least in introductory texts) split in two, and the two smaller data sets are then dealt with recursively. It ...
20
votes
6answers
13k views

Why is quicksort better than other sorting algorithms in practice?

This is a repost of a question on cs.SE by Janoma. Full credits and spoils to him or cs.SE. In a standard algorithms course we are taught that quicksort is O(n log n) on average and O(n²) in the ...
20
votes
9answers
6k views

Are algorithm questions good interview questions? [closed]

I've had an argument recently with a fellow programmer. He was interviewing for a new position and was asked this question: Give a sequence of numbers starting at X and ending in Y but with one ...
20
votes
3answers
751 views

How do I express subtle relationships in my data?

"A" is related to "B" and "C". How do I show that "B" and "C" might, by this context, be related as well? Example: Here are a few headlines about a recent Broadway play: David Mamet's Glengarry ...
20
votes
4answers
3k views

Which algorithms and data structures should a developer absolutely know?

I want to be a successful enterprise Java developer. With what algorithms and data structures should I be well versed? What books would you recommend to me? To be a successful Java developer, do I ...
19
votes
9answers
5k views

Is it essential to learn algorithms to be a real programmer?

I'm a PHP programmer, and until now I have not needed to learn algorithms... Now I'm start learning Python (a real programming language), because I need to use matplotlib. Does it make sense to start ...
19
votes
4answers
3k views

Is MapReduce anything more than just an application of divide and conquer?

Dividing a problem to smaller ones until the individual problems can be solved independently and then combining them to answer the original question is known as the divide and conquer algorithm design ...
19
votes
2answers
923 views

What class of problem is this, and what math do I need to know to solve it?

Mushroom cultivation requires fairly precise chemical composition of substrate (a.k.a. growing medium). Let's pretend we're growing shitakes and that this is the required composition of their ...
18
votes
4answers
892 views

Why do most languages provide a min-heap instead of a max-heap implementation?

I just noticed something and I wonder if there is any reason for that. Except for C++ (std::priority_queue is a max heap), I don't know any other language that offers a max heap. Python's heapq ...
18
votes
6answers
593 views

Visiting points on a number line while minimizing a cost not related to distance

I need some help on this ACM ICPC problem. My current idea is to model this as a shortest path problem, which is described under the problem statement. Problem There are N = 1000 nuclear waste ...
17
votes
4answers
4k views

In pseudo code what does := mean?

The section entitled Algorithmic Implementation has the following code: // Return RC low-pass filter output samples, given input samples, // time interval dt, and time constant RC function ...
17
votes
8answers
3k views

Is having trouble with data structures common for beginners?

I'm taking my second course on Java. We are getting into data structures. I have done an assignment on a linked list, and now a stack. I had a hard time with the linked list. The stack gave me a ...
17
votes
6answers
4k views

What methods are there to avoid a stack overflow in a recursive algorithm?

Question What are the possible ways to solve a stack overflow caused by an recursive algorithm? Example I'm trying to solve Project Euler problem 14 and decided to try it with a recursive ...
16
votes
6answers
1k views

Tool that turns truth table into smallest possible if / else block

Is there any application or tool that will take a truth table and turn it into a compacted if block? For instance, lets say I have this truth table where A and B are conditions and x, y and z are ...
16
votes
1answer
611 views

What algorithms are there for picking colors for plot lines on graphs?

I'm interested in what algorithms or rules I can programmatically implement to generate RGB or HSV colors for plotlines to keep them visually distinct from the neighbors. I know that in professional ...
16
votes
8answers
1k views

Strategy/algorithm to divide fair teams based on history

We are a group of people playing floorball together on a regular basis. Every session starts with the daunting task of dividing teams... So what would be better than an application to pick teams ...
16
votes
2answers
8k views

Best practice/Patterns for two way data synchronisation

Quite often in my work the idea of 2-way data synchronisation between database systems crops up. The classic example is two slightly different CRM systems (say, Raiser's Edge and Salesforce) and the ...
15
votes
4answers
3k views

Return random `list` item by its `weight`

I have, for example, this table +-----------------+ | fruit | weight | +-----------------+ | apple | 4 | | orange | 2 | | lemon | 1 | +-----------------+ I need to return random ...
15
votes
6answers
869 views

TDD and complete test coverage where exponential test cases are needed

I am working on a list comparator to assist sorting an unordered list of search results per very specific requirements from our client. The requirements call for a ranked relevance algorithm with the ...