<p>It is a tough problem to give even a coherent definition of "Algorithm A is similar to Algorithm B". For one, I don't think that "they must be solving the same problem" is a necessary condition. Often when one says in a paper that "the algorithm $A$ of Theorem $2$ is similar to the algorithm $B$ in Theorem $1$", the algorithm $A$ is actually solving a different problem than that of $B$, but has some minor modifications to handle the new problem. </p>

<p>Even trying to determine what it means for two algorithms to be <strong>the same</strong> is an interesting and difficult problem. See the paper "When are two algorithms the same?" <a href="http://research.microsoft.com/~gurevich/Opera/192.pdf">http://research.microsoft.com/~gurevich/Opera/192.pdf</a> </p>

CC BY-SA 3.0
2012-03-06T07:18:26.223Z
2012-03-06T07:18:26.223Z
Ryan Williams
<p>More often than not, it means "I don't want to write out Algorithm B in detail, because all the interesting details are nearly identical to those in Algorithm A, and I don't want to go over the 10-page limit, and anyway the submission deadline is in three hours."</p>

CC BY-SA 3.0
2012-03-06T08:01:52.427Z
2012-03-06T08:01:52.427Z
Jeffε
<p>If you mean "similar" in the colloquial sense, I think JeffE's answer captures what some people mean.</p>

<p>In a technical sense though, it depends on what you care about. If asymptotic time complexity is all you care about, the difference between recursion and iteration may not matter. If computatability  is all you care about, the difference between a counter variable and a one-symbol stack do not matter.</p>

<p>To compare algorithms, a first step would be to make the notion of equivalence precise. Intuitively, let $A$ be the space of algorithms and $M$ be a space of mathematical objects and $\mathit{sem}: A \to M$ be a function encoding that $\mathit{sem}(P)$ is the meaning of algorithm $P$. The space $M$ could contain anything ranging from the number of variables in your algorithm, to its state-graph or it's time complexity. I don't believe there is an absolute notion of what $M$ can be. Given $M$ though, we can say two algorithms are equivalent if $\mathit{sem}(P)$ equals $\mathit{sem}(Q)$. Let me add that I think each of the five criteria you mentioned can be formalised mathematically in this manner.</p>

<p>If we want to talk about an algorithm being more general than another (or an algorithm refining another), I would endow $M$ with more structure. Imagine that $(M, \sqsubseteq)$ is a partially ordered set and the order $x \sqsubseteq y$ encodes that $x$ is a more defined object than $y$. For example, if $M$ contains sets of traces of an algorithm and $\sqsubseteq$ is set inclusion, $\mathit{sem}(P) \sqsubseteq \mathit{sem}(Q)$ means that every trace of $P$ is a trace of $Q$. We can interpret this as saying that  $P$ is more deterministic than $Q$. </p>

<p>Next, we could ask if it's possible to quantify how close two algorithms are. In this case, I would imagine that $M$ has to be endowed with a metric. Then, we can measure the distance between the mathematical objects that two algorithms represent. Further possibilities are to map algorithms to measure spaces or probability spaces and compare them using other criteria. </p>

<p>More generally, I would ask - what do you care about (in intuitive terms), what are the mathematical objects representing these intuitive properties, how can I map from algorithms to these objects, and what is the structure of this space? I would also ask if the space of objects enjoys enough structure to admit a notion of similarity. This is the approach I would take coming from a programming language semantics perspective. I'm not sure if you find this approach appealing, given the vastly different cultures of thought in computer science.</p>

CC BY-SA 3.0
2012-03-07T07:57:17.817Z
2012-03-07T07:57:17.817Z
Vijay D
<p>Along the lines of Jeff's answer, two algorithms are similar if the author of one of them expects that the author of the other one might be reviewing her paper. </p>

