Documentation for 8b1eab204b

This commit is contained in:
realstealthninja
2024-11-04 12:43:05 +00:00
parent 4fb6e622e9
commit a7bccf7d01
6732 changed files with 153919 additions and 365711 deletions

View File

@@ -1,3 +1,4 @@
<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
@@ -5,10 +6,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: data_structures/dsu_path_compression.cpp File Reference</title>
<title>TheAlgorithms/C++: data_structures/dsu_path_compression.cpp File Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
@@ -18,14 +24,24 @@
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
@@ -122,7 +139,9 @@ Include dependency graph for dsu_path_compression.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/de3/dsu__path__compression_8cpp__incl.svg" width="336" height="126"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div><table class="memberdecls">
</div>
<p><a href="../../d3/dae/dsu__path__compression_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d1f/classdsu.html">dsu</a></td></tr>
@@ -146,6 +165,8 @@ Functions</h2></td></tr>
<p>It is a very powerful data structure that keeps track of different clusters(sets) of elements, these sets are disjoint(doesnot have a common
element). Disjoint sets uses cases : for finding connected components in a graph, used in Kruskal's algorithm for finding <a class="el" href="../../d4/d12/namespace_minimum.html" title="Implementation of Minimum Edit Distance algorithm.">Minimum</a> Spanning tree. Operations that can be performed: 1) UnionSet(i,j): add(element i and j to the set) 2) findSet(i): returns the representative of the set to which i belogngs to. 3) get_max(i),get_min(i) : returns the maximum and minimum Below is the class-based approach which uses the heuristic of path compression. Using path compression in findSet(i),we are able to get to the representative of i in O(1) time. </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/AayushVyasKIIT" target="_blank">AayushVyasKIIT</a> </dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="../../df/d28/dsu__union__rank_8cpp.html" title="DSU (Disjoint sets)">dsu_union_rank.cpp</a> </dd></dl>
<p class="definition">Definition in file <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html">dsu_path_compression.cpp</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
@@ -166,24 +187,21 @@ element). Disjoint sets uses cases : for finding connected components in a graph
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<p>&lt; number of items</p>
<p>&lt; object of class disjoint sets</p>
<p class="definition">Definition at line <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00206">206</a> of file <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html">dsu_path_compression.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 206</span> {</div>
<div class="line"><span class="lineno"> 207</span> uint64_t n = 10; <span class="comment">///&lt; number of items</span></div>
<div class="line"><span class="lineno"> 208</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); <span class="comment">///&lt; object of class disjoint sets</span></div>
<div class="line"><span class="lineno"> 207</span> uint64_t n = 10; </div>
<div class="line"><span class="lineno"> 208</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); </div>
<div class="line"><span class="lineno"> 209</span> </div>
<div class="line"><span class="lineno"> 210</span> <a class="code hl_function" href="#ae7880ce913f3058a35ff106d5be9e243">test1</a>(); <span class="comment">// run 1st test case</span></div>
<div class="line"><span class="lineno"> 211</span> <a class="code hl_function" href="#a45d94ead4cf4e1ff9f87c38bc99f59ae">test2</a>(); <span class="comment">// run 2nd test case</span></div>
<div class="line"><span class="lineno"> 212</span> </div>
<div class="line"><span class="lineno"> 213</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 214</span>}</div>
<div class="ttc" id="aclassdsu_html"><div class="ttname"><a href="../../dd/d1f/classdsu.html">dsu</a></div><div class="ttdoc">Disjoint sets union data structure, class based representation.</div><div class="ttdef"><b>Definition</b> dsu_path_compression.cpp:34</div></div>
<div class="ttc" id="adsu__path__compression_8cpp_html_a45d94ead4cf4e1ff9f87c38bc99f59ae"><div class="ttname"><a href="#a45d94ead4cf4e1ff9f87c38bc99f59ae">test2</a></div><div class="ttdeci">static void test2()</div><div class="ttdoc">Self-implementations, 2nd test.</div><div class="ttdef"><b>Definition</b> dsu_path_compression.cpp:187</div></div>
<div class="ttc" id="adsu__path__compression_8cpp_html_ae7880ce913f3058a35ff106d5be9e243"><div class="ttname"><a href="#ae7880ce913f3058a35ff106d5be9e243">test1</a></div><div class="ttdeci">static void test1()</div><div class="ttdoc">Self-test implementations, 1st test.</div><div class="ttdef"><b>Definition</b> dsu_path_compression.cpp:170</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d3/dae/dsu__path__compression_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="599" height="384"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="aclassdsu_html"><div class="ttname"><a href="../../dd/d1f/classdsu.html">dsu</a></div><div class="ttdoc">Disjoint sets union data structure, class based representation.</div><div class="ttdef"><b>Definition</b> <a href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00034">dsu_path_compression.cpp:34</a></div></div>
<div class="ttc" id="adsu__path__compression_8cpp_html_a45d94ead4cf4e1ff9f87c38bc99f59ae"><div class="ttname"><a href="#a45d94ead4cf4e1ff9f87c38bc99f59ae">test2</a></div><div class="ttdeci">static void test2()</div><div class="ttdoc">Self-implementations, 2nd test.</div><div class="ttdef"><b>Definition</b> <a href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00187">dsu_path_compression.cpp:187</a></div></div>
<div class="ttc" id="adsu__path__compression_8cpp_html_ae7880ce913f3058a35ff106d5be9e243"><div class="ttname"><a href="#ae7880ce913f3058a35ff106d5be9e243">test1</a></div><div class="ttdeci">static void test1()</div><div class="ttdoc">Self-test implementations, 1st test.</div><div class="ttdef"><b>Definition</b> <a href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00170">dsu_path_compression.cpp:170</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="ae7880ce913f3058a35ff106d5be9e243" name="ae7880ce913f3058a35ff106d5be9e243"></a>
@@ -213,28 +231,23 @@ Here is the call graph for this function:</div>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p>&lt; number of items</p>
<p>&lt; object of class disjoint sets</p>
<p class="definition">Definition at line <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00170">170</a> of file <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html">dsu_path_compression.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 170</span> {</div>
<div class="line"><span class="lineno"> 171</span> <span class="comment">// the minimum, maximum, and size of the set</span></div>
<div class="line"><span class="lineno"> 172</span> uint64_t n = 10; <span class="comment">///&lt; number of items</span></div>
<div class="line"><span class="lineno"> 173</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); <span class="comment">///&lt; object of class disjoint sets</span></div>
<div class="line"><span class="lineno"> 172</span> uint64_t n = 10; </div>
<div class="line"><span class="lineno"> 173</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); </div>
<div class="line"><span class="lineno"> 174</span> <span class="comment">// set 1</span></div>
<div class="line"><span class="lineno"> 175</span> d.UnionSet(1, 2); <span class="comment">// performs union operation on 1 and 2</span></div>
<div class="line"><span class="lineno"> 176</span> d.UnionSet(1, 4); <span class="comment">// performs union operation on 1 and 4</span></div>
<div class="line"><span class="lineno"> 177</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">vector&lt;uint64_t&gt;</a> ans = {1, 4, 3};</div>
<div class="line"><span class="lineno"> 177</span> vector&lt;uint64_t&gt; ans = {1, 4, 3};</div>
<div class="line"><span class="lineno"> 178</span> <span class="keywordflow">for</span> (uint64_t i = 0; i &lt; ans.size(); i++) {</div>
<div class="line"><span class="lineno"> 179</span> assert(d.get(4).at(i) == ans[i]); <span class="comment">// makes sure algorithm works fine</span></div>
<div class="line"><span class="lineno"> 180</span> }</div>
<div class="line"><span class="lineno"> 181</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">cout</a> &lt;&lt; <span class="stringliteral">&quot;1st test passed!&quot;</span> &lt;&lt; <a class="code hl_define" href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a>;</div>
<div class="line"><span class="lineno"> 181</span> cout &lt;&lt; <span class="stringliteral">&quot;1st test passed!&quot;</span> &lt;&lt; <a class="code hl_define" href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a>;</div>
<div class="line"><span class="lineno"> 182</span>}</div>
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
<div class="ttc" id="amatrix__exponentiation_8cpp_html_a600eaf353befc174637855795f12d258"><div class="ttname"><a href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a></div><div class="ttdeci">#define endl</div><div class="ttdef"><b>Definition</b> matrix_exponentiation.cpp:36</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d3/dae/dsu__path__compression_8cpp_ae7880ce913f3058a35ff106d5be9e243_cgraph.svg" width="502" height="384"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="amatrix__exponentiation_8cpp_html_a600eaf353befc174637855795f12d258"><div class="ttname"><a href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a></div><div class="ttdeci">#define endl</div><div class="ttdef"><b>Definition</b> <a href="../../d7/d35/matrix__exponentiation_8cpp_source.html#l00036">matrix_exponentiation.cpp:36</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a45d94ead4cf4e1ff9f87c38bc99f59ae" name="a45d94ead4cf4e1ff9f87c38bc99f59ae"></a>
@@ -264,26 +277,23 @@ Here is the call graph for this function:</div>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p>&lt; number of items</p>
<p>&lt; object of class disjoint sets</p>
<p class="definition">Definition at line <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html#l00187">187</a> of file <a class="el" href="../../d3/dae/dsu__path__compression_8cpp_source.html">dsu_path_compression.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 187</span> {</div>
<div class="line"><span class="lineno"> 188</span> <span class="comment">// the minimum, maximum, and size of the set</span></div>
<div class="line"><span class="lineno"> 189</span> uint64_t n = 10; <span class="comment">///&lt; number of items</span></div>
<div class="line"><span class="lineno"> 190</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); <span class="comment">///&lt; object of class disjoint sets</span></div>
<div class="line"><span class="lineno"> 189</span> uint64_t n = 10; </div>
<div class="line"><span class="lineno"> 190</span> <a class="code hl_class" href="../../dd/d1f/classdsu.html">dsu</a> d(n + 1); </div>
<div class="line"><span class="lineno"> 191</span> <span class="comment">// set 1</span></div>
<div class="line"><span class="lineno"> 192</span> d.UnionSet(3, 5);</div>
<div class="line"><span class="lineno"> 193</span> d.UnionSet(5, 6);</div>
<div class="line"><span class="lineno"> 194</span> d.UnionSet(5, 7);</div>
<div class="line"><span class="lineno"> 195</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">vector&lt;uint64_t&gt;</a> ans = {3, 7, 4};</div>
<div class="line"><span class="lineno"> 195</span> vector&lt;uint64_t&gt; ans = {3, 7, 4};</div>
<div class="line"><span class="lineno"> 196</span> <span class="keywordflow">for</span> (uint64_t i = 0; i &lt; ans.size(); i++) {</div>
<div class="line"><span class="lineno"> 197</span> assert(d.get(3).at(i) == ans[i]); <span class="comment">// makes sure algorithm works fine</span></div>
<div class="line"><span class="lineno"> 198</span> }</div>
<div class="line"><span class="lineno"> 199</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">cout</a> &lt;&lt; <span class="stringliteral">&quot;2nd test passed!&quot;</span> &lt;&lt; <a class="code hl_define" href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a>;</div>
<div class="line"><span class="lineno"> 199</span> cout &lt;&lt; <span class="stringliteral">&quot;2nd test passed!&quot;</span> &lt;&lt; <a class="code hl_define" href="../../d7/d35/matrix__exponentiation_8cpp.html#a600eaf353befc174637855795f12d258">endl</a>;</div>
<div class="line"><span class="lineno"> 200</span>}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d3/dae/dsu__path__compression_8cpp_a45d94ead4cf4e1ff9f87c38bc99f59ae_cgraph.svg" width="502" height="384"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->