{"id":8802,"date":"2022-06-29T11:20:02","date_gmt":"2022-06-29T11:20:02","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=8802"},"modified":"2022-07-20T09:43:41","modified_gmt":"2022-07-20T09:43:41","slug":"priority-queue-introduction","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/","title":{"rendered":"Priority Queue Introduction"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg\" alt=\"\" \/><\/p>\n<h3>Priority Queue:<\/h3>\n<p>Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The priority of the element determines the order in which elements are removed from the priority queue. In the priority queue, all the elements are arranged either in ascending order or descending order.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656499578545-Image-02.png\" alt=\"\" \/><\/p>\n<h3>Priority Queue Properties:<\/h3>\n<ul>\n<li>In the priority queue, every element has priority assigned to it.<\/li>\n<li>The element with highest priority first.<\/li>\n<li>If two elements are having the same priority then they are served according to their order in the queue.<\/li>\n<\/ul>\n<h3>Implementation of Priority queue:<\/h3>\n<p><strong>Priority queue is implemented in the following ways:<\/strong><\/p>\n<ul>\n<li>Using Arrays.<\/li>\n<li>Using Linked List<\/li>\n<li>Using Heap data structure<\/li>\n<li>Using Binary Search Tree<\/li>\n<\/ul>\n<h4>1. Priority Queue using array:<\/h4>\n<p>Simple structure to implement a priority queue.<br \/>\n<code>struct item {<\/code><br \/>\n<code>\tint item;<\/code><br \/>\n<code>\tint priority;<\/code><br \/>\n<code>}<\/code><\/p>\n<p><strong>Enqueue():<\/strong> This function is used to insert an element in the queue.<br \/>\n<strong>Dequeue():<\/strong> This function is used to remove an element from the queue.<br \/>\n<strong>peek():<\/strong> This function is used to get the highest priority element from the queue.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_8803 {\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_8803 .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_8803 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_8803 .wpsm_nav-tabs > li.active > a, #tab_container_8803 .wpsm_nav-tabs > li.active > a:hover, #tab_container_8803 .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_8803 .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_8803 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_8803 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_8803 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_8803 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_8803 .wpsm_nav-tabs > li > a:hover , #tab_container_8803 .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_8803 .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_8803 .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_8803 .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_8803 .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_8803 .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_8803 .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_8803 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8803 .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_8803 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8803 .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_8803 .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_8803\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_8803\">\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_8803_1\" aria-controls=\"tabs_desc_8803_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_8803\">\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_8803_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\nusing namespace std;\r\n \r\n\r\nstruct item {\r\n    int value;\r\n    int priority;\r\n};\r\n \r\nitem pr[100000];\r\n \r\nint size = -1;\r\n \r\nvoid enqueue(int value, int priority)\r\n{\r\n    size++;\r\n \r\n    \/\/ Insert the element\r\n    pr[size].value = value;\r\n    pr[size].priority = priority;\r\n}\r\n \r\nint peek()\r\n{\r\n    int highestPriority = INT_MIN;\r\n    int ind = -1;\r\n \r\n    for (int i = 0; i &lt;= size; i++) {\r\n \r\n       \r\n        if (highestPriority == pr[i].priority &amp;&amp; ind &gt; -1\r\n            &amp;&amp; pr[ind].value &lt; pr[i].value) {\r\n            highestPriority = pr[i].priority;\r\n            ind = i;\r\n        }\r\n        else if (highestPriority &lt; pr[i].priority) {\r\n            highestPriority = pr[i].priority;\r\n            ind = i;\r\n        }\r\n    }\r\n \r\n    return ind;\r\n}\r\n \r\nvoid dequeue()\r\n{\r\n    int ind = peek();\r\n \r\n    for (int i = ind; i &lt; size; i++) {\r\n        pr[i] = pr[i + 1];\r\n    }\r\n \r\n    size--;\r\n}\r\n \r\nint main()\r\n{\r\n    enqueue(20, 2);\r\n    enqueue(14, 4);\r\n    enqueue(160, 4);\r\n    enqueue(120, 3);\r\n \r\n    int ind = peek();\r\n \r\n    cout &lt;&lt; pr[ind].value &lt;&lt; endl;\r\n \r\n    \/\/ Dequeue the top element\r\n    dequeue();\r\n \r\n    \/\/ Check the top element\r\n    ind = peek();\r\n    cout &lt;&lt; pr[ind].value &lt;&lt; endl;\r\n \r\n    \/\/ Dequeue the top element\r\n    dequeue();\r\n \r\n    \/\/ Check the top element\r\n    ind = peek();\r\n    cout &lt;&lt; pr[ind].value &lt;&lt; endl;\r\n \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_8803 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_8803 a\"),jQuery(\"#tab-content_8803\"));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>Time Complexity:<\/strong><br \/>\nEnqueue: O(1)<br \/>\nDequeue: O(N)<br \/>\nPeek: O(N)<\/p>\n<h4>2. Priority queue using Linked List:<\/h4>\n<p>In linked List, the elements are sorted in the descending order according to their priority, the element with the highest priority are added to the front of the priority queue that is formed using linked list.<\/p>\n<p><strong>Enqueue():<\/strong> This function is used to insert an element in the queue.<br \/>\n<strong>Dequeue():<\/strong> This function is used to remove an element from the queue.<br \/>\n<strong>peek():<\/strong> This function is used to get the highest priority element from the queue.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_8804 {\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_8804 .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_8804 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_8804 .wpsm_nav-tabs > li.active > a, #tab_container_8804 .wpsm_nav-tabs > li.active > a:hover, #tab_container_8804 .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_8804 .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_8804 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_8804 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_8804 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_8804 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_8804 .wpsm_nav-tabs > li > a:hover , #tab_container_8804 .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_8804 .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_8804 .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_8804 .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_8804 .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_8804 .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_8804 .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_8804 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8804 .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_8804 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8804 .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_8804 .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_8804\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_8804\">\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_8804_1\" aria-controls=\"tabs_desc_8804_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_8804\">\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_8804_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\r\n#include &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\ntypedef struct node {\r\n\tint data;\r\n\r\n\tint priority;\r\n\r\n\tstruct node* next;\r\n\r\n} Node;\r\n\r\nNode* newNode(int d, int p)\r\n{\r\n\tNode* temp = (Node*)malloc(sizeof(Node));\r\n\ttemp-&gt;data = d;\r\n\ttemp-&gt;priority = p;\r\n\ttemp-&gt;next = NULL;\r\n\r\n\treturn temp;\r\n}\r\n\r\nint peek(Node** head) { return (*head)-&gt;data; }\r\n\r\n\r\nvoid pop(Node** head)\r\n{\r\n\tNode* temp = *head;\r\n\t(*head) = (*head)-&gt;next;\r\n\tfree(temp);\r\n}\r\n\r\nvoid push(Node** head, int d, int p)\r\n{\r\n\tNode* start = (*head);\r\n\r\n\tNode* temp = newNode(d, p);\r\n\r\n\tif ((*head)-&gt;priority &gt; p) {\r\n\r\n\t\ttemp-&gt;next = *head;\r\n\t\t(*head) = temp;\r\n\t}\r\n\telse {\r\n\r\n\t\twhile (start-&gt;next != NULL\r\n\t\t\t&amp;&amp; start-&gt;next-&gt;priority &lt; p) {\r\n\t\t\tstart = start-&gt;next;\r\n\t\t}\r\n\r\n\t\ttemp-&gt;next = start-&gt;next;\r\n\t\tstart-&gt;next = temp;\r\n\t}\r\n}\r\n\r\nint isEmpty(Node** head) { return (*head) == NULL; }\r\n\r\nint main()\r\n{\r\n\r\n\t\/\/ Create a Priority Queue\r\n\t\/\/ 10-&gt;20-&gt;30-&gt;40\r\n\tNode* pq = newNode(20, 1);\r\n\tpush(&amp;pq, 30, 2);\r\n\tpush(&amp;pq, 40, 3);\r\n\tpush(&amp;pq, 10, 0);\r\n\r\n\twhile (!isEmpty(&amp;pq)) {\r\n\t\tcout &lt;&lt; &quot; &quot; &lt;&lt; peek(&amp;pq);\r\n\t\tpop(&amp;pq);\r\n\t}\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_8804 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_8804 a\"),jQuery(\"#tab-content_8804\"));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>Time Complexity:<\/strong><br \/>\nEnqueue: O(N)<br \/>\nDequeue: O(1)<br \/>\nPeek: O(1)<\/p>\n<h4>3. Priority queue using binary heap:<\/h4>\n<p>Generally, Binary heaps are preferred for the implementation of priority queue because heaps provide better performance as compared to arrays or linked lists.<\/p>\n<p><strong>Operations of Binary heaps are:<\/strong><\/p>\n<p><strong>Insert():<\/strong> This function is used to insert an element into the priority queue.<\/p>\n<p><strong>remove():<\/strong> This function is used to remove the element from the priority queue.<\/p>\n<p><strong>extractMax():<\/strong> This function is used to extract the element with the highest priority.<\/p>\n<p><strong>getmax():<\/strong> This function is used to return the maximum priority element.<\/p>\n<p><strong>ChangePriority():<\/strong> This function is used to change the priority of the element.<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_8805 {\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_8805 .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_8805 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_8805 .wpsm_nav-tabs > li.active > a, #tab_container_8805 .wpsm_nav-tabs > li.active > a:hover, #tab_container_8805 .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_8805 .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_8805 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_8805 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_8805 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_8805 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_8805 .wpsm_nav-tabs > li > a:hover , #tab_container_8805 .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_8805 .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_8805 .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_8805 .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_8805 .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_8805 .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_8805 .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_8805 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8805 .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_8805 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_8805 .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_8805 .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_8805\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_8805\">\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_8805_1\" aria-controls=\"tabs_desc_8805_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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_8805_2\" aria-controls=\"tabs_desc_8805_2\" 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>Java<\/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\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_8805_3\" aria-controls=\"tabs_desc_8805_3\" 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>Python<\/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_8805\">\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_8805_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\r\n\r\n#include &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\nint H[50];\r\nint size = -1;\r\n\r\n\r\nint parent(int i)\r\n{\r\n\r\n\treturn (i - 1) \/ 2;\r\n}\r\n\r\nint leftChild(int i)\r\n{\r\n\r\n\treturn ((2 * i) + 1);\r\n}\r\n\r\nint rightChild(int i)\r\n{\r\n\r\n\treturn ((2 * i) + 2);\r\n}\r\n\r\nvoid shiftUp(int i)\r\n{\r\n\twhile (i &gt; 0 &amp;&amp; H[parent(i)] &lt; H[i]) {\r\n\r\n\t\r\n\t\tswap(H[parent(i)], H[i]);\r\n\r\n\t\r\n\t\ti = parent(i);\r\n\t}\r\n}\r\n\r\nvoid shiftDown(int i)\r\n{\r\n\tint maxIndex = i;\r\n\r\n\t\/\/ Left Child\r\n\tint l = leftChild(i);\r\n\r\n\tif (l &lt;= size &amp;&amp; H[l] &gt; H[maxIndex]) {\r\n\t\tmaxIndex = l;\r\n\t}\r\n\r\n\t\/\/ Right Child\r\n\tint r = rightChild(i);\r\n\r\n\tif (r &lt;= size &amp;&amp; H[r] &gt; H[maxIndex]) {\r\n\t\tmaxIndex = r;\r\n\t}\r\n\r\n\tif (i != maxIndex) {\r\n\t\tswap(H[i], H[maxIndex]);\r\n\t\tshiftDown(maxIndex);\r\n\t}\r\n}\r\n\r\nvoid insert(int p)\r\n{\r\n\tsize = size + 1;\r\n\tH[size] = p;\r\n\r\n\tshiftUp(size);\r\n}\r\n\r\nint extractMax()\r\n{\r\n\tint result = H[0];\r\n\r\n\tH[0] = H[size];\r\n\tsize = size - 1;\r\n\r\n\tshiftDown(0);\r\n\treturn result;\r\n}\r\n\r\nvoid changePriority(int i, int p)\r\n{\r\n\tint oldp = H[i];\r\n\tH[i] = p;\r\n\r\n\tif (p &gt; oldp) {\r\n\t\tshiftUp(i);\r\n\t}\r\n\telse {\r\n\t\tshiftDown(i);\r\n\t}\r\n}\r\n\r\n\r\nint getMax()\r\n{\r\n\r\n\treturn H[0];\r\n}\r\n\r\nvoid remove(int i)\r\n{\r\n\tH[i] = getMax() + 1;\r\n\r\n\t\r\n\tshiftUp(i);\r\n\r\n\textractMax();\r\n}\r\n\r\nint main()\r\n{\r\n\r\n\t\/*\t\t 45\r\n\t\t\t\/\t &#92;\r\n\t\t31\t 14\r\n\t\t\/ &#92; \/ &#92;\r\n\t\t13 20 7 11\r\n\t\t\/ &#92;\r\n\t12 7\r\n\tCreate a priority queue shown in\r\n\texample in a binary max heap form.\r\n\tQueue will be represented in the\r\n\tform of array as:\r\n\t45 31 14 13 20 7 11 12 7 *\/\r\n\r\n\t\/\/ Insert the element to the\r\n\t\/\/ priority queue\r\n\tinsert(55);\r\n\tinsert(20);\r\n\tinsert(14);\r\n\tinsert(12);\r\n\tinsert(31);\r\n\tinsert(7);\r\n\tinsert(11);\r\n\tinsert(13);\r\n\tinsert(7);\r\n\r\n\tint i = 0;\r\n\r\n\t\/\/ Priority queue before extracting max\r\n\tcout &lt;&lt; &quot;Priority Queue : &quot;;\r\n\twhile (i &lt;= size) {\r\n\t\tcout &lt;&lt; H[i] &lt;&lt; &quot; &quot;;\r\n\t\ti++;\r\n\t}\r\n\r\n\tcout &lt;&lt; &quot;&#92;n&quot;;\r\n\r\n\t\/\/ Node with maximum priority\r\n\tcout &lt;&lt; &quot;Node with maximum priority : &quot;\r\n\t\t&lt;&lt; extractMax() &lt;&lt; &quot;&#92;n&quot;;\r\n\r\n\t\/\/ Priority queue after extracting max\r\n\tcout &lt;&lt; &quot;Priority queue after &quot;\r\n\t\t&lt;&lt; &quot;extracting maximum : &quot;;\r\n\tint j = 0;\r\n\twhile (j &lt;= size) {\r\n\t\tcout &lt;&lt; H[j] &lt;&lt; &quot; &quot;;\r\n\t\tj++;\r\n\t}\r\n\r\n\tcout &lt;&lt; &quot;&#92;n&quot;;\r\n\r\n\t\/\/ Change the priority of element\r\n\t\/\/ present at index 2 to 49\r\n\tchangePriority(2, 49);\r\n\tcout &lt;&lt; &quot;Priority queue after &quot;\r\n\t\t&lt;&lt; &quot;priority change : &quot;;\r\n\tint k = 0;\r\n\twhile (k &lt;= size) {\r\n\t\tcout &lt;&lt; H[k] &lt;&lt; &quot; &quot;;\r\n\t\tk++;\r\n\t}\r\n\r\n\tcout &lt;&lt; &quot;&#92;n&quot;;\r\n\r\n\t\/\/ Remove element at index 3\r\n\tremove(3);\r\n\tcout &lt;&lt; &quot;Priority queue after &quot;\r\n\t\t&lt;&lt; &quot;removing the element : &quot;;\r\n\tint l = 0;\r\n\twhile (l &lt;= size) {\r\n\t\tcout &lt;&lt; H[l] &lt;&lt; &quot; &quot;;\r\n\t\tl++;\r\n\t}\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_8805_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\nimport java.util.*;\r\nclass PrepBytes{\r\n\r\nstatic int []H = new int[50];\r\nstatic int size = -1;\r\n\r\n\r\nstatic int parent(int i)\r\n{\r\nreturn (i - 1) \/ 2;\r\n}\r\n\r\n\r\nstatic int leftChild(int i)\r\n{\r\nreturn ((2 * i) + 1);\r\n}\r\n\r\nstatic int rightChild(int i)\r\n{\r\nreturn ((2 * i) + 2);\r\n}\r\n\r\nstatic void shiftUp(int i)\r\n{\r\nwhile (i &gt; 0 &amp;&amp;\r\n\t\tH[parent(i)] &lt; H[i])\r\n{\r\n\t\/\/ Swap parent and current node\r\n\tswap(parent(i), i);\r\n\r\n\t\/\/ Update i to parent of i\r\n\ti = parent(i);\r\n}\r\n}\r\n\r\nstatic void shiftDown(int i)\r\n{\r\nint maxIndex = i;\r\n\r\n\/\/ Left Child\r\nint l = leftChild(i);\r\n\r\nif (l &lt;= size &amp;&amp;\r\n\tH[l] &gt; H[maxIndex])\r\n{\r\n\tmaxIndex = l;\r\n}\r\n\r\n\/\/ Right Child\r\nint r = rightChild(i);\r\n\r\nif (r &lt;= size &amp;&amp;\r\n\tH[r] &gt; H[maxIndex])\r\n{\r\n\tmaxIndex = r;\r\n}\r\n\r\nif (i != maxIndex)\r\n{\r\n\tswap(i, maxIndex);\r\n\tshiftDown(maxIndex);\r\n}\r\n}\r\n\r\nstatic void insert(int p)\r\n{\r\nsize = size + 1;\r\nH[size] = p;\r\n\r\nshiftUp(size);\r\n}\r\n\r\n\r\nstatic int extractMax()\r\n{\r\nint result = H[0];\r\n\r\nH[0] = H[size];\r\nsize = size - 1;\r\n\r\n\r\nshiftDown(0);\r\nreturn result;\r\n}\r\n\r\nstatic void changePriority(int i,\r\n\t\t\t\t\t\tint p)\r\n{\r\nint oldp = H[i];\r\nH[i] = p;\r\n\r\nif (p &gt; oldp)\r\n{\r\n\tshiftUp(i);\r\n}\r\nelse\r\n{\r\n\tshiftDown(i);\r\n}\r\n}\r\n\r\nstatic int getMax()\r\n{\r\nreturn H[0];\r\n}\r\n\r\nstatic void remove(int i)\r\n{\r\nH[i] = getMax() + 1;\r\n\r\n\r\nshiftUp(i);\r\n\r\n\/\/ Extract the node\r\nextractMax();\r\n}\r\n\r\nstatic void swap(int i, int j)\r\n{\r\nint temp= H[i];\r\nH[i] = H[j];\r\nH[j] = temp;\r\n}\r\n\r\npublic static void main(String[] args)\r\n{\r\n\r\ninsert(55);\r\ninsert(20);\r\ninsert(14);\r\ninsert(12);\r\ninsert(31);\r\ninsert(7);\r\ninsert(11);\r\ninsert(13);\r\ninsert(7);\r\n\r\nint i = 0;\r\n\r\n\/\/ Priority queue before extracting max\r\nSystem.out.print(&quot;Priority Queue : &quot;);\r\nwhile (i &lt;= size)\r\n{\r\n\tSystem.out.print(H[i] + &quot; &quot;);\r\n\ti++;\r\n}\r\n\r\nSystem.out.print(&quot;&#92;n&quot;);\r\n\r\n\/\/ Node with maximum priority\r\nSystem.out.print(&quot;Node with maximum priority : &quot; +\r\n\t\t\t\t\textractMax() + &quot;&#92;n&quot;);\r\n\r\n\/\/ Priority queue after extracting max\r\nSystem.out.print(&quot;Priority queue after &quot; +\r\n\t\t\t\t&quot;extracting maximum : &quot;);\r\nint j = 0;\r\nwhile (j &lt;= size)\r\n{\r\n\tSystem.out.print(H[j] + &quot; &quot;);\r\n\tj++;\r\n}\r\n\r\nSystem.out.print(&quot;&#92;n&quot;);\r\n\r\n\/\/ Change the priority of element\r\n\/\/ present at index 2 to 49\r\nchangePriority(2, 49);\r\nSystem.out.print(&quot;Priority queue after &quot; +\r\n\t\t\t\t&quot;priority change : &quot;);\r\nint k = 0;\r\nwhile (k &lt;= size)\r\n{\r\n\tSystem.out.print(H[k] + &quot; &quot;);\r\n\tk++;\r\n}\r\n\r\nSystem.out.print(&quot;&#92;n&quot;);\r\n\r\n\/\/ Remove element at index 3\r\nremove(3);\r\nSystem.out.print(&quot;Priority queue after &quot; +\r\n\t\t\t\t&quot;removing the element : &quot;);\r\nint l = 0;\r\nwhile (l &lt;= size)\r\n{\r\n\tSystem.out.print(H[l] + &quot; &quot;);\r\n\tl++;\r\n}\r\n}\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_8805_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\n\r\n\r\nH = [0]*50\r\nsize = -1\r\n\r\n\r\ndef parent(i) :\r\n\r\n\treturn (i - 1) \/\/ 2\r\n\r\ndef leftChild(i) :\r\n\r\n\treturn ((2 * i) + 1)\r\n\r\n\r\ndef rightChild(i) :\r\n\r\n\treturn ((2 * i) + 2)\r\n\r\ndef shiftUp(i) :\r\n\r\n\twhile (i > 0 and H[parent(i)] < H[i]) :\r\n\t\t\r\n\t\r\n\t\tswap(parent(i), i)\r\n\t\r\n\t\r\n\t\ti = parent(i)\r\n\t\t\r\ndef shiftDown(i) :\r\n\r\n\tmaxIndex = i\r\n\t\r\n\t# Left Child\r\n\tl = leftChild(i)\r\n\t\r\n\tif (l <= size and H[l] > H[maxIndex]) :\r\n\t\r\n\t\tmaxIndex = l\r\n\t\r\n\t# Right Child\r\n\tr = rightChild(i)\r\n\t\r\n\tif (r <= size and H[r] > H[maxIndex]) :\r\n\t\r\n\t\tmaxIndex = r\r\n\t\r\n\t# If i not same as maxIndex\r\n\tif (i != maxIndex) :\r\n\t\r\n\t\tswap(i, maxIndex)\r\n\t\tshiftDown(maxIndex)\r\n\r\ndef insert(p) :\r\n\t\r\n\tglobal size\r\n\tsize = size + 1\r\n\tH[size] = p\r\n\t\r\n\r\n\tshiftUp(size)\r\n\r\ndef extractMax() :\r\n\t\r\n\tglobal size\r\n\tresult = H[0]\r\n\t\r\n\t\r\n\tH[0] = H[size]\r\n\tsize = size - 1\r\n\r\n\tshiftDown(0)\r\n\treturn result\r\n\r\n\r\ndef changePriority(i,p) :\r\n\r\n\toldp = H[i]\r\n\tH[i] = p\r\n\t\r\n\tif (p > oldp) :\r\n\t\r\n\t\tshiftUp(i)\r\n\r\n\telse :\r\n\t\r\n\t\tshiftDown(i)\r\n\r\ndef getMax() :\r\n\r\n\treturn H[0]\r\n\r\ndef Remove(i) :\r\n\r\n\tH[i] = getMax() + 1\r\n\t\r\n\r\n\tshiftUp(i)\r\n\t\r\n\t# Extract the node\r\n\textractMax()\r\n\r\ndef swap(i, j) :\r\n\t\r\n\ttemp = H[i]\r\n\tH[i] = H[j]\r\n\tH[j] = temp\r\n\r\ninsert(55)\r\ninsert(20)\r\ninsert(14)\r\ninsert(12)\r\ninsert(31)\r\ninsert(7)\r\ninsert(11)\r\ninsert(13)\r\ninsert(7)\r\n\r\ni = 0\r\n\r\n# Priority queue before extracting max\r\nprint(\"Priority Queue : \", end = \"\")\r\nwhile (i <= size) :\r\n\r\n\tprint(H[i], end = \" \")\r\n\ti += 1\r\n\r\nprint()\r\n\r\n# Node with maximum priority\r\nprint(\"Node with maximum priority :\" , extractMax())\r\n\r\n# Priority queue after extracting max\r\nprint(\"Priority queue after extracting maximum : \", end = \"\")\r\nj = 0\r\nwhile (j <= size) :\r\n\r\n\tprint(H[j], end = \" \")\r\n\tj += 1\r\n\r\nprint()\r\n\r\n# Change the priority of element\r\n# present at index 2 to 49\r\nchangePriority(2, 49)\r\nprint(\"Priority queue after priority change : \", end = \"\")\r\nk = 0\r\nwhile (k <= size) :\r\n\r\n\tprint(H[k], end = \" \")\r\n\tk += 1\r\n\r\nprint()\r\n\r\n# Remove element at index 3\r\nRemove(3)\r\nprint(\"Priority queue after removing the element : \", end = \"\")\r\nl = 0\r\nwhile (l <= size) :\r\n\r\n\tprint(H[l], end = \" \")\r\n\tl += 1\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\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_8805 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_8805 a\"),jQuery(\"#tab-content_8805\"));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>Time Complexity:<\/strong><br \/>\nInsertion: O(Log N)<br \/>\nDeletion: O(Log N)<br \/>\nPeek: O(1)<\/p>\n<h4>4. Using BST:<\/h4>\n<p>A self balancing tree like Red black tree, AVL Tree etc are used to implement the priority queue.<br \/>\nA BST takes O(log N) for both the operations i.e. insertion and deletion, Also we can find the top most element in the constant time O(1) by keeping the extra pointer which stores the highest priority element separately and update the pointer after every operation.<\/p>\n<p><strong>Applications of Priority queue:<\/strong><\/p>\n<ul>\n<li>Priority queues are used to implement the stack.<\/li>\n<li>Priority queues are used to implement Dijkstra\u2019s Algorithm.<\/li>\n<li>Also used in huffman code.<\/li>\n<\/ul>\n<p>This article tried to discuss <strong>Priority Queue<\/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>Priority Queue: Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The priority of the element determines the order in which elements are removed from the priority queue. In the priority queue, all the elements are arranged either in ascending order [&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":[128],"tags":[149],"class_list":["post-8802","post","type-post","status-publish","format-standard","hentry","category-queues","tag-queue"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Priority Queue Introduction | Queue | Prepbytes<\/title>\n<meta name=\"description\" content=\"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.\" \/>\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\/priority-queue-introduction\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Priority Queue Introduction | Queue | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\" \/>\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-29T11:20:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-20T09:43:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Priority Queue Introduction\",\"datePublished\":\"2022-06-29T11:20:02+00:00\",\"dateModified\":\"2022-07-20T09:43:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\"},\"wordCount\":506,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg\",\"keywords\":[\"queue\"],\"articleSection\":[\"Queues\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\",\"name\":\"Priority Queue Introduction | Queue | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg\",\"datePublished\":\"2022-06-29T11:20:02+00:00\",\"dateModified\":\"2022-07-20T09:43:41+00:00\",\"description\":\"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Queues\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/queues\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Priority Queue Introduction\"}]},{\"@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":"Priority Queue Introduction | Queue | Prepbytes","description":"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.","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\/priority-queue-introduction\/","og_locale":"en_US","og_type":"article","og_title":"Priority Queue Introduction | Queue | Prepbytes","og_description":"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.","og_url":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-06-29T11:20:02+00:00","article_modified_time":"2022-07-20T09:43:41+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Priority Queue Introduction","datePublished":"2022-06-29T11:20:02+00:00","dateModified":"2022-07-20T09:43:41+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/"},"wordCount":506,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg","keywords":["queue"],"articleSection":["Queues"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/","url":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/","name":"Priority Queue Introduction | Queue | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg","datePublished":"2022-06-29T11:20:02+00:00","dateModified":"2022-07-20T09:43:41+00:00","description":"Priority queue is an abstract data type, It is a type of queue in which each element has a priority assigned to it. The element with highest priority first.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1656309097456-article%20img.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/priority-queue-introduction\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Queues","item":"https:\/\/prepbytes.com\/blog\/category\/queues\/"},{"@type":"ListItem","position":3,"name":"Priority Queue Introduction"}]},{"@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\/8802","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=8802"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8802\/revisions"}],"predecessor-version":[{"id":8865,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/8802\/revisions\/8865"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=8802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=8802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=8802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}