Documentation for 0931d530ae

This commit is contained in:
github-actions
2023-01-22 19:44:10 +00:00
parent a448f64699
commit b48f6e8671
2457 changed files with 9513 additions and 8691 deletions

View File

@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.5"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: sorting/recursive_bubble_sort.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
@@ -128,30 +128,30 @@ Namespaces</h2></td></tr>
Functions</h2></td></tr>
<tr class="memitem:ae3a775d99dbbb94c130a973df0cfddcf"><td class="memTemplParams" colspan="2">template&lt;typename T &gt; </td></tr>
<tr class="memitem:ae3a775d99dbbb94c130a973df0cfddcf"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d5/d91/namespacesorting.html#ae3a775d99dbbb94c130a973df0cfddcf">sorting::recursive_bubble_sort</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; T &gt; *nums, uint64_t n)</td></tr>
<tr class="memdesc:ae3a775d99dbbb94c130a973df0cfddcf"><td class="mdescLeft">&#160;</td><td class="mdescRight">This is an implementation of the recursive_bubble_sort. A vector is passed to the function which is then dereferenced, so that the changes are reflected in the original vector. It also accepts a second parameter of type <code>int</code> and name <code>n</code>, which is the size of the array. <a href="../../d5/d91/namespacesorting.html#ae3a775d99dbbb94c130a973df0cfddcf">More...</a><br /></td></tr>
<tr class="memdesc:ae3a775d99dbbb94c130a973df0cfddcf"><td class="mdescLeft">&#160;</td><td class="mdescRight">This is an implementation of the recursive_bubble_sort. A vector is passed to the function which is then dereferenced, so that the changes are reflected in the original vector. It also accepts a second parameter of type <code>int</code> and name <code>n</code>, which is the size of the array. <br /></td></tr>
<tr class="separator:ae3a775d99dbbb94c130a973df0cfddcf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/df9/recursive__bubble__sort_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations. <a href="../../d3/df9/recursive__bubble__sort_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Self-test implementations. <br /></td></tr>
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/df9/recursive__bubble__sort_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../d3/df9/recursive__bubble__sort_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <br /></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >This is an implementation of a recursive version of the <a href="https://www.geeksforgeeks.org/recursive-bubble-sort/" target="_blank">Bubble sort algorithm</a> </p>
<div class="textblock"><p>This is an implementation of a recursive version of the <a href="https://www.geeksforgeeks.org/recursive-bubble-sort/" target="_blank">Bubble sort algorithm</a> </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://adityaprakash.tech" target="_blank">Aditya Prakash</a> </dd></dl>
<p>The working principle of the Bubble sort algorithm.</p>
<p >Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements. Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset.</p>
<p>Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements. Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset.</p>
<h3><a class="anchor" id="autotoc_md111"></a>
Algorithm</h3>
<p >What is Swap?</p>
<p >Swapping two numbers means that we interchange their values. Often, an additional variable is required for this operation. This is further illustrated in the following:</p>
<p >void swap(int x, int y){ int z = x; x = y; y = z; }</p>
<p >The above process is a typical displacement process. When we assign a value to x, the old value of x is lost. That's why we create a temporary variable z to store the initial value of x. z is further used to assign the initial value of x to y, to complete swapping.</p>
<p >Recursion</p>
<p >While the recursive method does not necessarily have advantages over iterative versions, but it is useful to enhance the understanding of the algorithm and recursion itself. In Recursive Bubble sort algorithm, we firstly call the function on the entire array, and for every subsequent function call, we exclude the last element. This fixes the last element for that sub-array.Formally, for <code>ith</code> iteration, we consider elements up to n-i, where n is the number of elements in the array. Exit condition: n==1; i.e. the sub-array contains only one element.</p>
<p >Complexity Time complexity: O(n) best case; O(n²) average case; O(n²) worst case Space complexity: O(n)</p>
<p >We need to traverse the array <code>n * (n-1)</code> times. However, if the entire array is already sorted, then we need to traverse it only once. Hence, O(n) is the best case complexity </p>
<p>What is Swap?</p>
<p>Swapping two numbers means that we interchange their values. Often, an additional variable is required for this operation. This is further illustrated in the following:</p>
<p>void swap(int x, int y){ int z = x; x = y; y = z; }</p>
<p>The above process is a typical displacement process. When we assign a value to x, the old value of x is lost. That's why we create a temporary variable z to store the initial value of x. z is further used to assign the initial value of x to y, to complete swapping.</p>
<p>Recursion</p>
<p>While the recursive method does not necessarily have advantages over iterative versions, but it is useful to enhance the understanding of the algorithm and recursion itself. In Recursive Bubble sort algorithm, we firstly call the function on the entire array, and for every subsequent function call, we exclude the last element. This fixes the last element for that sub-array.Formally, for <code>ith</code> iteration, we consider elements up to n-i, where n is the number of elements in the array. Exit condition: n==1; i.e. the sub-array contains only one element.</p>
<p>Complexity Time complexity: O(n) best case; O(n²) average case; O(n²) worst case Space complexity: O(n)</p>
<p>We need to traverse the array <code>n * (n-1)</code> times. However, if the entire array is already sorted, then we need to traverse it only once. Hence, O(n) is the best case complexity </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>
@@ -279,7 +279,7 @@ Here is the call graph for this function:</div>
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_bb1b521853a9c46347182a9d10420771.html">sorting</a></li><li class="navelem"><a class="el" href="../../d3/df9/recursive__bubble__sort_8cpp.html">recursive_bubble_sort.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.5 </li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
</ul>
</div>
</body>