<p>But joking aside, in the theory community, I would say that what problem algorithm A is solving is rather tangental to whether it is "similar" to algorithm B, which might be solving a completely different problem. A is similar to B if it "works" because of the same main theoretical idea. For example, is the main idea in both algorithms that you can project the data into a much lower dimensional space, preserve norms with the Johnson-Lindenstrauss lemma, and then do a brute-force search? Then your algorithm is similar to other algorithms that do this, no matter what problem you are solving. There are some small number of heavy-duty algorithmic techniques that can be used to solve a wide variety of problems, and I would think that these techniques form the centroids of many sets of "similar" algorithms. </p>

CC BY-SA 3.0
2012-03-08T12:55:50.360Z
2012-03-08T12:55:50.360Z
Aaron Roth
<p>Very interesting question, and very nice paper Ryan!</p>

<p>I do definitely agree with the idea that making an assessment on the overall similarity between algorithms is mainly a subjective value judgement. While from a technical point of view there are a number of features that are closely observed to decide upon the similarity of algorithms, in the end, it is also a matter of personal taste. I will try to provide a description of the importance of both sides of the same coin while referring to the particular points of your question:</p>

<p>From a technical point of view:</p>

<ol>
<li>Ryan already pointed out that both algorithms <strong>must solve the same problem</strong>. One could go even further and generalize this notion by saying that it is usually enough to prove that there is a polynomial transformation of the same instance that is understoodable by algorithm A so that algorithm B can handle it. However, this would be actually very weak. I do prefer to think of the similarity in a stronger sense. </li>
<li>However, I would never expect for two equivalent algorithms to have the same intuitive idea ---though, again, this is a definition which ain't easy to capture. More than that, it is often the case that algorithms that are deemed to be similar do not follow the main rationale. Consider for example some sorting algorithms which however, originated in different ways following different ideas. As an extreme example consider genetic algorithms which are usually considered by the mathematical community just as stochastic processes (and therefore they are equivalent in their view) which are then modeled and analyzed in quite a different way. </li>
<li>Moreover, I would even generalize this notion to say that other technicalities such as the termination condition or the pre-processing stage do not matter often. But this is not always the case. See for example <a href="http://www.aaai.org/ocs/index.php/SOCS/SOCS11/paper/view/4017" rel="nofollow">Dijkstra's Algorithm versus Uniform Cost Search or a Case Against Dijkstra's Algorithm</a>. Both algorithms are so close that most people do not tell the difference, yet the differences (being technical) were very important for the author of that paper. Much the same happens with the pre-processing step. In case you are familiar with the $N$-puzzle, then observe that an A$^*$-like search algorithm using the Manhattan distance or $(N^2-1)$ additive pattern databases would actually expand the same number of nodes in exactly the same order, and that makes both algorithms (and their heuristics) to be strictly equivalent in a very strong sense, whereas the first approach has no pre-processing and the second one has a significant overhead before starting to solve a particular instance. However, as soon as your Pattern Databases consider more simulatenous interactions there is a huge gap in performance between them, so that they are definitely different ideas/algorithms.</li>
<li>As a matter of fact, I think that most people would judge algorithms for their <strong>purpose</strong> and <strong>performance</strong>. Therefore, asymptotic performance is a good metric to reason about the similarity between programs. However, bear in mind that this performance is not necessarily the typical case so that if two algorithms have the same asymptotic performance but behave differently in practice, then you would probably conclude that they are different. The strong evidence in this regard would be that both algorithms have the same performance both on time and memory (and this, as Suresh said, makes DFS and BFS to look different). In case this assertion does not sound convincing to you, please refer to the excellent (and very recommended book): <a href="http://books.google.es/books?id=lOXtkUMjQpsC&amp;dq=%22Programming+the+Universe%22&amp;hl=es&amp;sa=X&amp;ei=yypXT8fzFee90QXOs8G5DQ&amp;redir_esc=y" rel="nofollow">Programming the Universe</a> by Seth Lloyd. In page 189 he refers to a list with more than 30 measures of complexity that can be used to regard algorithms as being different.</li>
</ol>

