<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=88.72.253.68</id>
	<title>formulasearchengine - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=88.72.253.68"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/wiki/Special:Contributions/88.72.253.68"/>
	<updated>2026-08-24T21:42:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.47.0-wmf.7</generator>
	<entry>
		<id>https://en.formulasearchengine.com/w/index.php?title=Pieri%27s_formula&amp;diff=23938</id>
		<title>Pieri&#039;s formula</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/w/index.php?title=Pieri%27s_formula&amp;diff=23938"/>
		<updated>2011-08-29T17:41:05Z</updated>

		<summary type="html">&lt;p&gt;88.72.253.68: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In [[computer science]], the &#039;&#039;&#039;Hunt–McIlroy algorithm&#039;&#039;&#039; is a solution to the [[longest common subsequence problem]].  It was one of the first non-heuristic algorithms used in [[diff]].  To this day, variations of this algorithm are found in incremental [[version control system]]s, [[wiki software|wiki engine]]s, and [[molecular phylogenetics]] research software.&lt;br /&gt;
&lt;br /&gt;
The research accompanying the final version of [[Unix]] &amp;lt;tt&amp;gt;[[diff]]&amp;lt;/tt&amp;gt;, written by [[Douglas McIlroy]], was published in the 1976 paper &amp;quot;An Algorithm for Differential File Comparison&amp;quot;, co-written with [[James W. Hunt]], who developed an initial prototype of diff.&amp;lt;ref&amp;gt;{{cite journal|author=James W. Hunt and M. Douglas McIlroy|title=An Algorithm for Differential File Comparison|volume=41|journal=Computing Science Technical Report, Bell Laboratories|month=June | year=1976|pages=|url=http://cm.bell-labs.com/cm/cs/cstr/41.pdf}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Algorithm==&lt;br /&gt;
The Hunt–McIlroy algorithm is a modification to a basic solution for the longest common subsequence problem. The solution is modified so that there are lower time and space requirements for the algorithm when it is working with typical inputs.&lt;br /&gt;
&lt;br /&gt;
===Basic Longest Common Subsequence Solution===&lt;br /&gt;
&lt;br /&gt;
====Algorithm====&lt;br /&gt;
Let A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; be the &#039;&#039;i&#039;&#039;th line of the first file.&lt;br /&gt;
&lt;br /&gt;
Let B&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt; be the &#039;&#039;j&#039;&#039;th line of the second file.&lt;br /&gt;
&lt;br /&gt;
Let P&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; be the length of the longest common subsequence for the first i lines of the first file and the first j lines of the second file.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
P_{ij} =&lt;br /&gt;
\begin{cases}&lt;br /&gt;
  0&lt;br /&gt;
&amp;amp; \mbox{ if }\ i = 0 \mbox{ or }  j = 0 \\&lt;br /&gt;
  1 + P_{i-1, j-1}&lt;br /&gt;
&amp;amp; \mbox{ if } A_i = B_j \\&lt;br /&gt;
  max(P_{i-1, j}, P_{i, j-1})&lt;br /&gt;
&amp;amp; \mbox{ if } A_i \ne B_j \\&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
[[File:Longest Common Subsequence Recursion.png|thumb|A table showing the recursive steps the basic longest common subsequence algorithm takes.]]&lt;br /&gt;
Consider the files A and B.&lt;br /&gt;
&lt;br /&gt;
A contains three lines:&lt;br /&gt;
* A&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; = a&lt;br /&gt;
* A&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; = b&lt;br /&gt;
* A&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; = c&lt;br /&gt;
&lt;br /&gt;
B contains three lines:&lt;br /&gt;
* B&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; = a&lt;br /&gt;
* B&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; = c&lt;br /&gt;
* B&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; = b&lt;br /&gt;
&lt;br /&gt;
The steps the above algorithm would perform to determine the length of the longest common subsequence for both files are shown in the diagram. The algorithm correctly reports that the longest common subsequence of the two files is two lines long.&lt;br /&gt;
&lt;br /&gt;
====Complexity====&lt;br /&gt;
The above algorithm has worst-case time and space complexities of &amp;lt;math&amp;gt;O(mn)&amp;lt;/math&amp;gt; (see [[big O notation]]), where m is the number of lines in file A and n is the number of lines in file B. The Hunt–McIlroy algorithm modifies this algorithm to have a worst case time complexity of &amp;lt;math&amp;gt;O(mn log m)&amp;lt;/math&amp;gt; and space complexity of &amp;lt;math&amp;gt;O(mn)&amp;lt;/math&amp;gt;, though it regularly beats the worst-case with typical inputs.&lt;br /&gt;
&lt;br /&gt;
===Essential Matches===&lt;br /&gt;
&lt;br /&gt;
====k-candidates====&lt;br /&gt;
The Hunt–McIlroy algorithm only considers what the authors call essential matches, or k-candidates. k-candidates are pairs of indices (i, j) such that:&lt;br /&gt;
* A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = B&amp;lt;sub&amp;gt;j&amp;lt;/sub&amp;gt;&lt;br /&gt;
* P&amp;lt;sub&amp;gt;ij&amp;lt;/sub&amp;gt; &amp;gt; max(P&amp;lt;sub&amp;gt;i-1, j&amp;lt;/sub&amp;gt;, P&amp;lt;sub&amp;gt;i, j-1&amp;lt;/sub&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
The second point implies two properties of k-candidates:&lt;br /&gt;
* There is a common subsequence of length k in the first i lines of file A and the first j lines of file B.&lt;br /&gt;
* There are no common subsequences of length k for any fewer than i lines of file A or j lines of file B.&lt;br /&gt;
&lt;br /&gt;
====Connecting k-candidates====&lt;br /&gt;
[[File:K Candidate Diagram.png|thumb|A diagram that shows how using k-candidates reduces the amount of time and space needed to find the longest common subsequence of two files.]]&lt;br /&gt;
To create the longest common subsequence from a collection of k-candidates, a grid with each file&#039;s contents on each axis is created. The k-candidates are marked on the grid. A common subsequence can be created by joining marked coordinates of the grid such that any increase in i is accompanied by an increase in j.&lt;br /&gt;
&lt;br /&gt;
This is illustrated in the diagram to the right.&lt;br /&gt;
&lt;br /&gt;
Black dots represent candidates that would have to be considered by the simple algorithm and the black lines are connections that create common subsequences of length 3.&lt;br /&gt;
&lt;br /&gt;
Red dots represent k-candidates that are considered by the Hunt–McIlroy algorithm and the red line is the connection that creates a common subsequence of length 3.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Levenshtein distance]]&lt;br /&gt;
* [[Longest common subsequence problem]]&lt;br /&gt;
* [[Wagner–Fischer algorithm]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Hunt-McIlroy algorithm}}&lt;br /&gt;
[[Category:Algorithms on strings]]&lt;br /&gt;
[[Category:Combinatorics]]&lt;br /&gt;
[[Category:Dynamic programming]]&lt;/div&gt;</summary>
		<author><name>88.72.253.68</name></author>
	</entry>
</feed>