{"id":8719,"date":"2022-06-29T12:30:09","date_gmt":"2022-06-29T12:30:09","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=8719"},"modified":"2022-07-20T10:22:13","modified_gmt":"2022-07-20T10:22:13","slug":"k-ary-heap","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/","title":{"rendered":"K-ary heap"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\" alt=\"\" \/><\/p>\n<p>K-ary heaps are similar to the binary heap (where K = 2) just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.<\/p>\n<p>It follows the following 2 properties:<\/p>\n<ol>\n<li>It is nearly like a complete binary tree, i.e. all the levels are having maximum number of nodes except the last level, which is filled from left to right.<\/li>\n<li>Just like a binary heap, it is further categorized into two types:\n<ul>\n<li>Max K &#8211; ary heap (Value of node at root is greater than its left and right child nodes).<\/li>\n<li>Min K &#8211; ary heap (Value of node at root is smaller than its left and right child nodes).<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505727563-Image-01%20%281%29.png\" alt=\"\" \/><\/p>\n<h3>Applications of k-ary Heap:<\/h3>\n<ul>\n<li>In the implementation of a priority queue, the k-ary heap (O(log<sub>k<\/sub>n)) is faster for decreasing key operations as compared to the binary heap(O(log<sub>2<\/sub>n)). But it increases the complexity of the extractMin() operation from (O(logkn)) when the binary heap is used to (O(klog<sub>k<\/sub>n)) when the k-ary heap is used for the priority queue. So, it will be more efficient for using the k-ary heap where a decreased priority queue is used. For example, Prim\u2019s algorithm for minimum spanning tree.<\/li>\n<li>K-ary heap has better handling for the memory cache behavior than the binary heap which allows running more quickly in practice although it is having a bigger worst-case time complexity of both extractMin() and delete() operation (both being (O(klog<sub>k<\/sub>n))).<\/li>\n<\/ul>\n<h3>Implementation<\/h3>\n<p>Consider 0-based indexing in the array, the array will represent a K-ary heap such that for any node:<\/p>\n<ul>\n<li>Parent of the node which is at index i is located at index (i-1)\/k.<\/li>\n<li>Child nodes of index i are at indices (k<em>i)+1, (k<\/em>i)+2\u2026.(k*i)+k.<\/li>\n<li>The last non-leaf node of the heap will be located at index (n-2)\/k.<\/li>\n<\/ul>\n<p><strong>buildHeap():<\/strong> This function is used for building the heap.<br \/>\nIn this function, iteration will be started from the last non-leaf node to the root node, and for each iteration restoreDown (or maxHeapify) function will be called that will restore the passed index at the correct position of the heap by shifting the node down in the k-ary heap which is built in a bottom-up manner.<\/p>\n<p><strong>restoreDown() (or maxHeapify):<\/strong> This function is used to maintain the property of the heap.<br \/>\nIn this function, iteration will be done for finding the maximum from all the children nodes, compare the value of the maximum child node value with its own, and swap if the max(value of all children)&gt;(value at a node). This step will be repeated until the node is restored to its original position in the heap.<\/p>\n<p><strong>extractMax():<\/strong> This function is used for extracting the root node.<br \/>\nIn the max k-ary heap, the largest element is stored in the root. This function will return the root node, and copies the value of the last node to the first node, and calls the restore down function on the first node to maintain the property of the heap.<\/p>\n<p><strong>insert():<\/strong> This function is used to insert the node into the heap.<br \/>\nFirstly, the node will be inserted at the last position, then the restoreUp function will be called on the given index to restore the node to its proper position in the heap. restoreUp function will iteratively do a comparison between the given node with its parent, to maintain the property of max heap, the node is swapped with its parent when its value is greater than its parent.<\/p>\n<h4>Code Implementation<\/h4>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_8720 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_8720 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_8720 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_8720 .wpsm_nav-tabs > li.active > a, #tab_container_8720 .wpsm_nav-tabs > li.active > a:hover, #tab_container_8720 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_8720 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_8720 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_8720 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_8720 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_8720 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_8720 .wpsm_nav-tabs > li > a:hover , #tab_container_8720 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_8720 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_8720 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_8720 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_8720 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_8720 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_8720 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_8720 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8720 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_8720 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8720 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_8720 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_8720\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_8720\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_8720_1\" aria-controls=\"tabs_desc_8720_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_8720\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_8720_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;bits\/stdc++.h&gt;\r\n\r\nusing namespace std;\r\n\r\nvoid restoreDown(int arr[], int len, int index,\r\n\t\t\t\t\t\t\t\t\t\tint k)\r\n{\r\n\tint child[k+1];\r\n\r\n\twhile (1)\r\n\t{\r\n\t\tfor (int i=1; i&lt;=k; i++)\r\n\t\t\tchild[i] = ((k*index + i) &lt; len) ?\r\n\t\t\t\t\t(k*index + i) : -1;\r\n\r\n\t\tint max_child = -1, max_child_index ;\r\n\r\n\t\tfor (int i=1; i&lt;=k; i++)\r\n\t\t{\r\n\t\t\tif (child[i] != -1 &amp;&amp;\r\n\t\t\t\tarr[child[i]] &gt; max_child)\r\n\t\t\t{\r\n\t\t\t\tmax_child_index = child[i];\r\n\t\t\t\tmax_child = arr[child[i]];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (max_child == -1)\r\n\t\t\tbreak;\r\n\r\n\t\tif (arr[index] &lt; arr[max_child_index])\r\n\t\t\tswap(arr[index], arr[max_child_index]);\r\n\r\n\t\tindex = max_child_index;\r\n\t}\r\n}\r\n\r\nvoid restoreUp(int arr[], int index, int k)\r\n{\r\n\tint parent = (index-1)\/k;\r\n\twhile (parent&gt;=0)\r\n\t{\r\n\t\tif (arr[index] &gt; arr[parent])\r\n\t\t{\r\n\t\t\tswap(arr[index], arr[parent]);\r\n\t\t\tindex = parent;\r\n\t\t\tparent = (index -1)\/k;\r\n\t\t}\r\n\r\n\t\telse\r\n\t\t\tbreak;\r\n\t}\r\n}\r\n\r\nvoid buildHeap(int arr[], int n, int k)\r\n{\r\n\tfor (int i= (n-1)\/k; i&gt;=0; i--)\r\n\t\trestoreDown(arr, n, i, k);\r\n}\r\n\r\nvoid insert(int arr[], int* n, int k, int elem)\r\n{\r\n\tarr[*n] = elem;\r\n\t*n = *n+1;\r\n\r\n\trestoreUp(arr, *n-1, k);\r\n}\r\n\r\nint extractMax(int arr[], int* n, int k)\r\n{\r\n\r\n\tint max = arr[0];\r\n\r\n\tarr[0] = arr[*n-1];\r\n\t*n = *n-1;\r\n\trestoreDown(arr, *n, 0, k);\r\n\r\n\treturn max;\r\n}\r\n\r\nint main()\r\n{\r\n\tconst int capacity = 100;\r\n\tint arr[capacity] = {4, 5, 6, 7, 8, 9, 10};\r\n\tint n = 7;\r\n\tint k = 3;\r\n\r\n\tbuildHeap(arr, n, k);\r\n\r\n\tprintf(&quot;Built Heap : &#92;n&quot;);\r\n\tfor (int i=0; i&lt;n; i++)\r\n\t\tprintf(&quot;%d &quot;, arr[i]);\r\n\r\n\tint element = 3;\r\n\tinsert(arr, &amp;n, k, element);\r\n\r\n\tprintf(&quot;&#92;n&#92;nHeap after insertion of %d: &#92;n&quot;,\r\n\t\t\telement);\r\n\tfor (int i=0; i&lt;n; i++)\r\n\t\tprintf(&quot;%d &quot;, arr[i]);\r\n\r\n\tprintf(&quot;&#92;n&#92;nExtracted max is %d&quot;,\r\n\t\t\t\textractMax(arr, &amp;n, k));\r\n\r\n\tprintf(&quot;&#92;n&#92;nHeap after extract max: &#92;n&quot;);\r\n\tfor (int i=0; i&lt;n; i++)\r\n\t\tprintf(&quot;%d &quot;, arr[i]);\r\n\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_8720 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_8720 a\"),jQuery(\"#tab-content_8720\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output:<\/strong><br \/>\nBuilt Heap :<br \/>\n10 9 6 7 8 4 5 <\/p>\n<p>Heap after insertion of 3:<br \/>\n10 9 6 7 8 4 5 3 <\/p>\n<p>Extracted max is 10<\/p>\n<p>Heap after extract max:<br \/>\n9 8 6 7 3 4 5<\/p>\n<h4>Time Complexity Analysis<\/h4>\n<ul>\n<li>The time complexity for the buildHeap function is O(n) (similar to binary heap).<\/li>\n<li>The time complexity for the restoreDown function is O(klogkn)).<\/li>\n<li>The time complexity for the insert and decreaseKey function is O(logkn)).<\/li>\n<li>Since extractMax calls the restoreDown function, the time complexity will be O(klogkn)).<\/li>\n<li>In the k-ary heap, the maximum height will be logkn for n nodes present in it. Therefore, the restoreUp function will be called for  maximum logkn times(in each iteration, the node will move upward which is the case of restoreUp, or moves downward which is the case of restoreDown).<\/li>\n<\/ul>\n<p>This article tried to discuss <strong>K-ary heap<\/strong>. Hope this blog helps you understand the concept. To practice more problems feel free to check <a href=\"#\"><\/a> at  <a href=\"https:\/\/www.prepbytes.com\/\"> Prepbytes.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>K-ary heaps are similar to the binary heap (where K = 2) just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap. It follows the following 2 properties: It is nearly like a complete binary tree, i.e. all the levels are having maximum [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[131],"tags":[175],"class_list":["post-8719","post","type-post","status-publish","format-standard","hentry","category-heap","tag-heap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>K-ary heap | Heap | Prepbytes<\/title>\n<meta name=\"description\" content=\"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"K-ary heap | Heap | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-29T12:30:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-20T10:22:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"K-ary heap\",\"datePublished\":\"2022-06-29T12:30:09+00:00\",\"dateModified\":\"2022-07-20T10:22:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\"},\"wordCount\":731,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\",\"keywords\":[\"heap\"],\"articleSection\":[\"Heap\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\",\"name\":\"K-ary heap | Heap | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\",\"datePublished\":\"2022-06-29T12:30:09+00:00\",\"dateModified\":\"2022-07-20T10:22:13+00:00\",\"description\":\"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Heap\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/heap\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"K-ary heap\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"K-ary heap | Heap | Prepbytes","description":"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.","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:\/\/prepbytes.com\/blog\/k-ary-heap\/","og_locale":"en_US","og_type":"article","og_title":"K-ary heap | Heap | Prepbytes","og_description":"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.","og_url":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-06-29T12:30:09+00:00","article_modified_time":"2022-07-20T10:22:13+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"K-ary heap","datePublished":"2022-06-29T12:30:09+00:00","dateModified":"2022-07-20T10:22:13+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/"},"wordCount":731,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg","keywords":["heap"],"articleSection":["Heap"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/k-ary-heap\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/","url":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/","name":"K-ary heap | Heap | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg","datePublished":"2022-06-29T12:30:09+00:00","dateModified":"2022-07-20T10:22:13+00:00","description":"K-ary heaps are similar to the binary heap just having one difference that instead of 2 child nodes, there can be k child nodes for every node in the heap.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/k-ary-heap\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656505772241-Article%20%281%29.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/k-ary-heap\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Heap","item":"https:\/\/prepbytes.com\/blog\/category\/heap\/"},{"@type":"ListItem","position":3,"name":"K-ary heap"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=8719"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8719\/revisions"}],"predecessor-version":[{"id":8878,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8719\/revisions\/8878"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=8719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=8719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=8719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}