<p>So what makes algorithms to be similar/different? In my view (and this is purely speculative), the main difference is about what they suggest to you. Many, many (many!) algorithms differ just in a few technicalities when serving to the same purpose so that the typical case is different for different ranges of the input. However, the greatest of all differences is (to my eye) what they suggest to you. Algorithms have different capabilities and therefore their own strengths and weaknesses. If two algorithms look like being the same but might be extended in different ways to cope with different cases then I would conclude that they are different. Often, however, two algorithms do look much the same so that you would regard them to be the same ... until someone arrives making a key distinction and suddenly, they are completely different!</p>

<p>Sorry, my response was in the end so long ... </p>

<p>Cheers,</p>

CC BY-SA 3.0
2012-05-10T06:21:05.867Z
Actually, Ryan suggested that it is *not* necessary for both algorithms to solve the same problem.
Jeffε
CC BY-SA 3.0
2012-05-12T12:17:29.463Z
True! I was just collecting my opinions in this regard, but you are definitely right!
Carlos Linares López
CC BY-SA 3.0
2012-03-07T09:44:56.337Z
2012-03-07T09:44:56.337Z
Carlos Linares López
<p>Any mention of similarity without defining a similarity <a href="http://en.wikipedia.org/wiki/Metric_%28mathematics%29" rel="nofollow">metric</a> is not well-defined. There are many ways in which two algorithms can be similar:</p>

<p>Quicksort and Mergesort solve very similar problems, but they use different algorithms to do so. They have similar algorithmic complexity (although their worst-case performance and memory usage can vary). Quicksort and Mergesort are both similar to Bubblesort,however Bubblesort has very different performance metrics. If you ignore complexity statistics Quicksort, Mergesort and Bubblesort are all in the same equivalence class. However, if you care at all about algorithmic complexity, then Quicksort and Mergesort are much more similar to each other than either is to Bubblesort. </p>

<p>Smith-Waterman dynamic programming and HMM-sequence comparison attempt to solve the problem of aligning two sequences. However, they take different inputs. Smith-Waterman takes two sequences as input, and HMM-sequence comparisons take a HMM and a sequence as input. Both output sequence alignments. In terms of motivating ideas, both of these are similar to <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow">Levenshtein's edit distance</a>, but only at a very high level. </p>

<p>Here are some criteria by which two algorithms might be called similar:</p>

<ol>
<li>Input/output types</li>
<li>Algorithmic/Memory Complexity</li>
<li>Assumptions about types of inputs (eg only positive numbers or floating point stability)</li>
<li>Nested relationships (eg some algorithms are special cases of others)</li>
</ol>

<p>The critical decision about the meaning of similarity remains. Sometimes you care about the complexity of an algorithm, sometimes you don't. As the definition of similarity depends on the context of the discussion, the term "similar algorithm" isn't well-defined. </p>

CC BY-SA 3.0
2012-03-13T02:50:21.763Z
2012-03-13T02:50:21.763Z
James Thompson
<p>I do not work in theory, but my work requires reading (and understanding) theory papers every once in a while. Once I understand a (set of) results, I discuss these results with people I work with, most of whom do not work in theory as well. During one of such discussions, the following question came up:</p>

<p>When does one say that two given algorithms are "similar"?</p>

<p>What do I mean by "similar"? Let us say that two algorithms are said to be similar if you can make either of the following claims in a paper without confusing/annoying any reviewer (better definitions welcomed):</p>

<p>Claim 1.  "Algorithm $A$, which is similar to algorithm $B$, also solves problem $X$" </p>

<p>Claim 2. "Our algorithm is similar to Algorithm $C$"</p>

<p>Let me make it slightly more specific. Suppose we are working with graph algorithms. First some necessary conditions for the two algorithms to be similar:</p>

<ol>
<li>They must be solving the same problem.</li>
<li>They must have the same high level intuitive idea.</li>
</ol>

