Skip to content
Snippets Groups Projects
Verified Commit 8e8cbebc authored by orestis.malaspin's avatar orestis.malaspin
Browse files

updated tri par tas

parent 081a23f2
Branches
Tags
No related merge requests found
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="159.01459mm"
height="65.378784mm"
viewBox="0 0 159.01459 65.378784"
version="1.1"
id="svg5"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
sodipodi:docname="heap_tree.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="true"
inkscape:zoom="0.67081229"
inkscape:cx="168.45249"
inkscape:cy="78.263325"
inkscape:window-width="1920"
inkscape:window-height="1080"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0">
<inkscape:grid
type="xygrid"
id="grid824"
originx="-26.326043"
originy="-41.90753" />
</sodipodi:namedview>
<defs
id="defs2">
<marker
style="overflow:visible"
id="Arrow2Lend"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-2"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-0" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8-2"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7-3" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8-2-9"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7-3-2" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-2-2"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-0-8" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8-3"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7-6" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-1"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-2" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-1-9"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-2-4" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8-3-7"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7-6-8" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-1-0"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-2-3" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lend-8-3-6"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Arrow2Lend"
inkscape:isstock="true">
<path
transform="matrix(-1.1,0,0,-1.1,-1.1,0)"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:0.625;stroke-linejoin:round"
id="path17053-7-6-1" />
</marker>
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-26.326042,-41.907531)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="31.369009"
y="64.637695"
id="text2487"><tspan
sodipodi:role="line"
id="tspan2485"
style="stroke-width:0.264583"
x="31.369009"
y="64.637695">0</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 26.458333,68.791666 h 15.875 V 52.916667 h -15.875 v 15.875"
id="path15418" />
<g
id="g15829"
transform="translate(-5.2916667,-26.458334)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="53.213009"
y="91.090736"
id="text4987"><tspan
sodipodi:role="line"
id="tspan4985"
style="stroke-width:0.264583"
x="53.213009"
y="91.090736">1</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 47.625,95.25 H 63.5 V 79.375001 H 47.625 v 15.875"
id="path15418-3" />
</g>
<g
id="g15834"
transform="translate(-37.041667,-52.916673)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="100.18185"
y="117.60199"
id="text5981"><tspan
sodipodi:role="line"
id="tspan5979"
style="stroke-width:0.264583"
x="100.18185"
y="117.60199">2</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 95.25,121.70833 h 15.875 V 105.83334 H 95.25 v 15.87499"
id="path15418-6" />
</g>
<g
id="g15839"
transform="translate(-58.208327,-58.208333)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="137.26584"
y="122.84074"
id="text6887"><tspan
sodipodi:role="line"
id="tspan6885"
style="stroke-width:0.264583"
x="137.26584"
y="122.84074">3</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 132.29166,127 h 15.875 v -15.875 h -15.875 V 127"
id="path15418-7" />
</g>
<g
id="g15844"
transform="translate(-42.333327,-74.083333)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="137.19705"
y="138.73691"
id="text7815"><tspan
sodipodi:role="line"
id="tspan7813"
style="stroke-width:0.264583"
x="137.19705"
y="138.73691">4</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 132.29166,142.875 h 15.875 V 127 h -15.875 v 15.875"
id="path15418-5" />
</g>
<g
id="g15854"
transform="translate(111.125,-68.791663)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="15.451676"
y="133.42407"
id="text9407"><tspan
sodipodi:role="line"
id="tspan9405"
style="stroke-width:0.264583"
x="15.451676"
y="133.42407">6</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 10.583333,137.58333 h 15.875 v -15.87499 h -15.875 v 15.87499"
id="path15418-35" />
</g>
<g
id="g15849"
transform="translate(79.375,-58.208333)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="31.337259"
y="122.78782"
id="text8479"><tspan
sodipodi:role="line"
id="tspan8477"
style="stroke-width:0.264583"
x="31.337259"
y="122.78782">5</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 26.458333,127 h 15.875 v -15.875 h -15.875 V 127"
id="path15418-62" />
</g>
<g
id="g15859"
transform="translate(58.208333,-100.54167)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="84.312134"
y="165.17407"
id="text10533"><tspan
sodipodi:role="line"
id="tspan10531"
style="stroke-width:0.264583"
x="84.312134"
y="165.17407">7</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 79.375,169.33334 H 95.25 v -15.875 H 79.375 v 15.875"
id="path15418-9" />
</g>
<g
id="g15864"
transform="translate(121.70833,-111.125)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="36.66597"
y="175.7574"
id="text11329"><tspan
sodipodi:role="line"
id="tspan11327"
style="stroke-width:0.264583"
x="36.66597"
y="175.7574">8</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 31.75,179.91667 h 15.875 v -15.875 H 31.75 v 15.875"
id="path15418-1" />
</g>
<g
id="g15869"
transform="translate(153.45833,-116.41667)">
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:0;font-family:sans-serif;letter-spacing:0px;stroke-width:0.264583"
x="20.796259"
y="181.04907"
id="text13137"><tspan
sodipodi:role="line"
id="tspan13135"
style="stroke-width:0.264583"
x="20.796259"
y="181.04907">9</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 15.875,185.20834 H 31.75 v -15.875 H 15.875 v 15.875"
id="path15418-2" />
</g>
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 26.458333,68.791666 v 21.166666 l 158.749997,10e-7 V 68.791667"
id="path15904" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 42.333333,68.791666 V 89.958332"
id="path15906" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 58.208333,68.791667 v 21.16666"
id="path15906-7" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 74.083333,68.791667 V 89.958329"
id="path15906-0" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 89.958333,68.791667 v 21.16666"
id="path15906-9" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 121.70833,68.791667 v 21.16666"
id="path15906-3" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 137.58333,68.791667 v 21.16666"
id="path15906-6" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 153.45833,68.791667 v 21.16666"
id="path15906-06" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 169.33333,68.791667 v 21.16666"
id="path15906-2" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 105.83333,68.791667 v 21.16667"
id="path15906-61" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend)"
d="m 34.395833,50.270833 c 0,0 7.9375,-10.583334 15.875,0"
id="path16437"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-8)"
d="m 34.395833,50.270833 c 0,0 14.552084,-18.520833 31.75,0"
id="path16437-9"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-1)"
d="m 161.39583,91.28125 c 0,0 -38.36458,35.71875 -79.374997,0"
id="path16437-93"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-8-3)"
d="m 145.52083,91.28125 c 0,0 -31.75,21.16667 -60.854163,0"
id="path16437-9-1"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-1-0)"
d="m 129.64583,91.28125 c 0,0 -31.749997,34.39583 -62.17708,0"
id="path16437-93-0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-8-3-6)"
d="m 113.77083,91.28125 c 0,0 -23.812497,21.16667 -43.656247,0"
id="path16437-9-1-6"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-2)"
d="m 50.270836,50.270833 c 0,0 15.874997,-10.583333 31.749997,0"
id="path16437-7"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-8-2)"
d="m 50.270836,50.270833 c 0,0 23.812497,-18.520833 47.624997,0"
id="path16437-9-5"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-2-2)"
d="m 66.145833,50.270833 c 0,0 23.8125,-11.90625 47.624997,1.322917"
id="path16437-7-9"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-end:url(#Arrow2Lend-8-2-9)"
d="m 66.145833,50.270833 c 0,0 31.75,-18.520833 62.177087,0"
id="path16437-9-5-7"
sodipodi:nodetypes="cc" />
</g>
</svg>
......@@ -24,6 +24,387 @@ date: "2022-03-02"
# Visuellement
::: columns
:::: column
* Où vont les indices correspondant du tableau?
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0(( ))-->id1(( ));
id0-->id2(( ));
id1-->id3(( ));
id1-->id4(( ));
id2-->id5(( ));
id2-->id6(( ));
id3-->id7(( ));
id3-->id8(( ));
id4-->id9(( ));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
* Les flèche de gauche à droite, parent -> enfants.
* Les flèche de droite à gauche, enfants -> parent.
![Dualité tableau arbre binaire.](figs/heap_tree.svg)
::::
:::
**Propriétés:**
1. les feuilles sont toutes sur l'avant dernier ou dernier niveau.
2. les feuilles de profondeur maximale sont "tassée" à gauche.
# Le tas (ou heap)
## Définition
* Un arbre est un tas, si la valeur de chacun de ses descendants est inférieure
ou égale à sa propre valeur.
## Exemples (ou pas)
```
16 8 14 6 2 10 12 4 5 # Tas
16 14 8 6 2 10 12 4 5 # Non-tas, 10 > 8 et 12 > 8
```
## Exercices (ou pas)
```
19 18 12 12 17 1 13 4 5 # Tas ou pas tas?
19 18 16 12 17 1 12 4 5 # Tas ou pas tas?
```
. . .
```
19 18 12 12 17 1 13 4 5 # Pas tas! 13 > 12
19 18 16 12 17 1 12 4 5 # Tas!
```
# Exemple de tri par tas (1/N)
```
| 1 | 16 | 5 | 12 | 4 | 2 | 8 | 10 | 6 | 7 |
```
::: columns
:::: column
* Quel est l'arbre que cela représente?
. . .
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((5));
id1-->id3((12));
id1-->id4((4));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((7));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
**But:** Transformer l'arbre en tas.
* On commence à l'indice $N/2 = 5$: `7`.
* `7 > 4` (enfant `>` parent).
* intervertir `4` et `7`.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((5));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::
. . .
```
* *
| 1 | 16 | 5 | 12 | 7 | 2 | 8 | 10 | 6 | 4 |
```
# Exemple de tri par tas (2/N)
```
| 1 | 16 | 5 | 12 | 7 | 2 | 8 | 10 | 6 | 4 |
```
::: columns
:::: column
**But:** Transformer l'arbre en tas.
* On continue à l'indice $N/2-1 = 4$: `12`.
* Déjà un tas, rien à faire.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((5));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
**But:** Transformer l'arbre en tas.
* On continue à l'indice $N/2-2 = 3$: `5`.
* `5 < 8`, échanger `8` et `5` (aka `max(2, 5, 8)`)
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((8));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((5));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::
. . .
```
| 1 | 16 | 8 | 12 | 7 | 2 | 5 | 10 | 6 | 4 |
```
# Exemple de tri par tas (3/N)
```
| 1 | 16 | 5 | 12 | 7 | 2 | 8 | 10 | 6 | 4 |
```
::: columns
:::: column
**But:** Transformer l'arbre en tas.
* Indice $N/2-1 = 4$: `12`.
* Déjà un tas, rien à faire.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((5));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
**But:** Transformer l'arbre en tas.
* Indice $N/2-2 = 3$: `5`.
* `5 < 8`, `5 <=> max(2, 5, 8)`
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((8));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((5));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::
```
* *
| 1 | 16 | 8 | 12 | 7 | 2 | 5 | 10 | 6 | 4 |
```
# Exemple de tri par tas (4/N)
```
| 1 | 16 | 8 | 12 | 7 | 2 | 5 | 10 | 6 | 4 |
```
::: columns
:::: column
**But:** Transformer l'arbre en tas.
* Indice $N/2-3 = 1$: `16`.
* Déjà un tas, rien à faire.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((1))-->id1((16));
id0-->id2((5));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
**But:** Transformer l'arbre en tas.
* Indice $N/2-4 = 1$: `1`.
* `1 < 16 && 1 < 8`, `1 <=> max(1, 16, 8)`
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((16))-->id1((1));
id0-->id2((8));
id1-->id3((12));
id1-->id4((7));
id2-->id5((2));
id2-->id6((5));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::
```
* *
| 16 | 1 | 8 | 12 | 7 | 2 | 5 | 10 | 6 | 4 |
```
# Exemple de tri par tas (5/N)
```
| 16 | 1 | 8 | 12 | 7 | 2 | 5 | 10 | 6 | 4 |
```
::: columns
:::: column
**But:** Transformer l'arbre en tas.
* Recommencer avec `1`.
* `1 <=> max(1, 12, 7)`.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((16))-->id1((12));
id0-->id2((5));
id1-->id3((1));
id1-->id4((7));
id2-->id5((2));
id2-->id6((8));
id3-->id7((10));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::: column
**But:** Transformer l'arbre en tas.
* Recommencer avec `1`.
* `1 <=> max(1, 10, 6)`.
```{.mermaid format=pdf width=400 loc=figs/}
graph TD;
id0((16))-->id1((12));
id0-->id2((8));
id1-->id3((10));
id1-->id4((7));
id2-->id5((2));
id2-->id6((5));
id3-->id7((1));
id3-->id8((6));
id4-->id9((4));
id4-->id10(( ));
style id10 fill:#fff,stroke:#fff
```
::::
:::
```
* * *
| 16 | 12 | 8 | 10 | 7 | 2 | 5 | 1 | 6 | 4 |
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment