{"id":6314,"date":"2019-12-21T16:11:38","date_gmt":"2019-12-21T16:11:38","guid":{"rendered":"https:\/\/holypython.com\/?p=6314"},"modified":"2021-03-28T13:17:42","modified_gmt":"2021-03-28T13:17:42","slug":"bubble-sort-algorithm-python-code","status":"publish","type":"post","link":"https:\/\/holypython.com\/bubble-sort-algorithm-python-code\/","title":{"rendered":"Bubble Sort Algorithm (Python Code)"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"6314\" class=\"elementor elementor-6314\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4aa78c95 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4aa78c95\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5acbd18b\" data-id=\"5acbd18b\" data-element_type=\"column\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-6619ccd2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6619ccd2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-798ea2ce\" data-id=\"798ea2ce\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-63588234 elementor-view-default elementor-widget elementor-widget-icon\" data-id=\"63588234\" data-element_type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<div class=\"elementor-icon\">\n\t\t\t<i aria-hidden=\"true\" class=\"fas fa-book-reader\"><\/i>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-inner-column elementor-element elementor-element-11c50a7b\" data-id=\"11c50a7b\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-71980e5e elementor-widget elementor-widget-heading\" data-id=\"71980e5e\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Algorithm: Bubble Sort<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-7f27e389 elementor-align-left elementor-icon-list--layout-traditional elementor-list-item-link-full_width elementor-widget elementor-widget-icon-list\" data-id=\"7f27e389\" data-element_type=\"widget\" data-widget_type=\"icon-list.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<ul class=\"elementor-icon-list-items\">\n\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item\">\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-icon\">\n\t\t\t\t\t\t\t<i aria-hidden=\"true\" class=\"fas fa-code\"><\/i>\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text\"><b>FUNCTION<\/b>: Sorting<\/span>\n\t\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item\">\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-icon\">\n\t\t\t\t\t\t\t<i aria-hidden=\"true\" class=\"fas fa-plane-departure\"><\/i>\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text\"><b>PERFORMANCE<\/b>:      <i>\u041e<\/i>(<i>n<\/i><sup>2<\/sup>)<\/span>\n\t\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item\">\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-icon\">\n\t\t\t\t\t\t\t<i aria-hidden=\"true\" class=\"fas fa-folder\"><\/i>\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text\"><b>DESIGN CATEGORY<\/b>: <\/span>\n\t\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item\">\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-icon\">\n\t\t\t\t\t\t\t<i aria-hidden=\"true\" class=\"far fa-clock\"><\/i>\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text\"><b>FOUNDED IN<\/b>: ~1955? (uncertain)<\/span>\n\t\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item\">\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-icon\">\n\t\t\t\t\t\t\t<i aria-hidden=\"true\" class=\"far fa-user-circle\"><\/i>\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text\"><b>FOUNDED BY<\/b>: Anonymous<\/span>\n\t\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t\t\t<\/ul>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-03e1ca6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"03e1ca6\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-78a86a6\" data-id=\"78a86a6\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-995d90b elementor-widget elementor-widget-text-editor\" data-id=\"995d90b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The way bubble sort works is it starts from the beginning and compares consecutive pairs with each other.<\/p>\n<p>When second number is smaller than the first number they will be swapped. This operation continues all the way to the end of the list causing the largest number to end up in the end.<\/p>\n<p>This iteration will continue until all the numbers are sorted.&nbsp;The name of the algorithm comes from the way it works as large numbers bubble to the end of the list similar to how bubbles bubble to the surface of the water.<\/p>\n<p>You can see a 10 step visual iteration showing how the algorithm swaps the pairs (when condition is satisfied).<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-fc7266a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fc7266a\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-dd9714a\" data-id=\"dd9714a\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-36bffc2 elementor-widget elementor-widget-heading\" data-id=\"36bffc2\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">STEP BY STEP<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-1d7e482 elementor-widget elementor-widget-image\" data-id=\"1d7e482\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"699\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2-1024x699.jpg\" class=\"attachment-large size-large wp-image-6706\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2-1024x699.jpg 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2-300x205.jpg 300w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2-768x524.jpg 768w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2-1536x1048.jpg 1536w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort-scheme2.jpg 1800w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Bubble Sort in 10 steps<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b0b0285 elementor-widget elementor-widget-text-editor\" data-id=\"b0b0285\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You can use the Python code below to create a bubble sort algorithm in your local environment. <code>yield<\/code> statement is used instead of <code>return<\/code> to create a generator so that the output is an iterable. (For visualization purposes.)<\/p><p>Bubble sort is not a very efficient sorting algorithm as it&#8217;s not suitable for large datasets nor reverse-ordered collections. It will usually perform slower than most of the other sorting algorithms. Only upper-hand of bubble sort is when the collection is already sorted it can be very efficient.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-b90baa6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b90baa6\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-8847df1\" data-id=\"8847df1\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-77e04c8 elementor-widget elementor-widget-heading\" data-id=\"77e04c8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">BUBBLE SORT ALGORITHM CODE IN PYTHON<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-7bf1d57 elementor-widget elementor-widget-html\" data-id=\"7bf1d57\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"PYTHON\"><code>#Bubble Sort Algorithm\r\n\r\ndef swap(A, p1, p2):\r\n    if p1 != p2:\r\n        A[p1], A[p2] = A[p2], A[p1]\r\n\r\ndef bubblesort(lst):\r\n    N = len(lst)\r\n    if N == 1:\r\n        return\r\n\r\n    for i in range(N - 1):     \r\n        for j in range(N-1-i):\r\n            if lst[j] > lst[j+1]:\r\n                swap(lst, j, j+1)             \r\n            yield lst\r\n<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-2201d07 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2201d07\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8e89550\" data-id=\"8e89550\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-6efc996 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6efc996\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-bf0cf25\" data-id=\"bf0cf25\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6077576 elementor-widget elementor-widget-heading\" data-id=\"6077576\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">BUBBLE SORT ALGORITHM VISUALIZATION<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-2a2bde7 elementor-widget elementor-widget-text-editor\" data-id=\"2a2bde7\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Matplotlib has a great class called animation which can be used to generate animations and live charts as below:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2823b46 elementor-widget elementor-widget-image\" data-id=\"2823b46\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"864\" height=\"648\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubblesort3.gif\" class=\"attachment-full size-full wp-image-6709\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">Bubble Sort Algorithm Visualization (17 items)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c95678 elementor-widget elementor-widget-text-editor\" data-id=\"8c95678\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here is the code to create a matplotlib animation based on the algorithm.<\/p><p>The code is a simplified version that was originally published in Najam Syed&#8217;s blog <a href=\"https:\/\/nrsyed.com\/2018\/09\/27\/visualizing-sorting-algorithms-and-time-complexity-with-matplotlib\/\">here.<\/a><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-261da1d elementor-widget elementor-widget-html\" data-id=\"261da1d\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<pre rel=\"PYTHON\"><code>#Visualization Code\r\n    \r\nimport random\r\nimport time\r\nimport matplotlib.pyplot as plt\r\nimport matplotlib.animation as animation\r\nfrom itertools import count\r\n\r\nif __name__ == \"__main__\":\r\n\r\n    N = 17\r\n    A = [x + 1 for x in range(N)]\r\n    random.seed(time.time())\r\n    random.shuffle(A)\r\n\r\n    figure, ax = plt.subplots(figsize=(12,9))\r\n    bar_list = ax.bar(range(len(A)), A, width=0.3, align=\"edge\", color=\"darkgreen\")\r\n    \r\n    index=count()\r\n    def update_figure(A, bars, iteration):\r\n        for bar, value in zip(bars, A):\r\n            bar.set_height(value)\r\n        \r\n    anim = animation.FuncAnimation(figure, func=update_figure,\r\n        fargs=(bar_list, next(index)), frames=bubblesort(A), interval=100,\r\n        repeat=False,save_count=150)\r\n    plt.show()<\/code><\/pre>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9d746ea elementor-widget elementor-widget-text-editor\" data-id=\"9d746ea\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>If you&#8217;re interested in saving your animation as a .gif or video file (such as: .mp4, .mov, .avi), you can check out the Matplotlib Animation saving tutorial <a href=\"https:\/\/holypython.com\/how-to-save-matplotlib-animations-the-ultimate-guide\/\">here<\/a>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5583d83 elementor-widget elementor-widget-image\" data-id=\"5583d83\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1024\" height=\"774\" src=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1-1024x774.png\" class=\"attachment-large size-large wp-image-6533\" alt=\"\" srcset=\"https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1-1024x774.png 1024w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1-300x227.png 300w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1-768x581.png 768w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1-1536x1161.png 1536w, https:\/\/holypython.com\/wp-content\/uploads\/2019\/12\/bubbleFigure_1.png 1566w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">List sorted with Bubble Sort Algorithm (55 items)<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9ed5d28 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9ed5d28\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2d50908\" data-id=\"2d50908\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-inner-section elementor-element elementor-element-e4a7300 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e4a7300\" data-element_type=\"section\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-inner-column elementor-element elementor-element-f9d9c2f\" data-id=\"f9d9c2f\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-42897eb elementor-widget elementor-widget-heading\" data-id=\"42897eb\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">HISTORY<\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<div class=\"elementor-element elementor-element-662a41e elementor-widget elementor-widget-text-editor\" data-id=\"662a41e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Fun Fact: <\/b><\/p><p>Former US President Barack Obama mentioned the shortcomings of Bubble Sort algorithm during an interview with the former Google CEO Eric Schmidt. You can watch the amusing interaction and President Obama&#8217;s answer below.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7461aba elementor-widget elementor-widget-video\" data-id=\"7461aba\" data-element_type=\"widget\" data-settings=\"{&quot;youtube_url&quot;:&quot;https:\\\/\\\/youtu.be\\\/m4yVlPqeZwo&quot;,&quot;start&quot;:1380,&quot;end&quot;:1440,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-wrapper elementor-open-inline\">\n\t\t\t<div class=\"elementor-video\"><\/div>\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ce6df0e elementor-widget elementor-widget-text-editor\" data-id=\"ce6df0e\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Epic exchange occurred on November 14, 2007 in Mountain View, California as<br \/>former Google CEO Eric Schmidth asks former US President Barack Obama the best way to sort 1M 32-bit integers to which he replies, probably not the bubble-sort!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Algorithm: Bubble Sort FUNCTION: Sorting PERFORMANCE: \u041e(n2) DESIGN CATEGORY: FOUNDED IN: ~1955? (uncertain) FOUNDED BY: Anonymous The way bubble sort works is it starts from the beginning and compares consecutive pairs with each other. When second number is smaller than the first number they will be swapped. This operation continues all the way to the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6533,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[45,50,46],"tags":[],"class_list":["post-6314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithms","category-divide-and-conquer","category-sorting"],"acf":[],"_links":{"self":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/6314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/comments?post=6314"}],"version-history":[{"count":0,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/posts\/6314\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media\/6533"}],"wp:attachment":[{"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/media?parent=6314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/categories?post=6314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/holypython.com\/wp-json\/wp\/v2\/tags?post=6314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}