<p>For instance, talking about graph traversal, breadth-first and depth-first traversal satisfy the above two conditions; for shortest-path computations, breadth-first and Dijkstra's algorithm satisfy the above two conditions (on unweighted graphs, of course); etc.</p>

<p>Are these also sufficient conditions? More specifically, suppose two algorithms satisfy the necessary conditions to be similar. Would you indeed call them similar, if</p>

<ol>
<li>they have different asymptotic performance?</li>
<li>for a special class of graphs, one algorithm requires $\Omega(n)$ time while the other requires $O(n^{1/3})$ time?</li>
<li>they have different terminating conditions? (recall, they are solving the same problem)</li>
<li>the pre-processing step is different in the two algorithms?</li>
<li>the memory complexity is different in the two algorithms?</li>
</ol>

<p>Edit: The question is clearly very context dependent and is subjective. I was hoping that the above five conditions, however, will allow getting some suggestions. I am happy to further modify the question and give more details, if needed to get an answer. Thanks!</p>

CC BY-SA 3.0
2012-03-06T06:37:33.530Z
it really depends on the context. For example, for certain sequential algorithms, DFS and BFS are very different and one might not even work. In parallel settings, DFS  (or at least one variant) is P-complete, whereas BFS is "easy in parallel".
Suresh Venkat
CC BY-SA 3.0
2012-03-06T06:44:21.023Z
@SureshVenkat -- I agree that the question is very context dependent. In the interest of not starting a debate, I refrained from taking names of "the two algorithms" at the risk of sounding vague :-)
Rachit
CC BY-SA 3.0
2012-03-06T06:49:37.837Z
The problem is that there is close and there is close. There's a way of thinking of the multiplicative-weight-update method as "essentially a binary search", but in the wrong context this would sound insane. FWIW, in all of your cases above I can imagine declaring the two algorithms to be different.
Suresh Venkat
CC BY-SA 3.0
2012-03-06T07:04:08.787Z
This question seems too subjective to me. You're basically asking for a definition of "similar", when no canonical definition exists.
Joe
CC BY-SA 3.0
2012-03-06T07:11:01.817Z
@Joe -- I agree. I was hoping that the five conditions I outlined would help because these conditions apply to the two algorithms in our case.
Rachit
CC BY-SA 3.0
2012-03-06T09:33:48.943Z
An argument can be made that breadth-first search *is* Dijkstra's algorithm applied to unweighted graphs. It just uses a particular heap implementation which is appropriate for the task. This illustrates Ryan Williams' answer.
Peter Taylor
CC BY-SA 3.0
2012-03-06T11:43:17.893Z
Somewhat related: http://cstheory.stackexchange.com/questions/9409/when-can-we-say-that-two-programs-are-different
Radu GRIGore
CC BY-SA 3.0
2012-03-06T21:31:44.600Z
The discussion here on equivalent proofs may also help - http://gowers.wordpress.com/2007/10/04/when-are-two-proofs-essentially-the-same/
Turbo
<ds.algorithms><graph-algorithms>
When are two algorithms said to be "similar"?
Rachit
# When are two algorithms said to be "similar"?

(Asked by: username_0 on 2012-03-06)

I do not work in theory, but my work requires reading (and understanding) theory papers every once in a while. Once I understand a (set of) results, I discuss these results with people I work with, most of whom do not work in theory as well. During one of such discussions, the following question came up:

When does one say that two given algorithms are "similar"?

What do I mean by "similar"? Let us say that two algorithms are said to be similar if you can make either of the following claims in a paper without confusing/annoying any reviewer (better definitions welcomed):

Claim 1. "Algorithm $A$, which is similar to algorithm $B$, also solves problem $X$"

Claim 2. "Our algorithm is similar to Algorithm $C$"

Let me make it slightly more specific. Suppose we are working with graph algorithms. First some necessary conditions for the two algorithms to be similar:

1. They must be solving the same problem.
2. They must have the same high level intuitive idea.

For instance, talking about graph traversal, breadth-first and depth-first traversal satisfy the above two conditions; for shortest-path computations, breadth-first and Dijkstra's algorithm satisfy the above two conditions (on unweighted graphs, of course); etc.

