Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • algorithmique/cours
  • aurelien.boyer/cours
  • jeremy.meissner/cours
  • radhwan.hassine/cours
  • yassin.elhakoun/cours-algo
  • gaspard.legouic/cours
  • joachim.bach/cours
  • gabriel.marinoja/algo-cours
  • loic.lavorel/cours
  • iliya.saroukha/cours
  • costanti.volta/cours
  • jacquesw.ndoumben/cours
12 results
Select Git revision
Loading items
Show changes
Showing
with 1664 additions and 18 deletions
slides/figs/kruskal_cycle.png

61.1 KiB

slides/figs/kruskal_enonce.png

184 KiB

slides/figs/kruskal_exercice.png

185 KiB

slides/figs/kruskal_solution.png

312 KiB

slides/figs/kruskal_solution_exercice.png

218 KiB

slides/figs/prim_0.png

37.3 KiB

slides/figs/prim_1.png

37.7 KiB

slides/figs/prim_2.png

37.7 KiB

slides/figs/prim_3.png

38.1 KiB

slides/figs/prim_4.png

38.6 KiB

slides/figs/prim_5.png

39.3 KiB

slides/figs/prim_exercice.png

53.2 KiB

slides/figs/prim_solution.png

101 KiB

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="900" height="300" id="svg2" sodipodi:version="0.32" inkscape:version="0.46" sodipodi:docname="Stack (data structure) - Kopia.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.0">
<defs id="defs4">
<marker inkscape:stockid="Arrow1Lstart" orient="auto" refY="0" refX="0" id="Arrow1Lstart" style="overflow:visible">
<path id="path3595" d="M 0,0 L 5,-5 L -12.5,0 L 5,5 L 0,0 z" style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none" transform="matrix(0.8,0,0,0.8,10,0)"/>
</marker>
<inkscape:perspective sodipodi:type="inkscape:persp3d" inkscape:vp_x="0 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" id="perspective10"/>
<inkscape:perspective id="perspective2390" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_x="0 : 526.18109 : 1" sodipodi:type="inkscape:persp3d"/>
<inkscape:perspective id="perspective2397" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_x="0 : 526.18109 : 1" sodipodi:type="inkscape:persp3d"/>
</defs>
<sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" gridtolerance="10000" guidetolerance="10" objecttolerance="10" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1.979899" inkscape:cx="312.8503" inkscape:cy="205.85154" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1196" inkscape:window-height="702" inkscape:window-x="-8" inkscape:window-y="-8" inkscape:snap-bbox="true" inkscape:object-paths="true">
<inkscape:grid type="xygrid" id="grid2396" visible="true" enabled="false"/>
</sodipodi:namedview>
<metadata id="metadata7">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
</cc:Work>
</rdf:RDF>
</metadata>
<g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(-11.994905,-782.85675)">
<g id="g5578" transform="translate(-23.246306,-18.180276)">
<path id="rect2392" d="M 61.055945,1044.6512 L 196.05595,1044.6512 L 196.05595,1069.3179 L 61.055945,1069.3179 L 61.055945,1044.6512 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 61.055945,1019.9845 L 196.05595,1019.9845 L 196.05595,1044.6512 L 61.055945,1044.6512 L 61.055945,1019.9845 z" id="path3165"/>
<path id="path3167" d="M 61.055945,994.98453 L 196.05595,994.98453 L 196.05595,1019.6512 L 61.055945,1019.6512 L 61.055945,994.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text sodipodi:linespacing="125%" id="text3169" y="1039.6512" x="46.568642" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1039.6512" x="46.568642" id="tspan3171" sodipodi:role="line">1</tspan></text>
<text sodipodi:linespacing="125%" id="text3173" y="1014.6512" x="46.055946" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1014.6512" x="46.055946" id="tspan3175" sodipodi:role="line">2</tspan></text>
<text sodipodi:linespacing="125%" id="text3177" y="989.52429" x="45.855751" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="989.52429" x="45.855751" id="tspan3179" sodipodi:role="line">3</tspan></text>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 61.055945,969.98453 L 196.05595,969.98453 L 196.05595,994.65125 L 61.055945,994.65125 L 61.055945,969.98453 z" id="path2403"/>
<path id="path2405" d="M 61.055945,944.98453 L 196.05595,944.98453 L 196.05595,969.65125 L 61.055945,969.65125 L 61.055945,944.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="46.178017" y="964.62195" id="text2407" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2409" x="46.178017" y="964.62195">4</tspan><tspan id="tspan2415" sodipodi:role="line" x="46.178017" y="989.62195"/></text>
<text sodipodi:linespacing="125%" id="text2411" y="1064.1959" x="45.885048" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1959" x="45.885048" id="tspan2413" sodipodi:role="line">0</tspan></text>
<path id="path2544" d="M 242.8671,1044.6512 L 377.8671,1044.6512 L 377.8671,1069.3179 L 242.8671,1069.3179 L 242.8671,1044.6512 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 242.8671,1019.9845 L 377.8671,1019.9845 L 377.8671,1044.6512 L 242.8671,1044.6512 L 242.8671,1019.9845 z" id="path2546"/>
<path id="path2548" d="M 242.8671,994.98453 L 377.8671,994.98453 L 377.8671,1019.6512 L 242.8671,1019.6512 L 242.8671,994.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text sodipodi:linespacing="125%" id="text2550" y="1039.6512" x="228.37979" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1039.6512" x="228.37979" id="tspan2552" sodipodi:role="line">1</tspan></text>
<text sodipodi:linespacing="125%" id="text2554" y="1014.6512" x="227.8671" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1014.6512" x="227.8671" id="tspan2556" sodipodi:role="line">2</tspan></text>
<text sodipodi:linespacing="125%" id="text2558" y="989.52429" x="227.6669" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="989.52429" x="227.6669" id="tspan2560" sodipodi:role="line">3</tspan></text>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 242.8671,969.98453 L 377.8671,969.98453 L 377.8671,994.65125 L 242.8671,994.65125 L 242.8671,969.98453 z" id="path2562"/>
<path id="path2564" d="M 242.86711,944.98453 L 377.86711,944.98453 L 377.86711,969.65125 L 242.86711,969.65125 L 242.86711,944.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="227.98917" y="964.62195" id="text2566" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2568" x="227.98917" y="964.62195">4</tspan><tspan id="tspan2570" sodipodi:role="line" x="227.98917" y="989.62195"/></text>
<text sodipodi:linespacing="125%" id="text2572" y="1064.1959" x="227.6962" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1959" x="227.6962" id="tspan2574" sodipodi:role="line">0</tspan></text>
<path id="path2580" d="M 424.67822,1044.6512 L 559.67822,1044.6512 L 559.67822,1069.3179 L 424.67822,1069.3179 L 424.67822,1044.6512 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 424.67822,1019.9845 L 559.67822,1019.9845 L 559.67822,1044.6512 L 424.67822,1044.6512 L 424.67822,1019.9845 z" id="path2582"/>
<path id="path2584" d="M 424.67822,994.98453 L 559.67822,994.98453 L 559.67822,1019.6512 L 424.67822,1019.6512 L 424.67822,994.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text sodipodi:linespacing="125%" id="text2586" y="1039.6512" x="410.19092" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1039.6512" x="410.19092" id="tspan2588" sodipodi:role="line">1</tspan></text>
<text sodipodi:linespacing="125%" id="text2590" y="1014.6512" x="409.67822" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1014.6512" x="409.67822" id="tspan2592" sodipodi:role="line">2</tspan></text>
<text sodipodi:linespacing="125%" id="text2594" y="989.52429" x="409.47803" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="989.52429" x="409.47803" id="tspan2596" sodipodi:role="line">3</tspan></text>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 424.67822,969.98453 L 559.67822,969.98453 L 559.67822,994.65125 L 424.67822,994.65125 L 424.67822,969.98453 z" id="path2598"/>
<path id="path2600" d="M 424.67822,944.98453 L 559.67822,944.98453 L 559.67822,969.65125 L 424.67822,969.65125 L 424.67822,944.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="409.80029" y="964.62195" id="text2602" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2604" x="409.80029" y="964.62195">4</tspan><tspan id="tspan2606" sodipodi:role="line" x="409.80029" y="989.62195"/></text>
<text sodipodi:linespacing="125%" id="text2608" y="1064.1959" x="409.50732" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1959" x="409.50732" id="tspan2610" sodipodi:role="line">0</tspan></text>
<path id="path2616" d="M 606.48937,1044.6512 L 741.48937,1044.6512 L 741.48937,1069.3179 L 606.48937,1069.3179 L 606.48937,1044.6512 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 606.48937,1019.9845 L 741.48937,1019.9845 L 741.48937,1044.6512 L 606.48937,1044.6512 L 606.48937,1019.9845 z" id="path2618"/>
<path id="path2620" d="M 606.48937,994.98453 L 741.48937,994.98453 L 741.48937,1019.6512 L 606.48937,1019.6512 L 606.48937,994.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text sodipodi:linespacing="125%" id="text2622" y="1039.6512" x="592.00208" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1039.6512" x="592.00208" id="tspan2624" sodipodi:role="line">1</tspan></text>
<text sodipodi:linespacing="125%" id="text2626" y="1014.6512" x="591.48938" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1014.6512" x="591.48938" id="tspan2628" sodipodi:role="line">2</tspan></text>
<text sodipodi:linespacing="125%" id="text2630" y="989.52429" x="591.28918" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="989.52429" x="591.28918" id="tspan2632" sodipodi:role="line">3</tspan></text>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 606.48937,969.98453 L 741.48937,969.98453 L 741.48937,994.65125 L 606.48937,994.65125 L 606.48937,969.98453 z" id="path2634"/>
<path id="path2636" d="M 606.48937,944.98453 L 741.48937,944.98453 L 741.48937,969.65125 L 606.48937,969.65125 L 606.48937,944.98453 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="591.61145" y="964.62195" id="text2638" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2640" x="591.61145" y="964.62195">4</tspan><tspan id="tspan2642" sodipodi:role="line" x="591.61145" y="989.62195"/></text>
<text sodipodi:linespacing="125%" id="text2644" y="1064.1959" x="591.31848" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1959" x="591.31848" id="tspan2646" sodipodi:role="line">0</tspan></text>
<g transform="translate(769.3005,38.058349)" id="g2650">
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 19,1006.5929 L 154,1006.5929 L 154,1031.2596 L 19,1031.2596 L 19,1006.5929 z" id="path2652"/>
<path id="path2654" d="M 19,981.92618 L 154,981.92618 L 154,1006.5929 L 19,1006.5929 L 19,981.92618 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 19,956.92618 L 154,956.92618 L 154,981.5929 L 19,981.5929 L 19,956.92618 z" id="path2656"/>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="4.5126953" y="1001.5929" id="text2658" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2660" x="4.5126953" y="1001.5929">1</tspan></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="4" y="976.5929" id="text2662" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2664" x="4" y="976.5929">2</tspan></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="3.7998047" y="951.46594" id="text2666" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2668" x="3.7998047" y="951.46594">3</tspan></text>
<path id="path2670" d="M 19,931.92618 L 154,931.92618 L 154,956.5929 L 19,956.5929 L 19,931.92618 z" style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
<path style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" d="M 19,906.92618 L 154,906.92618 L 154,931.5929 L 19,931.5929 L 19,906.92618 z" id="path2672"/>
<text sodipodi:linespacing="125%" id="text2674" y="926.5636" x="4.1220703" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="926.5636" x="4.1220703" id="tspan2676" sodipodi:role="line">4</tspan><tspan y="951.5636" x="4.1220703" sodipodi:role="line" id="tspan2678"/></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="3.8291016" y="1026.1376" id="text2680" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2682" x="3.8291016" y="1026.1376">0</tspan></text>
</g>
<text sodipodi:linespacing="125%" id="text2684" y="1064.1427" x="303.69717" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1427" x="303.69717" id="tspan2686" sodipodi:role="line">A</tspan></text>
<text sodipodi:linespacing="125%" id="text2688" y="1039.4761" x="485.30811" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1039.4761" x="485.30811" id="tspan2690" sodipodi:role="line">B</tspan></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="485.5083" y="1064.1427" id="text2763" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2765" x="485.5083" y="1064.1427">A</tspan></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="121.88602" y="846.32251" id="text2816" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan2818" x="121.88602" y="846.32251">A</tspan></text>
<g transform="translate(-110.82003,-12.8571)" id="g5458">
<g id="g5454">
<path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;marker-start:none;stroke-opacity:1" d="M 239.37598,930.5929 L 239.37598,885.5929" id="path4887" sodipodi:nodetypes="cs"/>
<path sodipodi:nodetypes="ccc" transform="translate(4.3759766,771.5929)" id="path5452" d="M 230,149 L 235,159 L 240,149" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
</g>
</g>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="303.49698" y="846.32251" id="text5496" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan5498" x="303.49698" y="846.32251">B</tspan></text>
<g id="g5500" transform="translate(70.991133,-12.8571)">
<g id="g5502">
<path sodipodi:nodetypes="cs" id="path5504" d="M 239.37598,930.5929 L 239.37598,885.5929" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;marker-start:none;stroke-opacity:1"/>
<path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" d="M 230,149 L 235,159 L 240,149" id="path5506" transform="translate(4.3759766,771.5929)" sodipodi:nodetypes="ccc"/>
</g>
</g>
<text sodipodi:linespacing="125%" id="text5508" y="846.32251" x="485.30811" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="846.32251" x="485.30811" id="tspan5510" sodipodi:role="line">B</tspan></text>
<g transform="matrix(1,0,0,-1,252.80224,1803.3287)" id="g5512">
<g id="g5514">
<path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;marker-start:none;stroke-opacity:1" d="M 239.37598,930.5929 L 239.37598,885.5929" id="path5516" sodipodi:nodetypes="cs"/>
<path sodipodi:nodetypes="ccc" transform="translate(4.3759766,771.5929)" id="path5518" d="M 230,149 L 235,159 L 240,149" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
</g>
</g>
<text sodipodi:linespacing="125%" id="text5520" y="1064.1427" x="485.5083" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" xml:space="preserve"><tspan y="1064.1427" x="485.5083" id="tspan5522" sodipodi:role="line">A</tspan></text>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="667.31946" y="1064.1427" id="text5558" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan5560" x="667.31946" y="1064.1427">A</tspan></text>
<g id="g5566" transform="matrix(1,0,0,-1,434.61339,1803.3287)">
<g id="g5568">
<path sodipodi:nodetypes="cs" id="path5570" d="M 239.37598,930.5929 L 239.37598,885.5929" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;marker-start:none;stroke-opacity:1"/>
<path style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" d="M 230,149 L 235,159 L 240,149" id="path5572" transform="translate(4.3759766,771.5929)" sodipodi:nodetypes="ccc"/>
</g>
</g>
<text xml:space="preserve" style="font-size:20px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Arial;-inkscape-font-specification:Arial" x="667.31946" y="846.32251" id="text5574" sodipodi:linespacing="125%"><tspan sodipodi:role="line" id="tspan5576" x="667.31946" y="846.32251">A</tspan></text>
</g>
</g>
<script xmlns="" public-path="moz-extension://ff8cca0e-5336-417a-b78e-a0d94c485783/"/></svg>
\ No newline at end of file
---
title: "Introduction générale"
date: "2022-09-20"
date: "2024-09-16"
---
# La hotline
......@@ -11,10 +11,9 @@ Paul Albuquerque paul.albuquerque@hesge.ch B410
Orestis Malaspinas orestis.malaspinas@hesge.ch A401
-------------------- ------------------------------ --------------------
* Utilisez le libre service (l'horaire sera fixé prochainement).
* On va intensivement utiliser *Element*, installez le et utilisez le!
* Espace de discussion [Matrix](https://matrix.to/#/!aKYVlcclmPGYXQFxAK:matrix.org?via=matrix.org), installez [element.io](https://element.io).
- Utilisez le libre service (l'horaire sera fixé prochainement).
- On va intensivement utiliser *Element*, installez le et utilisez le!
- Espace de discussion Matrix: <https://rb.gy/ku5es>, installez [element.io](https://element.io).
![](figs/matrix_qr.png){width=20%}
......@@ -23,31 +22,31 @@ Orestis Malaspinas orestis.malaspinas@hesge.ch A401
Tout le contenu de ce qu'on raconte se trouve sur cyberlearn:
- Algorithmes et structures de données
- <https://cyberlearn.hes-so.ch/course/view.php?id=13941>
- Clé d'inscription: algo_2021_22
- <https://cyberlearn.hes-so.ch/course/view.php?id=7276>
- Clé d'inscription: algo_2024_25
- Programmation Sequentielle en C
- <https://cyberlearn.hes-so.ch/course/view.php?id=12399>
- Clé d'inscription: prog_seq_2021_22
- <https://cyberlearn.hes-so.ch/course/view.php?id=7282>
- Clé d'inscription: prog_seq_2024_25
# Organisation du module
* Deux cours, 50% chacun.
1. Algorithmes et structures de données:
## Cinq cours, 20% chacun.
1. Algorithmes et structures de données (2 semestres):
* 1er semestre:
* bases de programmation en C jusqu'à Noël.
* algorithmique jusqu'à fin janvier.
* 2e semestre:
* algorithmique.
* Deux évaluations écrites par semestre (1er: novembre et janvier).
2. Programmation séquentielle en C
* Deux évaluations écrites par semestre (1er sem.: novembre et janvier).
2. Programmation séquentielle en C (2 semestres)
* Familiarisation avec l'environnement Linux.
* Travaux pratiques en C.
* Apprentissage du gestionnaire de versions: git.
* Plusieurs exercices illustrant les concepts d'algorithmique.
* Évaluations:
* Deux évaluations machine (1er semestre).
* Probablement, une évaluation machine et un projet (2e semestre).
* Évaluations (4 tests machine).
3. Programmation système
---
subtitle: "Algorithmique et structures de données, 2022-2023"
author: "P. Albuquerque (B410), P. Künzli et O. Malaspinas (A401), ISC, HEPIA"
subtitle: "Algorithmique et structures de données, 2024-2025"
author: "P. Albuquerque (B410) et O. Malaspinas (A401), ISC, HEPIA"
institute: En partie inspirés des supports de cours de P. Albuquerque
lang: fr-CH
revealjs-url: /reveal.js
......
PDFOPTIONS = -t beamer
# PDFOPTIONS += -F pantable
PDFOPTIONS += -F mermaid-filter
PDFOPTIONS += --highlight-style my_highlight.theme
PDFOPTIONS += --pdf-engine xelatex
PDFOPTIONS += -V theme:metropolis
PDFOPTIONS += -V themeoptions:numbering=none -V themeoptions:progressbar=foot
PDFOPTIONS += -V fontsize=smaller
PDFOPTIONS += -V urlcolor=blue
MD=$(wildcard *.md) # Tous les fichiers .md
PDF=$(MD:%.md=%.pdf) # Pour les fichier pdf on transforme .md -> .pdf
HTML=$(MD:%.md=%.html) # Pour les fichier html on transforme .md -> .html
MARKDOWN=$(MD:%.md=%.markdown) # Pour les fichier markdown on transforme .md -> .markdown
CHROMIUM:=$(shell which chromium || which chromium-browser)
all: puppeteer $(PDF)
# all: puppeteer $(PDF) $(HTML) # La cible par défaut (all) exécute les cibles %.pdf
docker: docker-compose.yml
docker-compose run slides
docker_clean: docker-compose.yml
docker-compose run slides clean
puppeteer:
@echo "Setting chromium to $(CHROMIUM) for puppeteer"
@echo -e "{\n\"executablePath\":" \"$(CHROMIUM)\" ",\n\"args\": [\"--no-sandbox\"]\n}" > .puppeteer.json
index.md: gen_index.sh
$(shell ./gen_index.sh)
index.html: index.md
pandoc -s $(OPTIONS) --css ../css/tufte-css/tufte.css -o $@ $^
markdown: $(MARKDOWN) # La markdown les cibles %.markdown
%.pdf: %.md metadata.yaml # %.pdf (chaque fichier %.md génère un fichier avec le même nom mais l'extension .pdf et la dépendance metadata.yaml)
pandoc -s $(OPTIONS) $(PDFOPTIONS) -o $@ $^
%.markdown: %.md metadata.yaml yq
sed '1 { /^---/ { :a N; /\n---/! ba; d} }' $< > no_header
grep -v -F -x -f no_header $< > header.yaml
echo "---" > tmp.yaml
./yq_linux_amd64 merge metadata.yaml header.yaml >> tmp.yaml
cat tmp.yaml no_header > $@
rm no_header header.yaml tmp.yaml
yq: # On peut même télécharger un petit programme avec notre makefile
wget -nc https://github.com/mikefarah/yq/releases/download/3.4.1/yq_linux_amd64
chmod "u+x" yq_linux_amd64
deploy: all index.html
mkdir -p algo_cours
cp *.pdf algo_cours
cp index.html algo_cours
clean:
rm -rf *.html *.pdf *.markdown yq_linux_amd64* index.md .puppeteer.json algo_cours *.err
.PHONY: clean index.md puppeteer yq
---
title: "Introduction aux algorithmes"
date: "2022-09-21"
---
# Qu'est-ce qu'un algorithme?
## Définition informelle (recette)
* des entrées (les ingrédients, le matériel utilisé) ;
* des instructions élémentaires simples (frire, flamber, etc.), dont les
exécutions dans un ordre précis amènent au résultat voulu ;
* un résultat : le plat préparé.
. . .
## Histoire et étymologie
- Existent depuis 4500 ans au moins (algorithme de division, crible
d'Eratosthène).
- Le mot algorithme est dérivé du nom du mathématicien perse
*Muḥammad ibn Musā al-Khwārizmī*, qui a été "latinisé" comme
*Algoritmi*.
. . .
## Définition formelle
En partant d'un état initial et d'entrées (peut-être vides), une séquence finie
d'instruction bien définies (ordonnées) implémentables sur un ordinateur, afin
de résoudre typiquement une classe de problèmes ou effectuer un calcul.
# Notions de base d'algorithmique
## Variable
. . .
* Paire: identifiant - valeur (assignation);
## Séquence d'instructions / expressions
. . .
* Opérateurs (arthimétiques / booléens)
* Boucles;
* Structures de contrôle;
* Fonctions;
# Algorithme de vérification qu'un nombre est premier (1/3)
Nombre premier: nombre possédant deux diviseurs entiers distincts.
. . .
## Algorithme naïf (problème)
```C
booléen est_premier(nombre)
si
pour tout i, t.q. 1 < i < nombre
i ne divise pas nombre
alors vrai
sinon faux
```
. . .
## Pas vraiment un algorithme: pas une séquence ordonnée et bien définie
. . .
## Problème: Comment écrire ça sous une forme algorithmique?
# Algorithme de vérification qu'un nombre est premier (2/3)
## Algorithme naïf (une solution)
```C
booléen est_premier(nombre) // fonction
soit i = 2; // variable, type, assignation
tant que i < nombre // boucle
si nombre modulo i == 0 // expression typée
retourne faux // expression typée
i = i + 1
retourne vrai // expression typée
```
# Algorithme de vérification qu'un nombre est premier (3/3)
## Algorithme naïf (une solution en C)
```C
bool est_premier(int nombre) {
int i; // i est un entier
i = 2; // assignation i à 2
while (i < nombre) { // boucle avec condition
if (0 == nombre % i) { // is i divise nombre
return false; // i n'est pas premier
}
i += 1; // sinon on incrémente i
}
return true;
}
```
. . .
## Exercice: Comment faire plus rapide?
# Génération d'un exécutable
- Pour pouvoir être exécuté un code C doit être d'abord compilé (avec `gcc` ou `clang`).
- Pour un code `prog.c` la compilation "minimale" est
```bash
$ gcc prog.c
$ ./a.out # exécutable par défaut
```
- Il existe une multitude d'options de compilation:
```bash
$ gcc -O1 -std=c11 -Wall -Wextra -g porg.c -o prog
-fsanitize=address
```
1. `-std=c11` utilisation de C11.
2. `-Wall et -Wextra` activation des warnings.
3. `-fsanitize=…` contrôles d’erreurs à l’exécution (coût en performance).
4. `-g` symboles de débogages sont gardés.
5. `-o` défini le fichier exécutable à produire en sortie.
6. `-O1`, `-O2`, `-O3`: activation de divers degrés d'optimisation
# La simplicité de C?
## 32 mots-clé et c'est tout
---------------- -------------- ---------------- ---------------
`auto`{.C} `double`{.C} `int`{.C} `struct`{.C}
`break`{.C} `else`{.C} `long`{.C} `switch`{.C}
`case`{.C} `enum`{.C} `register`{.C} `typedef`{.C}
`char`{.C} `extern`{.C} `return`{.C} `union`{.C}
`const`{.C} `float`{.C} `short`{.C} `unsigned`{.C}
`continue`{.C} `for`{.C} `signed`{.C} `void`{.C}
`default`{.C} `goto`{.C} `sizeof`{.C} `volatile`{.C}
`do`{.C} `if`{.C} `static`{.C} `while`{.C}
---------------- -------------- ---------------- ---------------
# Déclaration et typage
En C lorsqu'on veut utiliser une variable (ou une constante), on doit déclarer son type
```C
const double two = 2.0; // déclaration et init.
int x; // déclaration (instruction)
char c; // déclaration (instruction)
x = 1; // affectation (expression)
c = 'a'; // affectation (expression)
int y = x; // déclaration et initialisation en même temps
int a, b, c; // déclarations multiples
a = b = c = 1; // init. multiples
```
# Les variables (1/2)
## Variables et portée
- Une variable est un identifiant, qui peut être liée à une valeur (un expression).
- Une variable a une **portée** qui définit où elle est *visible* (où elle peut être accédée).
- La portée est **globale** ou **locale**.
- Une variable est **globale** est accessible à tout endroit d'un programme et doit être déclarée en dehors de toute fonction.
- Une variable est **locale** lorsqu'elle est déclarée dans un **bloc**, `{...}`{.C}.
- Une variable est dans la portée **après** avoir été déclarée.
# Les variables (2/2)
## Exemple
```C
float max; // variable globale accessible partout
int foo() {
// max est visible ici
float a = max; // valide
// par contre les varibles du main() ne sont pas visibles
}
int main() {
// max est visible ici
int x = 1; // x est locale à main
{
// x est visible ici, y pas encore
// on peut par exemple pas faire x = y;
int y = 2;
} // y est détruite à la sortie du bloc
} // x est à la sortie de main
```
<!-- TODO: quiz, compile, compile pas -->
<!-- ```C
int main() {
global = 1;
} // COMPILE PAS
```
```C
int main() {
int global = 1;
{
printf("global = %d", global);
}
} // COMPILE
```
```C
int local;
int main() {
local = 1;
{
printf("local = %d", local);
}
} // COMPILE
```
```C
#include <stdio.h>
int local = 0;
int main() {
int local = -1;
{
int local = 1;
printf("local = %d\n", local);
}
} // COMPILE
``` -->
# Quiz: compile ou compile pas?
## [Quiz: compile ou compile pas](https://cyberlearn.hes-so.ch/mod/evoting/view.php?id=1033948)
# Types de base (1/4)
## Numériques
Type Signification (**gcc pour x86-64**)
---------------------------------- ---------------------------------------------
`char`{.C}, `unsigned char`{.C} Entier signé/non-signé 8-bit
`short`{.C}, `unsigned short`{.C} Entier signé/non-signé 16-bit
`int`{.C}, `unsigned int`{.C} Entier signé/non-signé 32-bit
`long`{.C}, `unsigned long`{.C} Entier signé/non-signé 64-bit
`float`{.C} Nombre à virgule flottante, simple précision
`double`{.C} Nombre à virgule flottante, double précision
---------------------------------- ---------------------------------------------
**La signification de `short`{.C}, `int`{.C}, ... dépend du compilateur et de l'architecture.**
# Types de base (2/4)
Voir `<stdint.h>` pour des représentations **portables**
Type Signification
---------------------------------- ---------------------------------------------
`int8_t`{.C}, `uint8_t`{.C} Entier signé/non-signé 8-bit
`int16_t`{.C}, `uint16_t`{.C} Entier signé/non-signé 16-bit
`int32_t`{.C}, `uint32_t`{.C} Entier signé/non-signé 32-bit
`int64_t`{.C}, `uint64_t`{.C} Entier signé/non-signé 64-bit
---------------------------------- ---------------------------------------------
. . .
## Prenez l'habitude d'utiliser ces types-là!
# Types de base (3/4)
## Booléens
- Le ANSI C n'offre pas de booléens.
- L'entier `0`{.C} signifie *faux*, tout le reste *vrai*.
- Depuis C99, la librairie `stdbool` met à disposition un type `bool`{.C}.
- En réalité c'est un entier:
- $1 \Rightarrow$ `true`{.C}
- $0 \Rightarrow$ `false`{.C}
- On peut les manipuler comme des entier (les sommer, les multiplier, ...).
# Quiz: booléens
## [Quiz: booléens](https://cyberlearn.hes-so.ch/mod/evoting/view.php?id=1032492)
<!-- TODO Quiz en ligne -->
<!-- ```C
if (42) { /* vrai */ }
int x = 100;
if (x == 4) { /* faux */ }
if (x) { /* vrai */ }
int x = 100;
while (x−−) { /* répète tant que x est différent de 0 */ }
if (0) { /* faux */ }
if (i = 4) { /* vrai */ }
if (i = 0) { /* faux */ }
#include <stdbool.h>
bool x = true;
if (x) { /* vrai */ }
``` -->
# Types de base (4/4)
## Conversions
- Les conversions se font de manière:
- Explicite:
```C
int a = (int)2.8;
double b = (double)a;
int c = (int)(2.8+0.5);
```
- Implicite:
```C
int a = 2.8; // warning, si activés, avec clang
double b = a + 0.5;
char c = b; // pas de warning...
int d = 'c';
```
# Quiz: conversions
## [Quiz: conversions](https://cyberlearn.hes-so.ch/mod/evoting/view.php?id=1033446)
<!-- TODO Quiz en ligne -->
<!-- ```C
int a = (int)2.8; // 2
double b = 2.85;
int c = b + 0.5; // 3
int d = a + 0.5; // 2
bool d = 2.78; // 1
bool e = 1.0; // 1
``` -->
# Expressions et opérateurs (1/6)
Une expression est tout bout de code qui est **évalué**.
## Expressions simples
- Pas d'opérateurs impliqués.
- Les littéraux, les variables, et les constantes.
```C
const int L = -1; // 'L' est une constante, -1 un littéral
int x = 0; // '0' est un litéral
int y = x; // 'x' est une variable
int z = L; // 'L' est une constante
```
## Expressions complexes
- Obtenues en combinant des *opérandes* avec des *opérateurs*
```C
int x; // pas une expression (une instruction)
x = 4 + 5; // 4 + 5 est une expression
// dont le résultat est affecté à 'x'
```
# Expressions et opérateurs (2/6)
## Opérateurs relationnels
Opérateurs testant la relation entre deux *expressions*:
- `(a opérateur b)` retourne `1`{.C} si l'expression s'évalue à `true`{.C}, `0`{.C} si l'expression s'évalue à `false`{.C}.
| Opérateur | Syntaxe | Résultat |
|-----------|--------------|----------------------|
| `<`{.C} | `a < b`{.C} | 1 si a < b; 0 sinon |
| `>`{.C} | `a > b`{.C} | 1 si a > b; 0 sinon |
| `<=`{.C} | `a <= b`{.C} | 1 si a <= b; 0 sinon |
| `>=`{.C} | `a >= b`{.C} | 1 si a >= b; 0 sinon |
| `==`{.C} | `a == b`{.C} | 1 si a == b; 0 sinon |
| `!=`{.C} | `a != b`{.C} | 1 si a != b; 0 sinon |
# Expressions et opérateurs (3/6)
## Opérateurs logiques
| Opérateur | Syntaxe | Signification |
|-----------|--------------|----------------------|
| `&&`{.C} | `a && b`{.C} | ET logique |
| `||`{.C} | `a || b`{.C} | OU logique |
| `!`{.C} | `!a`{.C} | NON logique |
# Quiz: opérateurs logiques
## [Quiz: opérateurs logiques](https://cyberlearn.hes-so.ch/mod/evoting/view.php?id=1033629)
<!-- TODO: Quiz -->
<!-- ```C
1 && 0 == 0
7 && 3 == 1
4 || 3 == 1
!34 == 0
!0 == 1
Soit n un unsigned char initialisé à 127:
!n == 0
``` -->
# Expressions et opérateurs (4/6)
## Opérateurs arithmétiques
| Opérateur | Syntaxe | Signification |
|-----------|--------------|----------------------|
| `+`{.C} | `a + b`{.C} | Addition |
| `-`{.C} | `a - b`{.C} | Soustraction |
| `*`{.C} | `a * b`{.C} | Multiplication |
| `/`{.C} | `a / b`{.C} | Division |
| `%`{.C} | `a % b`{.C} | Modulo |
# Expressions et opérateurs (5/6)
## Opérateurs d'assignation
| Opérateur | Syntaxe | Signification |
|-----------|--------------|---------------------------------------------|
| `=`{.C} | `a = b`{.C} | Affecte la valeur `b` à la variable `a` |
| | | et retourne la valeur de `b` |
| `+=`{.C} | `a += b`{.C} | Additionne la valeur de `b` à `a` et |
| | | assigne le résultat à `a`. |
| `-=`{.C} | `a -= b`{.C} | Soustrait la valeur de `b` à `a` et |
| | | assigne le résultat à `a`. |
| `*=`{.C} | `a *= b`{.C} | Multiplie la valeur de `b` à `a` et |
| | | assigne le résultat à `a`. |
| `/=`{.C} | `a /= b`{.C} | Divise la valeur de `b` à `a` et |
| | | assigne le résultat à `a`. |
| `%=`{.C} | `a %= b`{.C} | Calcule le modulo la valeur de `b` à `a` et |
| | | assigne le résultat à `a`. |
# Expressions et opérateurs (6/6)
## Opérateurs d'assignation (suite)
| Opérateur | Syntaxe | Signification |
|-----------|--------------|---------------------------------------------|
| `++`{.C} | `++a`{.C} | Incrémente la valeur de `a` de 1 et |
| | | retourne le résultat (`a += 1`). |
| `--`{.C} | `--a`{.C} | Décrémente la valeur de `a` de 1 et |
| | | retourne le résultat (`a -= 1`). |
| `++`{.C} | `a++`{.C} | Retourne `a`{.C} et incrémente `a` de 1. |
| `--`{.C} | `a--`{.C} | Retourne `a`{.C} et décrémente `a` de 1. |
# Structures de contrôle: `if`{.C} .. `else if`{.C} .. `else`{.C} (1/2)
## Syntaxe
```C
if (expression) {
instructions;
} else if (expression) { // optionnel
// il peut y en avoir plusieurs
instructions;
} else {
instructions; // optionnel
}
```
```C
if (x) { // si x s'évalue à `vrai`
printf("x s'évalue à vrai.\n");
} else if (y == 8) { // si y vaut 8
printf("y vaut 8.\n");
} else {
printf("Ni l'un ni l'autre.\n");
}
```
# Structures de contrôle: `if`{.C} .. `else if`{.C} .. `else`{.C} (2/2)
## Pièges
```C
int x, y;
x = y = 3;
if (x = 2)
printf("x = 2 est vrai.\n");
else if (y < 8)
printf("y < 8.\n");
else if (y == 3)
printf("y vaut 3 mais cela ne sera jamais affiché.\n");
else
printf("Ni l'un ni l'autre.\n");
x = -1; // toujours évalué
```
# Quiz: `if ... else`{.C}
## [Quiz: `if ... else`{.C}](https://cyberlearn.hes-so.ch/mod/evoting/view.php?id=1033916)
# Structures de contrôle: `while`{.C}
## La boucle `while`{.C}
```C
while (condition) {
instructions;
}
do {
instructions;
} while (condition);
```
## La boucle `while`{.C}, un exemple
```C
int sum = 0; // syntaxe C99
while (sum < 10) {
sum += 1;
}
do {
sum += 10;
} while (sum < 100)
```
# Structures de contrôle: `for`{.C}
## La boucle `for`{.C}
```C
for (expression1; expression2; expression3) {
instructions;
}
```
## La boucle `for`{.C}
```C
int sum = 0; // syntaxe C99
for (int i = 0; i < 10; i++) {
sum += i;
}
for (int i = 0; i != 1; i = rand() % 4) { // ésotérique
printf("C'est plus ésotérique.\n");
}
```
---
title: "Piles"
date: "2022-12-14"
patat:
eval:
tai:
command: fish
fragment: false
replace: true
ccc:
command: fish
fragment: false
replace: true
images:
backend: auto
---
# Rappel
## Qu'est-ce qu'une pile?
. . .
* Structure de données LIFO.
## Quelles fonctionnalités?
. . .
1. Empiler (push): ajouter un élément sur la pile.
2. Dépiler (pop): retirer l'élément du sommet de la pile et le retrouner.
3. Liste vide? (is_empty?).
4. Jeter un oeil (peek): retourner l'élément du sommet de la pile (sans le dépiler).
5. Nombre d'éléments (length).
# Le tri à deux piles (3/3)
## Exercice: trier le tableau `[2, 10, 5, 20, 15]`
```C
```
# La calculatrice (1/8)
## Vocabulaire
```C
2 + 3 = 2 3 +,
```
`2` et `3` sont les *opérandes*, `+` l'*opérateur*.
. . .
## La notation infixe
```C
2 * (3 + 2) - 4 = 6.
```
## La notation postfixe
```C
2 3 2 + * 4 - = 6.
```
## Exercice: écrire `2 * 3 * 4 + 2` en notation `postfixe`
. . .
```C
2 3 4 * * 2 + = (2 * (3 * 4)) + 2.
```
# La calculatrice (2/8)
## De infixe à post-fixe
* Une *pile* est utilisée pour stocker *opérateurs* et *parenthèses*.
* Les opérateurs on des *priorités* différentes.
```C
^ : priorité 3
* / : priorité 2
+ - : priorité 1
( ) : priorité 0 // pas un opérateur mais bon
```
# La calculatrice (3/8)
## De infixe à post-fixe: algorithme
* On lit l'expression infixe de gauche à droite.
* On examine le prochain caractère de l'expression infixe.
* Si opérande, le placer dans l'expression du résultat.
* Si parenthèse le mettre dans la pile (priorité 0).
* Si opérateur, comparer sa priorité avec celui du sommet de la pile:
* Si sa priorité est plus élevée, empiler.
* Sinon dépiler l'opérateur de la pile dans l'expression du résultat et
recommencer jusqu'à apparition d'un opérateur de priorité plus faible
au sommet de la pile (ou pile vide).
* Si parenthèse fermée, dépiler les opérateurs du sommet de la pile et les
placer dans l'expression du résultat, jusqu'à ce qu'une parenthèse
ouverte apparaisse au sommet, dépiler également la parenthèse.
* Si il n'y a pas de caractère dans l'expression dépiler tous les
opérateurs dans le résultat.
# La calculatrice (4/8)
## De infixe à post-fixe: exemple
```C
Infixe Postfixe Pile Priorité
((A*B)/D-F)/(G+H) Vide Vide Néant
(A*B)/D-F)/(G+H) Vide ( 0
A*B)/D-F)/(G+H) Vide (( 0
*B)/D-F)/(G+H) A (( 0
B)/D-F)/(G+H) A ((* 2
)/D-F)/(G+H) AB ((* 2
/D-F)/(G+H) AB* ( 0
D-F)/(G+H) AB* (/ 2
-F)/(G+H) AB*D (/ 2
F)/(G+H) AB*D/ (- 1
)/(G+H) AB*D/F (- 1
/(G+H) AB*D/F- Vide Néant
```
# La calculatrice (5/8)
## De infixe à post-fixe: exemple
```C
Infixe Postfixe Pile Priorité
((A*B)/D-F)/(G+H) Vide Vide Néant
--------------------------------------------------------
/(G+H) AB*D/F- Vide Néant
(G+H) AB*D/F- / 2
G+H) AB*D/F- /( 0
+H) AB*D/F-G /( 0
H) AB*D/F-G /(+ 1
) AB*D/F-GH /(+ 1
Vide AB*D/F-GH+ / 2
Vide AB*D/F-GH+/ Vide Néant
```
# La calculatrice (6/8)
\footnotesize
## Exercice: écrire le code et le poster sur matrix
* Quelle est la signature de la fonction?
. . .
* Une sorte de corrigé:
```C
char *infix_to_postfix(char* infix) { // init and alloc stack and postfix
for (size_t i = 0; i < strlen(infix); ++i) {
if (is_operand(infix[i])) {
// we just add operands in the new postfix string
} else if (infix[i] == '(') {
// we push opening parenthesis into the stack
} else if (infix[i] == ')') {
// we pop everything into the postfix
} else if (is_operator(infix[i])) {
// this is an operator. We add it to the postfix based
// on the priority of what is already in the stack and push it
}
}
// pop all the operators from the s at the end of postfix
// and end the postfix with `\0`
return postfix;
}
```
# La calculatrice (7/8)
## Évaluation d'expression postfixe: algorithme
* Chaque *opérateur* porte sur les deux opérandes qui le précèdent.
* Le *résultat d'une opération* est un nouvel *opérande* qui est remis au
sommet de la pile.
## Exemple
```C
2 3 4 + * 5 - = ?
```
* On parcours de gauche à droite:
```C
Caractère lu Pile opérandes
2 2
3 2, 3
4 2, 3, 4
+ 2, (3 + 4)
* 2 * 7
5 14, 5
- 14 - 5 = 9
```
# La calculatrice (8/8)
## Évaluation d'expression postfixe: algorithme
1. La valeur d'un opérande est *toujours* empilée.
2. L'opérateur s'applique *toujours* au 2 opérandes au sommet.
3. Le résultat est remis au sommet.
## Exercice: écrire l'algorithme en C (et poster sur matrix)
. . .
```C
bool evaluate(char *postfix, double *val) { // init stack
for (size_t i = 0; i < strlen(postfix); ++i) {
if (is_operand(postfix[i])) {
stack_push(&s, postfix[i]);
} else if (is_operator(postfix[i])) {
double rhs = stack_pop(&s);
double lhs = stack_pop(&s);
stack_push(&s, op(postfix[i], lhs, rhs));
}
}
return stack_pop(&s);
}
```
# La liste chaînée et pile (1/6)
## Structure de données
* Chaque élément de la liste contient:
1. une valeur,
2. un pointeur vers le prochain élément.
* La pile est un pointeur vers le premier élément.
![Un exemple de liste chaînée.](figs/Singly-linked-list.svg){width=80%}
# La liste chaînée et pile (2/6)
## Une pile-liste-chaînée
```C
typedef struct _element {
int data;
struct _element *next;
} element;
typedef element* stack;
```
## Fonctionnalités?
. . .
```C
void stack_create(stack *s); // *s = NULL;
void stack_destroy(stack *s);
void stack_push(stack *s, int val);
void stack_pop(stack *s, int *val);
void stack_peek(stack s, int *val);
bool stack_is_empty(stack s); // reutrn NULL == stack;
```
# La liste chaînée et pile (3/6)
## Empiler? (faire un dessin)
. . .
```C
```
## Empiler? (le code ensemble)
. . .
```C
void stack_push(stack *s, int val) {
element *elem = malloc(sizeof(*elem));
elem->data = val;
elem->next = *s;
s = elem;
}
```
# La liste chaînée et pile (4/6)
## Jeter un oeil? (faire un dessin)
. . .
```C
```
## Jeter un oeil? (le code ensemble)
. . .
```C
void stack_peek(stack s, int *val) {
*val = s->data;
}
```
# La liste chaînée et pile (5/6)
## Dépiler? (faire un dessin)
. . .
```C
```
## Dépiler? (le code ensemble)
. . .
```C
void stack_pop(stack *s, int *val) {
stack_peek(*s, val);
element *tmp = *s;
*s = (*s)->next;
free(tmp);
return val;
}
```
# La liste chaînée et pile (6/6)
## Détruire? (faire un dessin)
. . .
```C
```
## Détruire? (le code ensemble)
. . .
```C
void stack_destroy(stack *s) {
while (!stack_is_empty(*s)) {
int val = stack_pop(s);
}
}
```
---
title: "Files d'attente et listes triées"
date: "2022-12-21"
---
# La file d'attente (1/N)
* Structure de données abstraite permettant le stockage d'éléments.
* *FIFO*: First In First Out, ou première entrée première sortie.
* Analogue de la vie "réelle"":
* File à un guichet,
* Serveur d'impressions,
* Mémoire tampon, ...
## Fonctionnalités
. . .
* Enfiler: ajouter un élément à la fin de la file.
* Défiler: extraire un élément au devant de la file.
* Tester si la file est vide.
. . .
* Lire l'élément de la fin de la file.
* Lire l'élément du devant de la file.
* Créer une liste vide.
* Détruire une liste vide.
# La file d'attente (2/N)
\footnotesize
## Implémentation possible
* La structure file, contient un pointeur vers la tête et un vers le début de la file.
* Entre les deux, les éléments sont stockés dans une liste chaînée.
![Illustration d'une file d'attente.](figs/fig_queue_representation.png){width=80%}
## Structure de données en C?
. . .
```C
typedef struct _element { // Elément de liste
int data;
struct _element* next;
} element;
typedef struct _queue { // File d'attente:
element* head; // tête de file d'attente
element* tail; // queue de file d'attente
} queue;
```
# Fonctionnalités d'une file d'attente
## Creation et consultations
. . .
```C
void queue_init(queue *fa); // head = tail = NULL
bool queue_is_empty(queue fa); // fa.head == fa.tail == NULL
int queue_tail(queue fa); // return fa.head->data
int queue_head(queue fa); // return fa.tail->data
```
## Manipulations et destruction
. . .
```C
void queue_enqueue(queue *fa, int val);
// adds an element before the tail
int queue_dequeue(queue *fa);
// removes the head and returns stored value
void queue_destroy(queue *fa);
// dequeues everything into oblivion
```
# Enfilage
## Deux cas différents:
1. La file est vide (faire un dessin):
. . .
![Insertion dans une file d'attente vide.](./figs/fig_empty_queue_insert.png){width=40%}
2. La file n'est pas vide (faire un dessin):
. . .
![Insertion dans une file d'attente non-vide.](./figs/fig_non_empty_queue_insert.png){width=70%}
# Enfilage
## Live (implémentation)
. . .
```C
void queue_enqueue(queue *fa, int val) {
element* elmt = malloc(sizeof(*elmt));
elmt->data = val;
elmt->next = NULL;
if (queue_is_empty(*fa)) {
fa->head = elmt;
fa->tail = elmt;
} else {
fa->tail->next = elmt;
fa->tail = elmt;
}
}
```
# Défilage
## Trois cas différents
1. La file a plus d'un élément (faire un dessin):
. . .
![Extraction d'une file d'attente](./figs/fig_queue_extract.png){width=80%}
2. La file un seul élément (faire un dessin):
. . .
![Extraction d'une file d'attente de longueur 1.](./figs/fig_queue_extract_one.svg){width=25%}
3. La file est vide (problème)
# Défilage
## Live (implémentation)
. . .
```C
int queue_dequeue(queue *fa) {
element* elmt = fa->head;
int val = elmt->data;
fa->head = fa->head->next;
free(elmt);
if (NULL == fa->head) {
fa->tail = NULL;
}
return val;
}
```
. . .
## Problème avec cette implémentation?
# Destruction
## Comment on faire la désallocation?
. . .
On défile jusqu'à ce que la file soit vide!
# Complexité
## Quelle sont les complexité de:
* Enfiler?
. . .
* Défiler?
. . .
* Détruire?
. . .
* Est vide?
# Implémentation alternative
## Comment implémenter la file autrement?
. . .
* Données stockées dans un tableau;
* Tableau de taille connue à la compilation ou pas (réallouable);
* `tail` seraient les indices du tableau;
* `capacity` seraient la capacité maximale;
* On *enfile* "au bout" du tableau, au défile au début (indice `0`).
. . .
## Structure de données
```C
typedef struct _queue {
int *data;
int tail, capacity;
} queue;
```
# File basée sur un tableau
* Initialisation?
. . .
```C
```
* Est vide?
. . .
```C
```
* Enfiler?
. . .
```C
```
* Défiler?
. . .
```C
```
# Complexité
## Quelle sont les complexités de:
* Initialisation?
. . .
```C
```
* Est vide?
. . .
```C
```
* Enfiler?
. . .
```C
```
* Défiler?
. . .
```C
```
# Une file plus efficace
## Comment faire une file plus efficace?
* Où est-ce que ça coince?
. . .
* Défiler est particulièrement lent $\mathcal{O}(N)$.
## Solution?
. . .
* Utiliser un indice séparé pour `head`.
```C
typedef struct _queue {
int *data;
int head, tail, capacity;
} queue;
```
# Une file plus efficace (implémentation)
## Enfilage
\footnotesize
```C
void queue_enqueue(queue *fa, int val) {
if ((fa->head == 0 && fa->tail == fa->capacity-1) ||
(fa->tail == (fa->head-1) % (fa->capacity-1))) {
return; // queue is full
}
if (fa->head == -1) { // queue was empty
fa->head = fa->tail = 0;
fa->data[fa->tail] = val;
} else if (fa->tail == fa->capacity-1 && fa->head != 0) {
// the tail reached the end of the array
fa->tail = 0;
fa->data[fa->tail] = val;
} else {
// nothing particular
fa->tail += 1;
fa->data[fa->tail] = val;
}
}
```
# Une file plus efficace (implémentation)
## Défilage
```C
void queue_dequeue(queue *fa, int *val) {
if (queue_is_empty(*fa)) {
return; // queue is empty
}
*val = fa->data[fa->head];
if (fa->head == fa->tail) { // that was the last element
fa->head = fa->tail = -1;
} else if (fa->head == fa->capacity-1) {
fa->head = 0;
} else {
fa->head += 1;
}
}
```
# Les listes triées
Une liste chaînée triée est:
* une liste chaînée
* dont les éléments sont insérés dans l'ordre.
![Exemple de liste triée.](./figs/sorted_list_example.svg)
. . .
* L'insertion est faite telle que l'ordre est maintenu.
## Quelle structure de données?
```C
```
# Les listes triées
## Quel but?
* Permet de retrouver rapidement un élément.
* Utile pour la recherche de plus court chemin dans des graphes.
* Ordonnancement de processus par degré de priorité.
## Comment?
* Les implémentations les plus efficaces se basent sur les tableaux.
* Possibles aussi avec des listes chaînées.
# Les listes triées
\footnotesize
## Quelle structure de données dans notre cas?
Une liste chaînée bien sûr (oui c'est pour vous entraîner)!
```C
typedef struct _element { // chaque élément
int data;
struct _element *next;
} element;
typedef element* sorted_list; // la liste
```
## Fonctionnalités
```C
// insertion de val
sorted_list sorted_list_push(sorted_list list, int val);
// la liste est-elle vide?
bool is_empty(sorted_list list); // list == NULL
// extraction de val (il disparaît)
sorted_list sorted_list_extract(sorted_list list, int val);
// rechercher un élément et le retourner
element* sorted_list_search(sorted_list list, int val);
```
# L'insertion
## Trois cas
1. La liste est vide.
. . .
![Insertion dans une liste vide, `list == NULL`.](figs/sorted_list_insert_one.svg){width=30%}
. . .
```C
sorted_list sorted_list_push(sorted_list list, int val) {
if (sorted_list_is_empty(list)) {
list = malloc(sizeof(*list));
list->data = val;
list->next = NULL;
return list;
}
}
```
# L'insertion
2. L'insertion se fait en première position.
. . .
![Insertion en tête de liste, `list->data >=
val`.](figs/sorted_list_insert_first.svg){width=80%}
. . .
```C
sorted_list sorted_list_push(sorted_list list, int val) {
if (list->data >= val) {
element *tmp = malloc(sizeof(*tmp));
tmp->data = val;
tmp->next = list;
list = tmp;
return list;
}
}
```
# L'insertion
3. L'insertion se fait sur une autre position que la première.
. . .
![Insertion sur une autre position, list->data <
val.](figs/sorted_list_insert_any.svg){width=70%}
. . .
\footnotesize
```C
sorted_list sorted_list_push(sorted_list list, int val) {
element *tmp = malloc(sizeof(*tmp));
tmp->data = val;
element *crt = list;
while (NULL != crt->next && val > crt->next->data) {
crt = crt->next;
}
tmp->next = crt->next;
crt->next = tmp;
return list;
}
```