{"id":699,"date":"2023-04-27T17:48:30","date_gmt":"2023-04-27T17:48:30","guid":{"rendered":"https:\/\/www.programminginpython.com\/?p=699"},"modified":"2025-03-31T07:24:48","modified_gmt":"2025-03-31T07:24:48","slug":"heap-sort-algorithm-python","status":"publish","type":"post","link":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/","title":{"rendered":"Heap Sort Algorithm in Python"},"content":{"rendered":"<p>Hello Python enthusiasts, welcome back to <a href=\"\/\" target=\"_blank\" rel=\"noopener\">Programming In Python<\/a>. I am back with another sorting algorithm, here I will try to discuss on Heap Sort Algorithm in Python.<\/p>\n<h2>Introduction<\/h2>\n<p>Heap sort is an efficient sorting algorithm that works by first organizing the data to be sorted into a binary heap. Then, the root element of the heap is removed and placed at the end of the sorted array. The heap is then reconstructed with the remaining elements, and the process repeats until the heap is empty. In this tutorial, we&#8217;ll be implementing the Heap sort algorithm in Python.<\/p>\n<p class=\"extra_btn_para\"><span class=\"wdg\"> <a href=\"https:\/\/github.com\/avinashn\/programminginpython.com\/blob\/master\/Algorithms\/Sorting%20Algorithms\/heap_sort.py\" target=\"_blank\" rel=\"noopener noreferrer\"> <i class=\"fa fa-github fa-lg\"><\/i> Program on GitHub<\/a><\/span><\/p>\n<h2>Step 1: Understanding the Binary Heap<\/h2>\n<p>Before we can implement Heap sort, we need to understand what a binary heap is. A binary heap is a complete binary tree in which every parent node has two child nodes, and the key value of the parent node is less than or equal to the key values of its child nodes (in a &#8220;min heap&#8221;). The root node of the binary heap is the smallest element in the heap.<\/p>\n<p>To represent a binary heap in Python, we can use an array or a list. For example, the following list represents a binary heap:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">[4, 7, 9, 10, 8, 5, 1, 3, 2, 6]<\/code><\/p>\n<p>In this list, the root node is 4, and the child nodes are 7 and 9. The next level of nodes contains 10, 8, 5, and 1. And the final level contains 3, 2, and 6.<\/p>\n<figure id=\"attachment_706\" aria-describedby=\"caption-attachment-706\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-706 lazyload\" data-src=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_binary_tree.png\" alt=\"Initial Heap - Binary tree\" width=\"500\" height=\"500\" data-srcset=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_binary_tree.png 500w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_binary_tree.png 300w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_binary_tree.png 150w\" data-sizes=\"(max-width: 500px) 100vw, 500px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 500px; --smush-placeholder-aspect-ratio: 500\/500;\" \/><figcaption id=\"caption-attachment-706\" class=\"wp-caption-text\">Initial Heap &#8211; Binary tree<\/figcaption><\/figure>\n<h2>Step 2: Implementing the Heapify Function<\/h2>\n<p>The first step in implementing Heap sort is to write a function that &#8220;heapifies&#8221; a binary tree. The heapify function takes an array or list and an index as input, and it recursively swaps elements until the heap property is satisfied. Here&#8217;s an implementation of the heapify function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def heapify(arr, n, i):\r\n    largest = i  # Initialize largest as root\r\n    l = 2 * i + 1  # left = 2*i + 1\r\n    r = 2 * i + 2  # right = 2*i + 2\r\n \r\n    # See if left child of root exists and is greater than root\r\n    if l &lt; n and arr[i] &lt; arr[l]:\r\n        largest = l\r\n \r\n    # See if right child of root exists and is greater than root\r\n    if r &lt; n and arr[largest] &lt; arr[r]:\r\n        largest = r\r\n \r\n    # Change root, if needed\r\n    if largest != i:\r\n        arr[i], arr[largest] = arr[largest], arr[i]  # swap\r\n \r\n        # Heapify the root.\r\n        heapify(arr, n, largest)\r\n<\/pre>\n<p>Here, arr is the input array, n is the size of the heap, and i is the index of the root node. The function first initializes the largest variable to the index of the root node. It then calculates the indices of the left and right child nodes, and checks whether they are greater than the root node. If either child node is greater, the function swaps the root node with the larger child node, and recursively calls itself on the child node.<\/p>\n<blockquote><p>Ad:<br \/>\n<span style=\"font-size: 18pt;\">Python for Finance: Investment Fundamentals &amp; Data Analytics \u2013 <a href=\"https:\/\/bit.ly\/python-programming-masterclass\" target=\"_blank\" rel=\"noopener\">Enroll Now<\/a>.<\/span><br \/>\n<span style=\"font-size: 12px;\">Udemy<\/span><\/p><\/blockquote>\n<h2>Step 3: Implementing Heap Sort<\/h2>\n<p>Now that we have a function to heapify the binary tree, we can use it to implement Heap sort. Here&#8217;s an implementation of the Heap sort algorithm:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def heap_sort(arr):\r\n    n = len(arr)\r\n \r\n    # Build a maxheap.\r\n    for i in range(n \/\/ 2 - 1, -1, -1):\r\n        heapify(arr, n, i)\r\n \r\n    #\u00a0Extract\u00a0elements\u00a0one\u00a0by\u00a0one\r\n\u00a0\u00a0\u00a0\u00a0for\u00a0i\u00a0in\u00a0range(n-1,\u00a00,\u00a0-1):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0arr[i],\u00a0arr[0]\u00a0=\u00a0arr[0],\u00a0arr[i]\u00a0\u00a0#\u00a0swap\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0heapify(arr,\u00a0i,\u00a00)\r\n<\/pre>\n<p>Here, the function first initializes the n variable to the length of the input array. It then builds a max heap by calling the heapify function on the array in reverse order from the middle to the start. Finally, the function extracts elements from the max heap one by one and places them at the end of the sorted array, while maintaining the heap property.<\/p>\n<h2>Step 4: Testing the Implementation<\/h2>\n<p>Now that we&#8217;ve implemented Heap sort, let&#8217;s test it out on a sample array. Here&#8217;s a sample array we&#8217;ll use for testing:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">arr = [12, 11, 13, 5, 6, 7]<\/code><\/p>\n<p>To sort this array using Heap sort, we can simply call the <code>heap_sort<\/code> function on the array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">heap_sort(arr)\r\nprint(\"Sorted array is:\")\r\nprint(arr)<\/pre>\n<p>This should output the following sorted array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Sorted array is:\r\n[5, 6, 7, 11, 12, 13]<\/pre>\n<p class=\"extra_btn_para\"><span class=\"wdg\"> <a href=\"https:\/\/github.com\/avinashn\/programminginpython.com\/blob\/master\/Algorithms\/Sorting%20Algorithms\/heap_sort.py\" target=\"_blank\" rel=\"noopener noreferrer\"> <i class=\"fa fa-github fa-lg\"><\/i> Program on GitHub<\/a><\/span><\/p>\n<h2>Code Visualization<\/h2>\n<p><iframe src=\"https:\/\/pythontutor.com\/iframe-embed.html#code=def%20heapify%28arr,%20n,%20i%29%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20Heapify%20function%20to%20build%20a%20max%20heap%20from%20an%20unsorted%20array.%0A%20%20%20%20%22%22%22%0A%20%20%20%20largest%20%3D%20i%20%20%23%20Initialize%20largest%20as%20root%0A%20%20%20%20l%20%3D%202%20*%20i%20%2B%201%20%20%23%20left%20%3D%202*i%20%2B%201%0A%20%20%20%20r%20%3D%202%20*%20i%20%2B%202%20%20%23%20right%20%3D%202*i%20%2B%202%0A%0A%20%20%20%20%23%20See%20if%20left%20child%20of%20root%20exists%20and%20is%20greater%20than%20root%0A%20%20%20%20if%20l%20%3C%20n%20and%20arr%5Bl%5D%20%3E%20arr%5Blargest%5D%3A%0A%20%20%20%20%20%20%20%20largest%20%3D%20l%0A%0A%20%20%20%20%23%20See%20if%20right%20child%20of%20root%20exists%20and%20is%20greater%20than%20root%0A%20%20%20%20if%20r%20%3C%20n%20and%20arr%5Br%5D%20%3E%20arr%5Blargest%5D%3A%0A%20%20%20%20%20%20%20%20largest%20%3D%20r%0A%0A%20%20%20%20%23%20Change%20root,%20if%20needed%0A%20%20%20%20if%20largest%20!%3D%20i%3A%0A%20%20%20%20%20%20%20%20arr%5Bi%5D,%20arr%5Blargest%5D%20%3D%20arr%5Blargest%5D,%20arr%5Bi%5D%20%20%23%20swap%0A%0A%20%20%20%20%20%20%20%20%23%20Heapify%20the%20root.%0A%20%20%20%20%20%20%20%20heapify%28arr,%20n,%20largest%29%0A%0A%0Adef%20heap_sort%28arr%29%3A%0A%20%20%20%20%22%22%22%0A%20%20%20%20Heap%20sort%20function%20to%20sort%20an%20unsorted%20array%20in%20ascending%20order.%0A%20%20%20%20%22%22%22%0A%20%20%20%20n%20%3D%20len%28arr%29%0A%0A%20%20%20%20%23%20Build%20a%20max%20heap.%0A%20%20%20%20for%20i%20in%20range%28n%20\/\/%202%20-%201,%20-1,%20-1%29%3A%0A%20%20%20%20%20%20%20%20heapify%28arr,%20n,%20i%29%0A%0A%20%20%20%20%23%20Extract%20elements%20one%20by%20one%0A%20%20%20%20for%20i%20in%20range%28n-1,%200,%20-1%29%3A%0A%20%20%20%20%20%20%20%20arr%5Bi%5D,%20arr%5B0%5D%20%3D%20arr%5B0%5D,%20arr%5Bi%5D%20%20%23%20swap%0A%20%20%20%20%20%20%20%20heapify%28arr,%20i,%200%29%0A%0A%20%20%20%20%23%20Print%20the%20sorted%20list%0A%20%20%20%20print%28'%5CnThe%20sorted%20list%3A%20%5Ct',%20arr%29%0A%20%20%20%20print%28'%5Cn'%29%0A%0A%0Alst%20%3D%20%5B%5D%0Asize%20%3D%20int%28input%28%22%5CnEnter%20size%20of%20the%20list%3A%20%5Ct%22%29%29%0A%0Afor%20input_elements%20in%20range%28size%29%3A%0A%20%20%20%20elements%20%3D%20int%28input%28%22Enter%20the%20element%3A%20%5Ct%22%29%29%0A%20%20%20%20lst.append%28elements%29%0A%0Aheap_sort%28lst%29&amp;codeDivHeight=400&amp;codeDivWidth=350&amp;cumulative=false&amp;curInstr=0&amp;heapPrimitives=nevernest&amp;origin=opt-frontend.js&amp;py=3&amp;rawInputLstJSON=%5B%225%22,%2210%22,%2225%22,%2230%22,%227%22,%221%22%5D&amp;textReferences=false\" width=\"800\" height=\"500\" frameborder=\"0\"> <\/iframe><\/p>\n<h2>Heap Sort Algorithm in Python: Full Program<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def heapify(arr, n, i):\r\n    \"\"\"\r\n    Heapify function to build a max heap from an unsorted array.\r\n    \"\"\"\r\n    largest = i  # Initialize largest as root\r\n    l = 2 * i + 1  # left = 2*i + 1\r\n    r = 2 * i + 2  # right = 2*i + 2\r\n\r\n    # See if left child of root exists and is greater than root\r\n    if l &lt; n and arr[l] &gt; arr[largest]:\r\n        largest = l\r\n\r\n    # See if right child of root exists and is greater than root\r\n    if r &lt; n and arr[r] &gt; arr[largest]:\r\n        largest = r\r\n\r\n    # Change root, if needed\r\n    if largest != i:\r\n        arr[i], arr[largest] = arr[largest], arr[i]  # swap\r\n\r\n        # Heapify the root.\r\n        heapify(arr, n, largest)\r\n\r\n\r\ndef heap_sort(arr):\r\n    \"\"\"\r\n    Heap sort function to sort an unsorted array in ascending order.\r\n    \"\"\"\r\n    n = len(arr)\r\n\r\n    # Build a max heap.\r\n    for i in range(n \/\/ 2 - 1, -1, -1):\r\n        heapify(arr, n, i)\r\n\r\n    # Extract elements one by one\r\n    for i in range(n-1, 0, -1):\r\n        arr[i], arr[0] = arr[0], arr[i]  # swap\r\n        heapify(arr, i, 0)\r\n\r\n    # Print the sorted list\r\n    print('\\nThe sorted list: \\t', arr)\r\n    print('\\n')\r\n\r\n\r\nlst = []\r\nsize = int(input(\"\\nEnter size of the list: \\t\"))\r\n\r\nfor input_elements in range(size):\r\nelements = int(input(\"Enter the element: \\t\"))\r\nlst.append(elements)\r\n\r\nheap_sort(lst)\r\n<\/pre>\n<h2>Output<\/h2>\n<figure id=\"attachment_704\" aria-describedby=\"caption-attachment-704\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-704 size-large lazyload\" data-src=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_output-1024x512.png\" alt=\"Heap Sort Algorithm in Python\" width=\"640\" height=\"320\" data-srcset=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_output.png 1024w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_output.png 300w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_output.png 768w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/heap_sort_output.png 1200w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 640px; --smush-placeholder-aspect-ratio: 640\/320;\" \/><figcaption id=\"caption-attachment-704\" class=\"wp-caption-text\">Heap Sort Algorithm in Python<\/figcaption><\/figure>\n<blockquote><p>Ad:<br \/>\n<span style=\"font-size: 18pt;\">Python for Finance: Investment Fundamentals &amp; Data Analytics \u2013 <a href=\"https:\/\/bit.ly\/python-programming-masterclass\" target=\"_blank\" rel=\"noopener\">Enroll Now<\/a>.<\/span><br \/>\n<span style=\"font-size: 12px;\">Udemy<\/span><\/p><\/blockquote>\n<h2>Conclusion<\/h2>\n<p>Heap sort is an efficient sorting algorithm that works by organizing the data to be sorted into a binary heap, and then repeatedly extracting elements from the heap and placing them in the sorted array. In this tutorial, we&#8217;ve implemented Heap sort in Python by first writing a function to heapify a binary tree, and then using that function to implement Heap sort. We&#8217;ve also tested our implementation on a sample array and verified that it correctly sorts the array.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Python enthusiasts, welcome back to Programming In Python. I am back with another sorting algorithm, here I will try to discuss on Heap Sort Algorithm in Python. Introduction Heap sort is an efficient sorting algorithm that works by first organizing the data to be sorted into a binary heap. Then, the root element of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":700,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,9],"tags":[90,183,91],"class_list":["post-699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithms","category-sorting-algorithms","tag-algorithms","tag-heap-sort-algorithm","tag-sorting-algorithms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Heap Sort Algorithm in Python<\/title>\n<meta name=\"description\" content=\"Learn how to implement Heap sort algorithm in Python and efficiently sort your data. Follow this step-by-step tutorial with complete code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Heap Sort Algorithm in Python\" \/>\n<meta property=\"og:description\" content=\"Learn how to implement Heap sort algorithm in Python and efficiently sort your data. Follow this step-by-step tutorial with complete code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Programming In Python\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/programminginpython\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-27T17:48:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-31T07:24:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"AVINASH NETHALA\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@python_pip\" \/>\n<meta name=\"twitter:site\" content=\"@python_pip\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"AVINASH NETHALA\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Heap Sort Algorithm in Python","description":"Learn how to implement Heap sort algorithm in Python and efficiently sort your data. Follow this step-by-step tutorial with complete code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/","og_locale":"en_US","og_type":"article","og_title":"Heap Sort Algorithm in Python","og_description":"Learn how to implement Heap sort algorithm in Python and efficiently sort your data. Follow this step-by-step tutorial with complete code","og_url":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/","og_site_name":"Programming In Python","article_publisher":"https:\/\/www.facebook.com\/programminginpython","article_published_time":"2023-04-27T17:48:30+00:00","article_modified_time":"2025-03-31T07:24:48+00:00","og_image":[{"width":1200,"height":400,"url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","type":"image\/png"}],"author":"AVINASH NETHALA","twitter_card":"summary_large_image","twitter_creator":"@python_pip","twitter_site":"@python_pip","twitter_misc":{"Written by":"AVINASH NETHALA","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#article","isPartOf":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/"},"author":{"name":"AVINASH NETHALA","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/9a3c14fe46d422ebf783ee61de1e788c"},"headline":"Heap Sort Algorithm in Python","datePublished":"2023-04-27T17:48:30+00:00","dateModified":"2025-03-31T07:24:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/"},"wordCount":664,"commentCount":0,"publisher":{"@id":"https:\/\/www.programminginpython.com\/#organization"},"image":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","keywords":["algorithms","heap sort algorithm","sorting algorithms"],"articleSection":["Algorithms","Sorting Algorithms"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/","url":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/","name":"Heap Sort Algorithm in Python","isPartOf":{"@id":"https:\/\/www.programminginpython.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#primaryimage"},"image":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","datePublished":"2023-04-27T17:48:30+00:00","dateModified":"2025-03-31T07:24:48+00:00","description":"Learn how to implement Heap sort algorithm in Python and efficiently sort your data. Follow this step-by-step tutorial with complete code","breadcrumb":{"@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#primaryimage","url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","contentUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","width":1200,"height":400,"caption":"Heap Sort Algorithm in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.programminginpython.com\/heap-sort-algorithm-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.programminginpython.com\/"},{"@type":"ListItem","position":2,"name":"Heap Sort Algorithm in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.programminginpython.com\/#website","url":"https:\/\/www.programminginpython.com\/","name":"Programming In Python","description":"All About Python","publisher":{"@id":"https:\/\/www.programminginpython.com\/#organization"},"alternateName":"pip","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.programminginpython.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.programminginpython.com\/#organization","name":"Programming In Python","alternateName":"PIP","url":"https:\/\/www.programminginpython.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/pip_logo_500_500.png","contentUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/pip_logo_500_500.png","width":500,"height":500,"caption":"Programming In Python"},"image":{"@id":"https:\/\/www.programminginpython.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/programminginpython","https:\/\/x.com\/python_pip","https:\/\/www.youtube.com\/programminginpython","https:\/\/github.com\/avinashn\/programminginpython.com"]},{"@type":"Person","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/9a3c14fe46d422ebf783ee61de1e788c","name":"AVINASH NETHALA","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ed52e7670d7db94820c7430d324103ccdecb16d86611d5b29064aa9ce25a958b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed52e7670d7db94820c7430d324103ccdecb16d86611d5b29064aa9ce25a958b?s=96&d=mm&r=g","caption":"AVINASH NETHALA"},"sameAs":["https:\/\/www.programminginpython.com\/"],"url":"https:\/\/www.programminginpython.com\/author\/avinash\/"}]}},"jetpack_featured_media_url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/Heap-Sort-Algorithm-In-Python.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":9,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/699\/revisions\/1013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/media\/700"}],"wp:attachment":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}