Are these also sufficient conditions? More specifically, suppose two algorithms satisfy the necessary conditions to be similar. Would you indeed call them similar, if

1. they have different asymptotic performance?
2. for a special class of graphs, one algorithm requires $\Omega(n)$ time while the other requires $O(n^{1/3})$ time?
3. they have different terminating conditions? (recall, they are solving the same problem)
4. the pre-processing step is different in the two algorithms?
5. the memory complexity is different in the two algorithms?

Edit: The question is clearly very context dependent and is subjective. I was hoping that the above five conditions, however, will allow getting some suggestions. I am happy to further modify the question and give more details, if needed to get an answer. Thanks!

**Tags:** ds.algorithms, graph-algorithms
> **Comments:**
> **username_1**: it really depends on the context. For example, for certain sequential algorithms, DFS and BFS are very different and one might not even work. In parallel settings, DFS  (or at least one variant) is P-complete, whereas BFS is "easy in parallel".  
> **username_0**: @SureshVenkat -- I agree that the question is very context dependent. In the interest of not starting a debate, I refrained from taking names of "the two algorithms" at the risk of sounding vague :-)  
> **username_1**: The problem is that there is close and there is close. There's a way of thinking of the multiplicative-weight-update method as "essentially a binary search", but in the wrong context this would sound insane. FWIW, in all of your cases above I can imagine declaring the two algorithms to be different.  
> **username_2**: This question seems too subjective to me. You're basically asking for a definition of "similar", when no canonical definition exists.  
> **username_0**: @Joe -- I agree. I was hoping that the five conditions I outlined would help because these conditions apply to the two algorithms in our case.  
> **username_3**: An argument can be made that breadth-first search *is* Dijkstra's algorithm applied to unweighted graphs. It just uses a particular heap implementation which is appropriate for the task. This illustrates Ryan Williams' answer.  
> **username_4**: Somewhat related: http://cstheory.stackexchange.com/questions/9409/when-can-we-say-that-two-programs-are-different  
> **username_5**: The discussion here on equivalent proofs may also help - http://gowers.wordpress.com/2007/10/04/when-are-two-proofs-essentially-the-same/  

---

## 6 answers

### Answer by username_6 on 2012-03-06. Score: 23

It is a tough problem to give even a coherent definition of "Algorithm A is similar to Algorithm B". For one, I don't think that "they must be solving the same problem" is a necessary condition. Often when one says in a paper that "the algorithm $A$ of Theorem $2$ is similar to the algorithm $B$ in Theorem $1$", the algorithm $A$ is actually solving a different problem than that of $B$, but has some minor modifications to handle the new problem.

Even trying to determine what it means for two algorithms to be **the same** is an interesting and difficult problem. See the paper "When are two algorithms the same?" <http://research.microsoft.com/~gurevich/Opera/192.pdf>


---

### Answer by username_7 on 2012-03-06. Score: 17

More often than not, it means "I don't want to write out Algorithm B in detail, because all the interesting details are nearly identical to those in Algorithm A, and I don't want to go over the 10-page limit, and anyway the submission deadline is in three hours."


---

### Answer by username_8 on 2012-03-07. Score: 7

If you mean "similar" in the colloquial sense, I think JeffE's answer captures what some people mean.

In a technical sense though, it depends on what you care about. If asymptotic time complexity is all you care about, the difference between recursion and iteration may not matter. If computatability is all you care about, the difference between a counter variable and a one-symbol stack do not matter.

To compare algorithms, a first step would be to make the notion of equivalence precise. Intuitively, let $A$ be the space of algorithms and $M$ be a space of mathematical objects and $\mathit{sem}: A \to M$ be a function encoding that $\mathit{sem}(P)$ is the meaning of algorithm $P$. The space $M$ could contain anything ranging from the number of variables in your algorithm, to its state-graph or it's time complexity. I don't believe there is an absolute notion of what $M$ can be. Given $M$ though, we can say two algorithms are equivalent if $\mathit{sem}(P)$ equals $\mathit{sem}(Q)$. Let me add that I think each of the five criteria you mentioned can be formalised mathematically in this manner.

