-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Soumik Sarkar: Add source for tree reroot fold (#67)
- Loading branch information
Showing
3 changed files
with
35 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>RerootFold</title><link href="linuwial.css" rel="stylesheet" type="text/css" title="Linuwial" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><span class="caption">haccepted-0.1.0.0: Data structures and algorithms</span><ul class="links" id="page-menu"><li><a href="src/RerootFold.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">RerootFold</p></div><div id="description"><p class="caption">Description</p><div class="doc"><h2>Tree reroot fold</h2><p>Folds of a tree with every node as root. | ||
Known as "tree rerooting DP", among other names.</p><p>Recall that Data.Tree has foldTree :: (a -> [c] -> c) -> Tree a -> c. foldReroot is similar but | ||
requires (b -> c -> b) and b to perform strict folds over [c].</p><p>g :: b -> c -> b must be commutative, in the sense that | ||
(b <code>g</code> c1) <code>g</code> c2 = (b <code>g</code> c2) <code>g</code> c1</p><p>Sources:</p><ul><li>Informal discussions. I am unable to find a good published source for this technique :(</li></ul></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><a href="#v:foldReroot">foldReroot</a> :: (a -> b -> c) -> (b -> c -> b) -> b -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> a -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> (a, c)</li></ul></details></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a id="v:foldReroot" class="def">foldReroot</a> :: (a -> b -> c) -> (b -> c -> b) -> b -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> a -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> (a, c) <a href="src/RerootFold.html#foldReroot" class="link">Source</a> <a href="#v:foldReroot" class="selflink">#</a></p><div class="doc"><p>Returns the same tree with each vertex accompanied by the fold of the tree if that vertex is made | ||
(b <code>g</code> c1) <code>g</code> c2 = (b <code>g</code> c2) <code>g</code> c1</p><p>Sources:</p><ul><li>pajenegod, "The Ultimate Reroot Template" | ||
<a href="https://codeforces.com/blog/entry/124286">https://codeforces.com/blog/entry/124286</a></li></ul></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><a href="#v:foldReroot">foldReroot</a> :: (a -> b -> c) -> (b -> c -> b) -> b -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> a -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> (a, c)</li></ul></details></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a id="v:foldReroot" class="def">foldReroot</a> :: (a -> b -> c) -> (b -> c -> b) -> b -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> a -> <a href="https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Tree.html#t:Tree" title="Data.Tree">Tree</a> (a, c) <a href="src/RerootFold.html#foldReroot" class="link">Source</a> <a href="#v:foldReroot" class="selflink">#</a></p><div class="doc"><p>Returns the same tree with each vertex accompanied by the fold of the tree if that vertex is made | ||
the root of the tree. f is called O(n) times. g is called O(n log n) times.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.24.0</p></div></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.