[{"data":1,"prerenderedAt":825},["ShallowReactive",2],{"article-fr-\u002Fdsa\u002Fbuble-sort":3,"article-sibling-fr-\u002Fdsa\u002Fbuble-sort":443,"surround-fr-\u002Fdsa\u002Fbuble-sort":808,"related-fr-\u002Fdsa\u002Fbuble-sort":813},{"id":4,"title":5,"body":6,"date":429,"description":430,"extension":431,"img":432,"meta":433,"navigation":200,"path":434,"seo":435,"slug":436,"stem":437,"tags":438,"topics":440,"__hash__":442},"content\u002F1.dsa\u002F1.buble-sort.fr.md","Le tri à bulles dévoilé avec Python",{"type":7,"value":8,"toc":418},"minimark",[9,14,23,27,30,33,37,40,45,48,100,106,110,113,116,166,169,173,176,341,344,361,364,368,371,397,404,408,411,414],[10,11,13],"h2",{"id":12},"introduction","Introduction",[15,16,17,18,22],"p",{},"Le tri est une opération fondamentale en informatique, et il existe différents algorithmes pour\nl'accomplir. L'un des plus simples est le ",[19,20,21],"strong",{},"tri à bulles"," (Bubble Sort). Même s'il n'est pas le\nplus efficace pour de grands jeux de données, le comprendre est une excellente porte d'entrée\nvers les principes de base des algorithmes de tri. Dans cet article, on explore ce qu'est le tri\nà bulles et comment l'implémenter en Python.",[10,24,26],{"id":25},"cest-quoi-le-tri-à-bulles","C'est quoi le tri à bulles",[15,28,29],{},"Le tri à bulles est un algorithme de tri par comparaison qui parcourt la liste à trier de\nmanière répétée. Il compare des éléments adjacents et les échange s'ils sont dans le mauvais\nordre. L'algorithme continue d'itérer sur la liste jusqu'à ce qu'aucun échange ne soit\nnécessaire, signe que la liste est triée.",[15,31,32],{},"L'idée centrale : les plus grands éléments « remontent comme des bulles » vers la fin de la\nliste, tandis que les plus petits « coulent » vers le début.",[10,34,36],{"id":35},"comment-fonctionne-le-tri-à-bulles","Comment fonctionne le tri à bulles",[15,38,39],{},"Deux versions : pour un enfant, et pour un adulte.",[41,42,44],"h3",{"id":43},"pour-un-enfant","Pour un enfant",[15,46,47],{},"Imagine que tu as plein de balles colorées et que tu veux les ranger de la plus légère à la plus\nlourde. Voici comment ça marche :",[49,50,51,64,82,93],"ol",{},[52,53,54,55],"li",{},"Comparer et échanger les balles",[56,57,58,61],"ul",{},[52,59,60],{},"Tu regardes les deux premières balles. Si la première est plus lourde que la seconde, tu\nles échanges. Maintenant la balle la plus lourde est après la plus légère.",[52,62,63],{},"Tu passes à la paire suivante et tu fais pareil. Et ainsi de suite pour toutes les paires\nde ta collection.",[52,65,66,67],{},"Une tournée de comparaisons et d'échanges",[56,68,69,76,79],{},[52,70,71,72,75],{},"Quand tu as fait toutes les paires, tu remarques que la balle la plus lourde a ",[19,73,74],{},"remonté","\njusqu'au bout de la rangée.",[52,77,78],{},"Tu ne touches plus à la plus lourde, elle est à sa place.",[52,80,81],{},"Tu recommences, mais seulement avec les balles avant la plus lourde. Tu compares et\néchanges si besoin.",[52,83,84,85],{},"Recommencer jusqu'à ce que tout soit trié",[56,86,87,90],{},[52,88,89],{},"Tu refais ces tournées de comparaisons et d'échanges, avec à chaque fois de moins en moins\nde balles à regarder.",[52,91,92],{},"Tu répètes jusqu'à ce qu'une tournée se passe sans aucun échange. Là, toutes les balles\nsont rangées !",[52,94,95,96,99],{},"Le tri à bulles, c'est comme des bulles qui remontent",[97,98],"br",{},"Le nom vient de l'image des bulles dans une boisson gazeuse. Les plus grosses bulles\nremontent en premier, les plus petites suivent.",[15,101,102,103,105],{},"En mots simples, le ",[19,104,21],{}," consiste à ranger des balles colorées en regardant les\npaires et en les échangeant si elles sont dans le mauvais ordre. On répète jusqu'à ce que les\nballes soient alignées de la plus légère à la plus lourde, comme les bulles dans ta boisson.",[41,107,109],{"id":108},"pour-un-adulte","Pour un adulte",[15,111,112],{},"Le tri à bulles est un algorithme simple qui parcourt une liste d'éléments (nombres, mots…) de\nmanière répétée, compare chaque paire d'éléments adjacents, et les échange s'ils sont dans le\nmauvais ordre. Le parcours est répété autant de fois qu'il y a d'éléments dans la liste. Le nom\nde l'algorithme vient du fait que les petits éléments « remontent comme des bulles d'air dans\nl'eau » alors que les grands « coulent » vers le bas.",[15,114,115],{},"Décomposons :",[49,117,118,124,138,149,155],{},[52,119,120,121,123],{},"Comparaison et échange",[97,122],{},"L'algorithme commence par comparer les deux premiers éléments. Si le premier est plus grand\nque le second, il les échange. Ce process continue pour chaque paire adjacente.",[52,125,126,127],{},"Un passage complet sur la liste",[56,128,129,135],{},[52,130,131,132,134],{},"Après ce premier passage, le plus grand élément a ",[19,133,74],{}," à la dernière position.",[52,136,137],{},"L'algorithme refait le même process sur les éléments restants, en excluant le dernier.",[52,139,140,141],{},"Répéter jusqu'au tri complet",[56,142,143,146],{},[52,144,145],{},"L'algorithme répète ces passages jusqu'à ce qu'aucun échange ne soit nécessaire. Tous les\néléments sont alors à leur position triée.",[52,147,148],{},"À chaque passage, les plus petits éléments « remontent » vers leur position correcte.",[52,150,151,152,154],{},"Optimisation",[97,153],{},"Une petite optimisation : un drapeau qui suit si un échange a eu lieu pendant un passage. Si\naucun échange n'a eu lieu, la liste est déjà triée et on peut s'arrêter plus tôt.",[52,156,157,158],{},"Complexité temporelle",[56,159,160,163],{},[52,161,162],{},"Au pire des cas, le tri à bulles demande n passages, où n est le nombre d'éléments. À\nchaque passage il compare et éventuellement échange des éléments adjacents.",[52,164,165],{},"Ce qui donne une complexité de O(n²), donc une performance qui s'effondre sur les grandes\nlistes.",[15,167,168],{},"En résumé : le tri à bulles est simple conceptuellement et facile à comprendre, mais peu\nefficace pour les grands jeux de données à cause de sa complexité quadratique. Il sert surtout\nen pédagogie. En production, on préfère Quick Sort, Merge Sort ou les fonctions de tri intégrées\nau langage, pour leurs performances bien meilleures.",[10,170,172],{"id":171},"implémentation-en-python","Implémentation en Python",[15,174,175],{},"Voici une implémentation pas à pas du tri à bulles en Python (version optimisée avec drapeau).\nLe drapeau permet de savoir si un échange a eu lieu pendant une itération. Si non, le tableau\nest déjà trié et l'algorithme s'arrête plus tôt.",[177,178,184],"pre",{"className":179,"code":180,"filename":181,"language":182,"meta":183,"style":183},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","from typing import List, Any\n\ndef bubble_sort(collection: List[Any]) -> List[Any]:\n    n = len(collection)\n\n    for i in range(n):\n        swapped = False  # Initialize the flag\n        for j in range(0, n-i-1):\n            if collection[j] > collection[j+1]:\n                collection[j], collection[j+1] = collection[j+1], collection[j]  # Swap the elements\n                swapped = True\n        if not swapped:\n            break  # No swaps were made, collection is sorted\n\n    return collection\n\ndef main():\n    # Input collection from the user\n    input_str = input(\"Enter a collection separated by a comma:\")\n    input_list = [x.strip() for x in input_str.split(',')]\n\n    # Print sorted collection\n    print(*bubble_sort(input_list), sep=\",\")\n\nif __name__ == \"__main__\":\n    main()\n","buble_sorting.py","python","",[185,186,187,195,202,208,214,219,225,231,237,243,249,255,261,267,272,278,283,289,295,301,307,312,318,324,329,335],"code",{"__ignoreMap":183},[188,189,192],"span",{"class":190,"line":191},"line",1,[188,193,194],{},"from typing import List, Any\n",[188,196,198],{"class":190,"line":197},2,[188,199,201],{"emptyLinePlaceholder":200},true,"\n",[188,203,205],{"class":190,"line":204},3,[188,206,207],{},"def bubble_sort(collection: List[Any]) -> List[Any]:\n",[188,209,211],{"class":190,"line":210},4,[188,212,213],{},"    n = len(collection)\n",[188,215,217],{"class":190,"line":216},5,[188,218,201],{"emptyLinePlaceholder":200},[188,220,222],{"class":190,"line":221},6,[188,223,224],{},"    for i in range(n):\n",[188,226,228],{"class":190,"line":227},7,[188,229,230],{},"        swapped = False  # Initialize the flag\n",[188,232,234],{"class":190,"line":233},8,[188,235,236],{},"        for j in range(0, n-i-1):\n",[188,238,240],{"class":190,"line":239},9,[188,241,242],{},"            if collection[j] > collection[j+1]:\n",[188,244,246],{"class":190,"line":245},10,[188,247,248],{},"                collection[j], collection[j+1] = collection[j+1], collection[j]  # Swap the elements\n",[188,250,252],{"class":190,"line":251},11,[188,253,254],{},"                swapped = True\n",[188,256,258],{"class":190,"line":257},12,[188,259,260],{},"        if not swapped:\n",[188,262,264],{"class":190,"line":263},13,[188,265,266],{},"            break  # No swaps were made, collection is sorted\n",[188,268,270],{"class":190,"line":269},14,[188,271,201],{"emptyLinePlaceholder":200},[188,273,275],{"class":190,"line":274},15,[188,276,277],{},"    return collection\n",[188,279,281],{"class":190,"line":280},16,[188,282,201],{"emptyLinePlaceholder":200},[188,284,286],{"class":190,"line":285},17,[188,287,288],{},"def main():\n",[188,290,292],{"class":190,"line":291},18,[188,293,294],{},"    # Input collection from the user\n",[188,296,298],{"class":190,"line":297},19,[188,299,300],{},"    input_str = input(\"Enter a collection separated by a comma:\")\n",[188,302,304],{"class":190,"line":303},20,[188,305,306],{},"    input_list = [x.strip() for x in input_str.split(',')]\n",[188,308,310],{"class":190,"line":309},21,[188,311,201],{"emptyLinePlaceholder":200},[188,313,315],{"class":190,"line":314},22,[188,316,317],{},"    # Print sorted collection\n",[188,319,321],{"class":190,"line":320},23,[188,322,323],{},"    print(*bubble_sort(input_list), sep=\",\")\n",[188,325,327],{"class":190,"line":326},24,[188,328,201],{"emptyLinePlaceholder":200},[188,330,332],{"class":190,"line":331},25,[188,333,334],{},"if __name__ == \"__main__\":\n",[188,336,338],{"class":190,"line":337},26,[188,339,340],{},"    main()\n",[15,342,343],{},"L'approche du tri à bulles avec drapeau d'optimisation, en résumé :",[49,345,346,349,352,355,358],{},[52,347,348],{},"On suppose au départ qu'aucun échange n'a eu lieu pendant l'itération courante.",[52,350,351],{},"On parcourt le tableau et compare les éléments adjacents.",[52,353,354],{},"Si l'élément de gauche est plus grand que celui de droite, on les échange et on positionne\nle drapeau à vrai.",[52,356,357],{},"À la fin de la boucle interne, si le drapeau est toujours à faux, le tableau est déjà trié\net on peut sortir tôt.",[52,359,360],{},"On répète les étapes 2 à 4 tant qu'un passage produit au moins un échange.",[15,362,363],{},"Cette optimisation réduit potentiellement le nombre d'itérations et de comparaisons quand le\ntableau est déjà trié ou presque, ce qui rend le tri à bulles légèrement plus efficace.",[10,365,367],{"id":366},"applications-dans-le-monde-réel","Applications dans le monde réel",[15,369,370],{},"En pratique, le tri à bulles est rarement utilisé en production à cause de son inefficacité par\nrapport à d'autres algorithmes. Il garde toutefois quelques cas d'usage limités et reste précieux\nsur le plan pédagogique :",[49,372,373,379,385,391],{},[52,374,375,378],{},[19,376,377],{},"Apprentissage"," : on l'utilise souvent en cours d'algorithmique pour introduire les\nconcepts de tri. Sa simplicité aide les débutants à comprendre comment les algorithmes de\ntri fonctionnent.",[52,380,381,384],{},[19,382,383],{},"Petits jeux de données"," : si tu n'as que très peu d'éléments à trier, le tri à bulles\nreste acceptable — ses problèmes de performance ne se voient pas sur les petits tableaux.",[52,386,387,390],{},[19,388,389],{},"Données déjà presque triées"," : si tes données sont déjà majoritairement triées, le côté\nadaptatif du tri à bulles (il devient plus efficace avec peu d'échanges) peut convenir.",[52,392,393,396],{},[19,394,395],{},"Tremplin vers d'autres algorithmes"," : le tri à bulles est un bon point de départ avant\nd'attaquer des techniques plus complexes.",[15,398,399,400,403],{},"Pour la majorité des cas réels — surtout sur de grandes données — on préfère Quick Sort, Merge\nSort, ou les fonctions de tri intégrées au langage (par ex. ",[185,401,402],{},"sorted()"," en Python). Elles offrent\ndes performances bien supérieures et sont mieux adaptées aux applications où la performance compte.",[10,405,407],{"id":406},"conclusion","Conclusion",[15,409,410],{},"Le tri à bulles est un algorithme de tri basique, fondation pour comprendre les méthodes plus\ncomplexes. Ce n'est pas le plus efficace sur les grandes données, mais c'est un excellent point\nde départ pour apprendre les principes du tri et de l'optimisation d'algorithmes. Plus tu\nplonges dans l'informatique, plus tu rencontres d'algorithmes avancés aux meilleures\nperformances.",[15,412,413],{},"Comprendre le tri à bulles, c'est comme apprendre à faire du vélo avant de passer à la moto.\nÇa t'équipe d'intuitions précieuses sur les techniques de tri qui te resserviront quand tu\nexploreras des algorithmes plus sophistiqués.",[415,416,417],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":183,"searchDepth":197,"depth":197,"links":419},[420,421,422,426,427,428],{"id":12,"depth":197,"text":13},{"id":25,"depth":197,"text":26},{"id":35,"depth":197,"text":36,"children":423},[424,425],{"id":43,"depth":204,"text":44},{"id":108,"depth":204,"text":109},{"id":171,"depth":197,"text":172},{"id":366,"depth":197,"text":367},{"id":406,"depth":197,"text":407},"2023-08-09","Plonge dans les fondamentaux de l'algorithme de tri à bulles en Python et découvre une approche directe du tri. Cet article t'accompagne dans le fonctionnement interne du bubble sort, présente des exemples de code concrets et met en lumière ses forces et ses limites en pratique.","md","https:\u002F\u002Fres.cloudinary.com\u002Fdpdwhd6ka\u002Fimage\u002Fupload\u002Fv1691549735\u002FBlog\u002Farticles\u002Falgorithms\u002Frxgsxwomtoonomowq7s.svg",{},"\u002Fdsa\u002Fbuble-sort.fr",{"title":5,"description":430},"understanding-and-implementing-the-bubble-sort-algorithm","1.dsa\u002F1.buble-sort.fr",[439],"Algorithms",[441],"dsa","9NVYYxW1ogLg4f0H-JZ74vc2Y1RlxT7AUbbny3f-P7M",{"id":444,"title":445,"body":446,"date":429,"description":800,"extension":431,"img":432,"meta":801,"navigation":200,"path":802,"seo":803,"slug":436,"stem":804,"tags":805,"topics":806,"__hash__":807},"content\u002F1.dsa\u002F1.buble-sort.md","Bubble Sort Unveiled: Sorting Simplified with Python",{"type":7,"value":447,"toc":789},[448,450,453,457,460,463,467,470,474,477,522,529,535,539,542,545,595,598,602,605,713,723,740,743,747,750,776,779,781,784,787],[10,449,13],{"id":12},[15,451,452],{},"Sorting is a fundamental operation in computer science, and there are various algorithms to accomplish this task. One of\nthe simplest sorting algorithms is the Bubble Sort. While not the most efficient for large datasets, understanding\nBubble Sort can be a great way to grasp the basic principles of sorting algorithms. In this post, we'll explore what\nBubble Sort is and how to implement it in Python.",[10,454,456],{"id":455},"what-is-bubble-sort","What is Bubble sort",[15,458,459],{},"Bubble Sort is a comparison-based sorting algorithm that repeatedly steps through the list to be sorted. It compares\nadjacent elements and swaps them if they are in the wrong order. The algorithm continues iterating through the list\nuntil no more swaps are needed, indicating that the list is now sorted.",[15,461,462],{},"The main idea behind Bubble Sort is that larger elements \"bubble up\" to the end of the list, while smaller elements\n\"sink\" to the beginning.",[10,464,466],{"id":465},"how-bubble-sort-works","How Bubble Sort Works",[15,468,469],{},"Let's have two versions: for a child and for adults",[41,471,473],{"id":472},"for-a-child","For a child",[15,475,476],{},"Imagine you have a bunch of colorful balls, and you want to arrange them in order from the\nlightest to the heaviest. The Bubble Sort method is a way to do this. Here's how it works:",[49,478,479,490,508,519],{},[52,480,481,482],{},"Comparing and swapping balls",[56,483,484,487],{},[52,485,486],{},"You start by looking at the first two balls. If the first ball is heavier than the second one,\nyou swap them. So now, the heaviest ball comes after the lighter ball.",[52,488,489],{},"You move on to the next pair of balls and do the same thing. Keep doing this for all the pairs\nof balls in your collection.",[52,491,492,493],{},"One round of comparing and swapping",[56,494,495,502,505],{},[52,496,497,498,501],{},"After you've gone through all the pairs, you'll notice that the heaviest balls have ",[19,499,500],{},"bubbled up","\nto the end of the row",[52,503,504],{},"Now, you don't touch the heaviest ball anymore, because it's in the right place.",[52,506,507],{},"You start over again but only look at the balls before the heaviest ball. You compare and\nswap them if needed",[52,509,510,511],{},"Repeating until sorted",[56,512,513,516],{},[52,514,515],{},"You keep doing these rounds of comparing and swapping, but each time, you focus on the fewer and fewer\nballs because the heaviest ones are already in place.",[52,517,518],{},"You repeat this process until no more swaps are needed in a round. This means the balls are all in order,\njust like you wanted!!!",[52,520,521],{},"Bubble Sort is like bubble rising",[15,523,524,525,528],{},"The reason it's called ",[19,526,527],{},"Bubble Sort"," is that it's like bubbles rising in a fizzy drink. The biggest bubbles\nrise to the top first, then the smaller ones follow.",[15,530,531,532,534],{},"So on simple words, ",[19,533,527],{}," is like arranging colorful balls by looking at pairs of balls and swapping\nthem if they're in the wrong order. You repeat thus until the balls are lined up from lightest to heaviest,\njust like the bubbles in your drink.",[41,536,538],{"id":537},"for-an-adult","For an adult",[15,540,541],{},"Bubble Sort is a simple sorting algorithm that works by repeatedly stepping through a list of elements (like numbers or\nwords), comparing each pair of adjacent items, and swapping them if they're in the wrong order. The pass through the\nlist is repeated for as many times as there are elements in the list. The algorithm gets its name because the smaller\nelements \"bubble\" to the top of the list like air bubbles in water, while the larger elements \"sink\" to the bottom.",[15,543,544],{},"Let's break this into more understandable words",[49,546,547,553,567,578,584],{},[52,548,549,550,552],{},"Comparison and swapping",[97,551],{},"The algorithm starts by comparing the first two elements in the list. If the first element is greater than the\nsecond, it swaps them. This process continues for every adjacent pair of elements in the list.",[52,554,555,556],{},"One pass through the list",[56,557,558,564],{},[52,559,560,561,563],{},"After this first pass through the list, the largest element has ",[19,562,500],{}," to the last position.",[52,565,566],{},"The algorithm then performs the same comparison and swapping process for the remaining elements in the list,\nexcluding the last one.",[52,568,569,570],{},"Repeat until sorted",[56,571,572,575],{},[52,573,574],{},"The algorithm keeps repeating these passes through the list until no more swaps are needed. This means that all\nelements are in their correct sorted positions.",[52,576,577],{},"During each pass, smaller elements \"bubble up\" to their appropriate positions.",[52,579,580,581,583],{},"Optimization",[97,582],{},"A small optimization can be applied by introducing a flag that keeps track of whether any swaps were made during a\npass. If no swaps were made, it means the list is already sorted, and the algorithm can stop early.",[52,585,586,587],{},"Time Complexity",[56,588,589,592],{},[52,590,591],{},"In the worst case, Bubble Sort requires n passes through the list, where n is the number of elements. For each\npass,\nit compares and possibly swaps adjacent elements.",[52,593,594],{},"This results in a time complexity of O(n^2), which means the algorithm's performance becomes slow for large lists.",[15,596,597],{},"In summary, while Bubble Sort is conceptually simple and easy to understand, it's not very efficient for large\ndatasets due to its quadratic time complexity. It's mainly used for educational purposes and understanding sorting\nconcepts. For practical applications, more advanced sorting algorithms like Quick Sort, Merge Sort, or built-in\nsorting functions in programming languages are preferred due to their better performance.",[10,599,601],{"id":600},"implementation-using-python","Implementation using Python",[15,603,604],{},"Here's a simple step-by-step implementation of the Bubble Sort algorithm in Python (Flagged Optimized Bubble Sort)\nwhich involves using a flag to determine whether any swaps were made during an iteration. If no swaps are made, the\nalgorithm knows that the array is already sorted and can terminate early.",[177,606,607],{"className":179,"code":180,"filename":181,"language":182,"meta":183,"style":183},[185,608,609,613,617,621,625,629,633,637,641,645,649,653,657,661,665,669,673,677,681,685,689,693,697,701,705,709],{"__ignoreMap":183},[188,610,611],{"class":190,"line":191},[188,612,194],{},[188,614,615],{"class":190,"line":197},[188,616,201],{"emptyLinePlaceholder":200},[188,618,619],{"class":190,"line":204},[188,620,207],{},[188,622,623],{"class":190,"line":210},[188,624,213],{},[188,626,627],{"class":190,"line":216},[188,628,201],{"emptyLinePlaceholder":200},[188,630,631],{"class":190,"line":221},[188,632,224],{},[188,634,635],{"class":190,"line":227},[188,636,230],{},[188,638,639],{"class":190,"line":233},[188,640,236],{},[188,642,643],{"class":190,"line":239},[188,644,242],{},[188,646,647],{"class":190,"line":245},[188,648,248],{},[188,650,651],{"class":190,"line":251},[188,652,254],{},[188,654,655],{"class":190,"line":257},[188,656,260],{},[188,658,659],{"class":190,"line":263},[188,660,266],{},[188,662,663],{"class":190,"line":269},[188,664,201],{"emptyLinePlaceholder":200},[188,666,667],{"class":190,"line":274},[188,668,277],{},[188,670,671],{"class":190,"line":280},[188,672,201],{"emptyLinePlaceholder":200},[188,674,675],{"class":190,"line":285},[188,676,288],{},[188,678,679],{"class":190,"line":291},[188,680,294],{},[188,682,683],{"class":190,"line":297},[188,684,300],{},[188,686,687],{"class":190,"line":303},[188,688,306],{},[188,690,691],{"class":190,"line":309},[188,692,201],{"emptyLinePlaceholder":200},[188,694,695],{"class":190,"line":314},[188,696,317],{},[188,698,699],{"class":190,"line":320},[188,700,323],{},[188,702,703],{"class":190,"line":326},[188,704,201],{"emptyLinePlaceholder":200},[188,706,707],{"class":190,"line":331},[188,708,334],{},[188,710,711],{"class":190,"line":337},[188,712,340],{},[15,714,715,716,718,719,722],{},"This implementation of ",[19,717,527],{}," with The ",[19,720,721],{},"Flagged Optimized Bubble Sort"," approach can be summarized as follows:",[49,724,725,728,731,734,737],{},[52,726,727],{},"Start by assuming that a swap has not occurred during the current iteration.",[52,729,730],{},"Traverse the array, comparing adjacent elements.",[52,732,733],{},"If an element on the left is greater than the element on the right, swap them and set the flag to indicate that a\nswap occurred.",[52,735,736],{},"After completing the inner loop for one full iteration, check if the flag is still false. If it is, the array is\nalready sorted, and the algorithm can terminate early.",[52,738,739],{},"Repeat steps 2 to 4 until no more swaps are made in a complete iteration.",[15,741,742],{},"This optimized approach will potentially reduce the number of iterations and comparisons in cases where the array is\nalready sorted or nearly sorted, making the Bubble Sort algorithm slightly more efficient.",[10,744,746],{"id":745},"bubble-sort-in-real-world-applications","Bubble Sort in real world applications",[15,748,749],{},"In the real world, Bubble Sort is rarely used for practical applications due to its inefficiency compared to other\nsorting algorithms. However, it still has some limited use cases and can be valuable for educational purposes. Here are\na few scenarios where Bubble Sort might be used:",[49,751,752,758,764,770],{},[52,753,754,757],{},[19,755,756],{},"Educational Purposes",": Bubble Sort is often used in programming courses to teach basic sorting concepts. Its\nsimple\nimplementation helps beginners understand how sorting algorithms work.",[52,759,760,763],{},[19,761,762],{},"Small Datasets",": If you have a very small number of items to sort, Bubble Sort might be acceptable since its\nperformance issues are not as pronounced with small data sets.",[52,765,766,769],{},[19,767,768],{},"Already Partially Sorted Data",": If you're dealing with data that is already mostly sorted, Bubble Sort's adaptive\nnature (it becomes more efficient with fewer swaps as it progresses) might make it a viable choice.",[52,771,772,775],{},[19,773,774],{},"Learning Algorithms",": Bubble Sort can be used as a stepping stone to learn about other, more efficient sorting\nalgorithms. It's a good starting point before moving on to more complex techniques.",[15,777,778],{},"However, for the most practical scenarios, especially those involving larger data sets, you would prefer more efficient\nsorting algorithms like Quick Sort, Merge Sort,\nor the built-in sorting functions provided by programming languages (e.g., sorted() in Python).\nThese algorithms offer significantly better performance and are better suited for real-world\napplications where efficiency matters.",[10,780,407],{"id":406},[15,782,783],{},"Bubble Sort is a basic sorting algorithm that serves as a foundation for understanding more complex sorting methods.\nWhile it's not the most efficient algorithm for large datasets, it's a great starting point to learn about the\nprinciples of sorting and algorithm optimization. As you delve further into the world of computer science, you'll\nencounter more advanced sorting algorithms that offer better performance.",[15,785,786],{},"Remember, understanding Bubble Sort is like learning to ride a bicycle before moving on to a motorbike. It equips you\nwith valuable insights into sorting techniques that will be useful when exploring more sophisticated algorithms.",[415,788,417],{},{"title":183,"searchDepth":197,"depth":197,"links":790},[791,792,793,797,798,799],{"id":12,"depth":197,"text":13},{"id":455,"depth":197,"text":456},{"id":465,"depth":197,"text":466,"children":794},[795,796],{"id":472,"depth":204,"text":473},{"id":537,"depth":204,"text":538},{"id":600,"depth":197,"text":601},{"id":745,"depth":197,"text":746},{"id":406,"depth":197,"text":407},"Dive into the fundamentals of the bubble sort algorithm in Python and unravel a straightforward approach to sorting. This post guides you through the inner workings of bubble sort, showcases hands-on code examples, and highlights its strengths and limitations for practical use.",{},"\u002Fdsa\u002Fbuble-sort",{"title":445,"description":800},"1.dsa\u002F1.buble-sort",[439],[441],"s-uEdyITTzRFbe5XMIAZSiCKkzDf23Ddt3jgqSfke1o",[809,810],null,{"title":811,"path":812},"Trier des listes efficacement : maîtriser l'algorithme de tri par insertion en Python","\u002Fdsa\u002Finsertion-sort.fr",[814,819],{"path":812,"title":811,"description":815,"date":816,"tags":817,"topics":818},"Découvre la puissance de l'algorithme de tri par insertion en Python et apprends à trier des listes efficacement pour une meilleure organisation des données. Implémentation pas à pas, exemples pratiques, et astuces pour optimiser la performance.","2023-07-06",[439],[441],{"path":820,"title":821,"description":822,"date":816,"tags":823,"topics":824},"\u002Fdsa\u002Fquick-sort.fr","Maîtriser l'algorithme Quick Sort en Python : un guide complet","Plonge dans le monde des algorithmes de tri avec notre guide approfondi sur le Quick Sort en Python. Apprends le fonctionnement interne de cette technique de tri efficace, pas à pas. Stratégies d'implémentation, bonnes pratiques, et astuces d'optimisation pour intégrer ça facilement dans tes projets.",[439],[441],1780074488614]