If we want to talk about an algorithm being more general than another (or an algorithm refining another), I would endow $M$ with more structure. Imagine that $(M, \sqsubseteq)$ is a partially ordered set and the order $x \sqsubseteq y$ encodes that $x$ is a more defined object than $y$. For example, if $M$ contains sets of traces of an algorithm and $\sqsubseteq$ is set inclusion, $\mathit{sem}(P) \sqsubseteq \mathit{sem}(Q)$ means that every trace of $P$ is a trace of $Q$. We can interpret this as saying that $P$ is more deterministic than $Q$.

Next, we could ask if it's possible to quantify how close two algorithms are. In this case, I would imagine that $M$ has to be endowed with a metric. Then, we can measure the distance between the mathematical objects that two algorithms represent. Further possibilities are to map algorithms to measure spaces or probability spaces and compare them using other criteria.

More generally, I would ask - what do you care about (in intuitive terms), what are the mathematical objects representing these intuitive properties, how can I map from algorithms to these objects, and what is the structure of this space? I would also ask if the space of objects enjoys enough structure to admit a notion of similarity. This is the approach I would take coming from a programming language semantics perspective. I'm not sure if you find this approach appealing, given the vastly different cultures of thought in computer science.


---

### Answer by username_9 on 2012-03-08. Score: 5

Along the lines of Jeff's answer, two algorithms are similar if the author of one of them expects that the author of the other one might be reviewing her paper.

But joking aside, in the theory community, I would say that what problem algorithm A is solving is rather tangental to whether it is "similar" to algorithm B, which might be solving a completely different problem. A is similar to B if it "works" because of the same main theoretical idea. For example, is the main idea in both algorithms that you can project the data into a much lower dimensional space, preserve norms with the Johnson-Lindenstrauss lemma, and then do a brute-force search? Then your algorithm is similar to other algorithms that do this, no matter what problem you are solving. There are some small number of heavy-duty algorithmic techniques that can be used to solve a wide variety of problems, and I would think that these techniques form the centroids of many sets of "similar" algorithms.


---

### Answer by username_10 on 2012-03-07. Score: 3

Very interesting question, and very nice paper Ryan!

I do definitely agree with the idea that making an assessment on the overall similarity between algorithms is mainly a subjective value judgement. While from a technical point of view there are a number of features that are closely observed to decide upon the similarity of algorithms, in the end, it is also a matter of personal taste. I will try to provide a description of the importance of both sides of the same coin while referring to the particular points of your question:

From a technical point of view:

