mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-21 20:31:43 +08:00
Documentation for 0931d530ae
This commit is contained in:
@@ -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/binary_insertion_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&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
|
||||
@@ -127,22 +127,22 @@ Namespaces</h2></td></tr>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:a034d8b276518a902962e87d3158b64fd"><td class="memTemplParams" colspan="2">template<class T > </td></tr>
|
||||
<tr class="memitem:a034d8b276518a902962e87d3158b64fd"><td class="memTemplItemLeft" align="right" valign="top">int64_t </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d5/d91/namespacesorting.html#a034d8b276518a902962e87d3158b64fd">sorting::binary_search</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>< T > &arr, T val, int64_t low, int64_t high)</td></tr>
|
||||
<tr class="memdesc:a034d8b276518a902962e87d3158b64fd"><td class="mdescLeft"> </td><td class="mdescRight">Binary search function to find the most suitable pace for an element. <a href="../../d5/d91/namespacesorting.html#a034d8b276518a902962e87d3158b64fd">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a034d8b276518a902962e87d3158b64fd"><td class="mdescLeft"> </td><td class="mdescRight">Binary search function to find the most suitable pace for an element. <br /></td></tr>
|
||||
<tr class="separator:a034d8b276518a902962e87d3158b64fd"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a5f4bc75cca6dd8294af2d0e328006c68"><td class="memTemplParams" colspan="2">template<typename T > </td></tr>
|
||||
<tr class="memitem:a5f4bc75cca6dd8294af2d0e328006c68"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d5/d91/namespacesorting.html#a5f4bc75cca6dd8294af2d0e328006c68">sorting::insertionSort_binsrch</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>< T > &arr)</td></tr>
|
||||
<tr class="memdesc:a5f4bc75cca6dd8294af2d0e328006c68"><td class="mdescLeft"> </td><td class="mdescRight">Insertion sort function to sort the vector. <a href="../../d5/d91/namespacesorting.html#a5f4bc75cca6dd8294af2d0e328006c68">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:a5f4bc75cca6dd8294af2d0e328006c68"><td class="mdescLeft"> </td><td class="mdescRight">Insertion sort function to sort the vector. <br /></td></tr>
|
||||
<tr class="separator:a5f4bc75cca6dd8294af2d0e328006c68"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/dcc/binary__insertion__sort_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <a href="../../d8/dcc/binary__insertion__sort_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <br /></td></tr>
|
||||
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/dcc/binary__insertion__sort_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
||||
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../d8/dcc/binary__insertion__sort_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <br /></td></tr>
|
||||
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p ><a href="https://en.wikipedia.org/wiki/Insertion_sort" target="_blank">Binary Insertion Sort Algorithm (Insertion Sort)</a> </p>
|
||||
<p >If the cost of comparisons exceeds the cost of swaps, as is the case for example with string keys stored by reference or with human interaction (such as choosing one of a pair displayed side-by-side), then using binary insertion sort may yield better performance. Binary insertion sort employs a binary search to determine the correct location to insert new elements, and therefore performs ⌈log2 n⌉ comparisons in the worst case. When each element in the array is searched for and inserted this is O(n log n). The algorithm as a whole still has a running time of O(n2) on average because of the series</p><ul>
|
||||
<div class="textblock"><p><a href="https://en.wikipedia.org/wiki/Insertion_sort" target="_blank">Binary Insertion Sort Algorithm (Insertion Sort)</a> </p>
|
||||
<p>If the cost of comparisons exceeds the cost of swaps, as is the case for example with string keys stored by reference or with human interaction (such as choosing one of a pair displayed side-by-side), then using binary insertion sort may yield better performance. Binary insertion sort employs a binary search to determine the correct location to insert new elements, and therefore performs ⌈log2 n⌉ comparisons in the worst case. When each element in the array is searched for and inserted this is O(n log n). The algorithm as a whole still has a running time of O(n2) on average because of the series</p><ul>
|
||||
<li>of swaps required for each insertion. However it has several advantages such as</li>
|
||||
</ul>
|
||||
<ol type="1">
|
||||
@@ -153,7 +153,7 @@ Functions</h2></td></tr>
|
||||
<li>It's stable that is it does not change the relative order of elements with equal keys.</li>
|
||||
<li>It can sort the array or list as it receives.</li>
|
||||
</ol>
|
||||
<p >Example execution steps:</p><ol type="1">
|
||||
<p>Example execution steps:</p><ol type="1">
|
||||
<li>Suppose initially we have <p class="formulaDsp">
|
||||
\begin{bmatrix}40 &30 &20 &50 &10\end{bmatrix}
|
||||
</p>
|
||||
@@ -285,7 +285,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="../../d8/dcc/binary__insertion__sort_8cpp.html">binary_insertion_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>
|
||||
|
||||
Reference in New Issue
Block a user