1. Ryan already pointed out that both algorithms **must solve the same problem**. One could go even further and generalize this notion by saying that it is usually enough to prove that there is a polynomial transformation of the same instance that is understoodable by algorithm A so that algorithm B can handle it. However, this would be actually very weak. I do prefer to think of the similarity in a stronger sense.
2. However, I would never expect for two equivalent algorithms to have the same intuitive idea ---though, again, this is a definition which ain't easy to capture. More than that, it is often the case that algorithms that are deemed to be similar do not follow the main rationale. Consider for example some sorting algorithms which however, originated in different ways following different ideas. As an extreme example consider genetic algorithms which are usually considered by the mathematical community just as stochastic processes (and therefore they are equivalent in their view) which are then modeled and analyzed in quite a different way.
3. Moreover, I would even generalize this notion to say that other technicalities such as the termination condition or the pre-processing stage do not matter often. But this is not always the case. See for example [Dijkstra's Algorithm versus Uniform Cost Search or a Case Against Dijkstra's Algorithm](http://www.aaai.org/ocs/index.php/SOCS/SOCS11/paper/view/4017). Both algorithms are so close that most people do not tell the difference, yet the differences (being technical) were very important for the author of that paper. Much the same happens with the pre-processing step. In case you are familiar with the $N$-puzzle, then observe that an A$^\*$-like search algorithm using the Manhattan distance or $(N^2-1)$ additive pattern databases would actually expand the same number of nodes in exactly the same order, and that makes both algorithms (and their heuristics) to be strictly equivalent in a very strong sense, whereas the first approach has no pre-processing and the second one has a significant overhead before starting to solve a particular instance. However, as soon as your Pattern Databases consider more simulatenous interactions there is a huge gap in performance between them, so that they are definitely different ideas/algorithms.
4. As a matter of fact, I think that most people would judge algorithms for their **purpose** and **performance**. Therefore, asymptotic performance is a good metric to reason about the similarity between programs. However, bear in mind that this performance is not necessarily the typical case so that if two algorithms have the same asymptotic performance but behave differently in practice, then you would probably conclude that they are different. The strong evidence in this regard would be that both algorithms have the same performance both on time and memory (and this, as Suresh said, makes DFS and BFS to look different). In case this assertion does not sound convincing to you, please refer to the excellent (and very recommended book): [Programming the Universe](http://books.google.es/books?id=lOXtkUMjQpsC&dq=%22Programming+the+Universe%22&hl=es&sa=X&ei=yypXT8fzFee90QXOs8G5DQ&redir_esc=y) by Seth Lloyd. In page 189 he refers to a list with more than 30 measures of complexity that can be used to regard algorithms as being different.

So what makes algorithms to be similar/different? In my view (and this is purely speculative), the main difference is about what they suggest to you. Many, many (many!) algorithms differ just in a few technicalities when serving to the same purpose so that the typical case is different for different ranges of the input. However, the greatest of all differences is (to my eye) what they suggest to you. Algorithms have different capabilities and therefore their own strengths and weaknesses. If two algorithms look like being the same but might be extended in different ways to cope with different cases then I would conclude that they are different. Often, however, two algorithms do look much the same so that you would regard them to be the same ... until someone arrives making a key distinction and suddenly, they are completely different!

Sorry, my response was in the end so long ...

Cheers,

> **Comments:**
> **username_7**: Actually, Ryan suggested that it is *not* necessary for both algorithms to solve the same problem.  
> **username_10**: True! I was just collecting my opinions in this regard, but you are definitely right!  

---

### Answer by username_11 on 2012-03-13. Score: 2

Any mention of similarity without defining a similarity [metric](http://en.wikipedia.org/wiki/Metric_%28mathematics%29) is not well-defined. There are many ways in which two algorithms can be similar:

Quicksort and Mergesort solve very similar problems, but they use different algorithms to do so. They have similar algorithmic complexity (although their worst-case performance and memory usage can vary). Quicksort and Mergesort are both similar to Bubblesort,however Bubblesort has very different performance metrics. If you ignore complexity statistics Quicksort, Mergesort and Bubblesort are all in the same equivalence class. However, if you care at all about algorithmic complexity, then Quicksort and Mergesort are much more similar to each other than either is to Bubblesort.

Smith-Waterman dynamic programming and HMM-sequence comparison attempt to solve the problem of aligning two sequences. However, they take different inputs. Smith-Waterman takes two sequences as input, and HMM-sequence comparisons take a HMM and a sequence as input. Both output sequence alignments. In terms of motivating ideas, both of these are similar to [Levenshtein's edit distance](http://en.wikipedia.org/wiki/Levenshtein_distance), but only at a very high level.

Here are some criteria by which two algorithms might be called similar:

1. Input/output types
2. Algorithmic/Memory Complexity
3. Assumptions about types of inputs (eg only positive numbers or floating point stability)
4. Nested relationships (eg some algorithms are special cases of others)

The critical decision about the meaning of similarity remains. Sometimes you care about the complexity of an algorithm, sometimes you don't. As the definition of similarity depends on the context of the discussion, the term "similar algorithm" isn't well-defined.


---

