Priority Queue: Min-Priority vs Max-Priority Queues Notes in Hindi & English : प्राथमिकता कतार (Priority Queue): न्यूनतम व अधिकतम कतार और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Priority Queue: Min-Priority vs Max-Priority Queues (प्राथमिकता कतार (Priority Queue): न्यूनतम व अधिकतम कतार) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: A Priority Queue is an abstract data type where every element carries an associated priority key, and dequeue extracts either the minimum-key item (Min-Priority Queue) or maximum-key item (Max-Priority Queue) rather than strict arrival order. Implemented efficiently via a Binary Heap, it delivers O(log n) insertion and extraction alongside O(1) extreme-key lookup.

अध्याय सार: प्राथमिकता कतार (Priority Queue) एक ऐसा ADT है जहाँ प्रत्येक तत्व के साथ एक प्राथमिकता कुंजी जुड़ी होती है और डिकतार पर हमेशा न्यूनतम कुंजी (Min-Priority) या अधिकतम कुंजी (Max-Priority) वाला तत्व पहले निकलता है। बाइनरी हीप (Binary Heap) द्वारा निर्मित होने पर यह O(log n) में प्रविष्टि/निकासी और O(1) में शीर्ष प्राथमिकता जांच देती है।

Priority Queue: Min-Priority vs Max-Priority Queues: Detailed Notes & Architecture (प्राथमिकता कतार (Priority Queue): न्यूनतम व अधिकतम कतार)

1. Priority Queue ADT and Departure from Strict FIFO (प्राथमिकता कतार ADT और सामान्य FIFO से भिन्नता)

[EN] Unlike a standard queue where arrival order strictly dictates exit order, a Priority Queue orders servicing by numeric or comparable priority values. If a high-priority interrupt arrives behind ten background tasks, it jumps ahead to be extracted first. When two items share identical priority, standard priority queues resolve ties using FIFO arrival order (preserving stability for equal keys).

[HI] सामान्य कतार के विपरीत, प्राथमिकता कतार में बाहर निकलने का क्रम आगमन के बजाय तत्व की प्राथमिकता से तय होता है। यदि उच्च प्राथमिकता वाला कार्य बाद में भी आए, तो वह कम प्राथमिकता वाले कार्यों से पहले निष्पादित होगा। समान प्राथमिकता वाले तत्वों के बीच प्रायः FIFO क्रम से निर्णय (tie-breaking) किया जाता है।

2. Min-Priority Queue vs Max-Priority Queue (मिन-प्राथमिकता (Min-Priority) बनाम मैक्स-प्राथमिकता (Max-Priority) कतार)

[EN] A Min-Priority Queue treats smaller key values as highest priority, exposing findMin() and extractMin(); it powers Dijkstra's shortest path, Prim's Minimum Spanning Tree, Huffman coding tree construction, and earliest-deadline event simulators. Conversely, a Max-Priority Queue gives highest priority to the largest key via findMax() and extractMax(); it drives OS priority schedulers (higher number = higher priority), Heap Sort in ascending order, and top-K tracking.

[HI] मिन-प्राथमिकता कतार में सबसे छोटे मान को सर्वोच्च प्राथमिकता मिलती है (extractMin); इसका उपयोग Dijkstra के सबसे छोटे पथ, Prim के MST और Huffman कोडिंग में होता है। इसके विपरीत, मैक्स-प्राथमिकता कतार सबसे बड़े मान को पहले निकालती है (extractMax) और OS प्राथमिकता शेड्यूलिंग तथा आरोही हीप सॉर्ट में प्रयुक्त होती है।

3. Implementation Trade-Offs: Lists, Arrays, and Binary Heaps (कार्यान्वयन विकल्प: एरे, लिंक्ड लिस्ट और बाइनरी हीप तुलना)

[EN] An unsorted array inserts in O(1) at the end, yet extractMin/Max must scan all elements in O(n). A sorted array maintains O(1) peek/extract at the end, yet insertion requires shifting elements in O(n). A Binary Heap strikes the optimal balance—supporting O(log n) insert (sift-up), O(log n) extract (sift-down), O(1) peek at index 0, and O(n) bottom-up buildHeap.

[HI] बिना क्रमबद्ध (Unsorted) एरे में जोड़ना O(1) है पर अधिकतम/न्यूनतम खोजना O(n) लेता है; क्रमबद्ध (Sorted) एरे में निकालना O(1) है पर जोड़ना O(n) लेता है। बाइनरी हीप सर्वोत्तम संतुलन देता है: O(log n) प्रविष्टि, O(log n) निकासी, O(1) शीर्ष अवलोकन (peek) और O(n) बिल्ड-हीप।

4. Starvation Hazard and Aging Mitigation (स्टार्वेशन (Starvation) समस्या और एजिंग (Aging) समाधान)

[EN] In continuous OS workloads, low-priority tasks inside a Priority Queue can suffer Starvation (indefinite blocking) if higher-priority jobs arrive endlessly. Operating systems eliminate starvation via Aging—periodically incrementing the priority of waiting tasks proportional to their wait duration so every job eventually reaches the top and executes.

[HI] निरंतर उच्च-प्राथमिकता वाले कार्य आते रहने से कम प्राथमिकता वाली प्रक्रियाएं अनिश्चित काल तक अटकी रह सकती हैं, जिसे Starvation (भूखमरी) कहते हैं। ऑपरेटिंग सिस्टम इसे Aging तकनीक से रोकते हैं, जहाँ प्रतीक्षा समय बढ़ने के साथ कतार में बैठे कार्य की प्राथमिकता धीरे-धीरे बढ़ा दी जाती है।

Syntax, Formula & Technical Example (Priority Queue: Min-Priority vs Max-Priority Queues)

// Binary Min-Heap Sift-Up on Insert (0-indexed array):
void insertMinPQ(int heap[], int *n, int key) {
    int i = (*n)++;
    heap[i] = key;
    while (i > 0 && heap[(i - 1) / 2] > heap[i]) {
        swap(&heap[i], &heap[(i - 1) / 2]);
        i = (i - 1) / 2;
    }
}

Priority Queue: Min-Priority vs Max-Priority Queues Quick Reference & Comparison Table

Implementation StructureInsert / Extract / Peek ComplexityKey Exam Fact
Unsorted Array / ListInsert O(1), Extract O(n), Peek O(n)Fastest insertion; linear scan to extract
Sorted ArrayInsert O(n), Extract O(1), Peek O(1)Insertion shift overhead; instant max/min read
Binary Heap (Min / Max)Insert O(log n), Extract O(log n), Peek O(1)Industry standard; O(n) initial buildHeap
Balanced BST (AVL / RB)Insert O(log n), Extract O(log n), Search O(log n)Supports range queries & predecessor in O(log n)

Priority Queue: Min-Priority vs Max-Priority Queues Top 20 Bilingual MCQs with Answers

Q1. Which data structure provides the optimal general-purpose implementation of a Priority Queue with O(log n) insert/delete and O(1) peek?

(O(log n) प्रविष्टि/विलोपन और O(1) पीक के साथ प्राथमिकता कतार बनाने के लिए सबसे उत्तम डेटा संरचना कौन सी है?)

(A) Unsorted Singly Linked List

(B) Binary Heap (Min-Heap or Max-Heap)

(C) Hash Table without ordering

(D) Sorted Static Array

Correct Answer: (B)

[EN] Binary Heap uses an array-backed complete binary tree to insert and extract in O(log n) while reading root in O(1).

[HI] बाइनरी हीप एरे आधारित पूर्ण बाइनरी ट्री से O(log n) में जोड़ने-हटाने और O(1) में शीर्ष प्राथमिकता देखने की सुविधा देता है।

Q2. What does extractMin() return from a Min-Priority Queue holding keys [45, 12, 88, 7, 30]?

(कुंजियों [45, 12, 88, 7, 30] वाली Min-Priority कतार पर extractMin() चलाने से कौन सा तत्व निकलेगा?)

(A) 7

(B) 30

(C) 45

(D) 88

Correct Answer: (A)

[EN] A Min-Priority Queue always removes the item having the numerically smallest priority key (7).

[HI] Min-Priority कतार हमेशा सबसे कम संख्यात्मक कुंजी (7) वाले तत्व को सबसे पहले निकालती है।

Q3. If items A(p=5), B(p=9), C(p=5), D(p=2) enter a Max-Priority Queue with FIFO tie-breaking, what is the exact extraction sequence?

(FIFO टाई-ब्रेकिंग वाली Max-Priority कतार में A(p=5), B(p=9), C(p=5), D(p=2) डालने पर इनके निकलने का सही क्रम क्या होगा?)

(A) B, A, C, D

(B) B, C, A, D

(C) D, A, C, B

(D) A, B, C, D

Correct Answer: (A)

[EN] Highest key B(9) exits first; between equal keys p=5, A arrived before C so A precedes C; lowest D(2) exits last.

[HI] सबसे पहले B(9) निकलेगा; बराबर प्राथमिकता p=5 में A पहले आया था इसलिए A के बाद C और अंत में D(2) निकलेगा।

Q4. Which classic graph/compression algorithms directly require a Min-Priority Queue?

(निम्नलिखित में से किन प्रसिद्ध एल्गोरिदम में सीधे Min-Priority कतार का उपयोग होता है?)

(A) Depth-First Search and Topological Sort

(B) Floyd-Warshall and Counting Sort

(C) Binary Search and Merge Sort

(D) Dijkstra's Shortest Path, Prim's MST, and Huffman Coding

Correct Answer: (D)

[EN] Dijkstra picks minimum-distance vertex, Prim picks minimum-weight edge, and Huffman merges minimum-frequency nodes.

[HI] Dijkstra न्यूनतम दूरी, Prim न्यूनतम भार एज, तथा Huffman न्यूनतम आवृत्ति नोड्स चुनने हेतु Min-Priority कतार उपयोग करते हैं।

Q5. What is the time complexity of building a Binary Heap (Priority Queue) bottom-up from an unsorted array of n elements?

(n तत्वों वाले बिना क्रमबद्ध एरे से बॉटम-अप विधि द्वारा बाइनरी हीप (Priority Queue) बनाने की समय जटिलता क्या है?)

(A) O(n log n)

(B) O(log n)

(C) O(n)

(D) O(n^2)

Correct Answer: (C)

[EN] Floyd's bottom-up heapify sums work geometrically across tree heights, converging strictly to O(n) linear time.

[HI] बॉटम-अप heapify विधि में अधिकांश नोड्स नीचे होते हैं, जिससे कुल निर्माण समय O(n log n) नहीं बल्कि O(n) होता है।

Q6. What OS mechanism resolves 'Starvation' of low-priority items inside a Priority Queue scheduler?

(प्राथमिकता कतार शेड्यूलर में कम प्राथमिकता वाले कार्यों के 'स्टार्वेशन' को किस OS तकनीक से रोका जाता है?)

(A) Swapping

(B) Spooling

(C) Aging (gradually increasing priority as wait time grows)

(D) Thrashing

Correct Answer: (C)

[EN] Aging prevents indefinite postponement by periodically boosting the priority of waiting jobs.

[HI] Aging तकनीक प्रतीक्षा समय बढ़ने के साथ रुके हुए कार्यों की प्राथमिकता धीरे-धीरे बढ़ाकर स्टार्वेशन रोकती है।

Q7. In a 0-indexed Binary Heap array, if a node sits at index i, what are the indices of its parent and left child?

(0-इंडेक्स्ड बाइनरी हीप एरे में यदि कोई नोड इंडेक्स i पर है, तो उसके पैरेंट और लेफ्ट चाइल्ड के इंडेक्स क्या होंगे?)

(A) Parent: i - 1; Left Child: i + 1

(B) Parent: i / 2; Left Child: 2*i

(C) Parent: (i - 1) / 2; Left Child: 2*i + 1

(D) Parent: (i + 1) / 2; Left Child: 2*i + 2

Correct Answer: (C)

[EN] Zero-based complete binary tree array mapping places parent at floor((i - 1) / 2), left at 2i + 1, right at 2i + 2.

[HI] 0-आधारित इंडेक्सिंग में पैरेंट (i - 1) / 2, बायां बच्चा 2i + 1 और दायां बच्चा 2i + 2 पर होता है।

Q8. In an unsorted array implementation of a Priority Queue of n elements, what are Insert and Extract complexities respectively?

(बिना क्रमबद्ध (Unsorted) एरे से बनी प्राथमिकता कतार में Insert और Extract की जटिलता क्रमशः क्या होती है?)

(A) Insert: O(1), Extract: O(n)

(B) Insert: O(log n), Extract: O(log n)

(C) Insert: O(n), Extract: O(1)

(D) Insert: O(1), Extract: O(1)

Correct Answer: (A)

[EN] Appending to the end takes O(1), while finding and removing the min/max scans all n elements in O(n).

[HI] अंत में नया मान जोड़ने में O(1) लगता है, लेकिन न्यूनतम/अधिकतम खोजकर हटाने में पूरा एरे O(n) में खोजना पड़ता है।

Q9. By default, C++ STL `std::priority_queue<int>` and Python `heapq` implement which variants respectively?

(डिफ़ॉल्ट रूप से C++ का `std::priority_queue<int>` और Python का `heapq` क्रमशः कौन सी कतार बनाते हैं?)

(A) C++ defaults to Min-PQ; Python heapq defaults to Max-PQ

(B) C++ defaults to Max-Priority Queue; Python heapq defaults to Min-Priority Queue

(C) Both default to Min-Priority Queue

(D) Both default to Max-Priority Queue

Correct Answer: (B)

[EN] C++ std::priority_queue uses std::less (max at top); Python's heapq maintains min-heap invariant (smallest at index 0).

[HI] C++ का priority_queue डिफ़ॉल्ट रूप से Max-Heap और Python का heapq मॉड्यूल Min-Heap होता है।

Q10. Why is a standard FIFO Queue considered a special case of a Priority Queue?

(सामान्य FIFO कतार को प्राथमिकता कतार का एक विशेष रूप क्यों माना जा सकता है?)

(A) Because FIFO sorts keys descending

(B) Assigning monotonically increasing timestamps/sequence numbers as keys in a Min-Priority Queue reproduces FIFO order

(C) Because both have O(1) arbitrary search

(D) Because Priority Queues ignore keys

Correct Answer: (B)

[EN] When priority equals insertion timestamp in a Min-PQ, the earliest arriving element always holds the smallest key and exits first.

[HI] यदि प्रत्येक आने वाले तत्व को बढ़ता हुआ टाइमस्टैम्प दे दें, तो Min-Priority कतार स्वतः FIFO क्रम में तत्व निकालेगी।

Q11. During extractMax() in a Binary Max-Heap of n elements, how does the heap restore its structural and heap-order properties?

(बाइनरी मैक्स-हीप में extractMax() करते समय हीप के नियम पुनः कैसे बहाल किए जाते हैं?)

(A) Delete index 0 and shift every array element left by 1

(B) Delete the smallest leaf directly

(C) Rebuild the entire heap from scratch in O(n)

(D) Swap root with last leaf, decrement heap size, and sift-down (max-heapify) from index 0

Correct Answer: (D)

[EN] Replacing the removed root with the last element preserves completeness, and sift-down fixes order in O(log n) swaps.

[HI] रूट निकालकर अंतिम पत्ती को इंडेक्स 0 पर रखा जाता है और फिर नीचे की ओर sift-down करके O(log n) में हीप सही करते हैं।

Q12. In a sorted descending array Priority Queue (highest priority at rear index n - 1), how fast are peekMax() and insert()?

(घटते क्रम में व्यवस्थित सॉर्टेड एरे प्राथमिकता कतार (शीर्ष मान अंत में) में peekMax() और insert() की गति क्रमशः क्या है?)

(A) peekMax: O(n), insert: O(1)

(B) peekMax: O(1), insert: O(1)

(C) peekMax: O(log n), insert: O(1)

(D) peekMax: O(1), insert: O(n)

Correct Answer: (D)

[EN] Reading/popping the tail takes O(1), but inserting an arbitrary priority requires binary search plus O(n) shifting.

[HI] अंतिम तत्व पढ़ना O(1) है, परंतु नई कुंजी को सही क्रम में रखने हेतु तत्व खिसकाने में O(n) समय लगता है।

Q13. Which discrete-event simulation rule naturally maps to a Min-Priority Queue?

(डिस्क्रीट-इवेंट सिमुलेशन में भविष्य की घटनाओं को चलाने हेतु Min-Priority कतार क्यों उपयुक्त होती है?)

(A) Events execute in reverse chronological order

(B) Events execute by alphabetical event name

(C) Events are discarded after 10 ticks

(D) Future events are keyed by timestamp so the earliest upcoming event always executes next

Correct Answer: (D)

[EN] Keying events by scheduled timestamp guarantees the closest upcoming timestamp is always extracted first.

[HI] घटनाओं को उनके समय (timestamp) की कुंजी देने पर सबसे नजदीकी भविष्य की घटना हमेशा पहले निकलती है।

Q14. If a Binary Max-Heap holds 15 elements, at most how many levels/comparisons can a single insert() sift-up traverse?

(15 तत्वों वाले बाइनरी मैक्स-हीप में एक नया तत्व जोड़ते समय अधिकतम कितने स्तरों (तुलनाओं) तक sift-up करना पड़ सकता है?)

(A) 1 level always

(B) 15 levels

(C) At most 4 levels (floor(log2(16)) = 4)

(D) 8 levels

Correct Answer: (C)

[EN] A binary heap of 15 elements has height 3 (4 levels); inserting a 16th item adds level 4 (at most 4 parent comparisons).

[HI] 15 तत्वों के बाद 16वां तत्व चौथे स्तर पर जुड़ता है, अतः रूट तक जाने में अधिकतम 4 तुलनाएं लगेंगी।

Q15. How does a Priority Queue implemented with a Sorted Singly Linked List perform compared to a Binary Heap?

(सॉर्टेड सिंगली लिंक्ड लिस्ट से बनी प्राथमिकता कतार की तुलना बाइनरी हीप से करने पर मुख्य अंतर क्या दिखता है?)

(A) Sorted Linked List has O(1) insert and O(1) extract

(B) Sorted Linked List has O(1) extract but O(n) insert, whereas Binary Heap achieves O(log n) for both

(C) Sorted Linked List prevents equal priorities

(D) Binary Heap requires O(n^2) space

Correct Answer: (B)

[EN] Finding the sorted insertion point in a linked list requires O(n) traversal even without array shifting.

[HI] सॉर्टेड लिंक्ड लिस्ट में सही स्थान खोजकर जोड़ने में O(n) समय लगता है, जबकि बाइनरी हीप दोनों काम O(log n) में करता है।

Q16. Which statement is NOT true about Priority Queues?

(प्राथमिकता कतार (Priority Queue) के बारे में निम्नलिखित में से कौन सा कथन असत्य (NOT true) है?)

(A) Binary Heap enables O(log n) enqueue and dequeue

(B) Elements are always guaranteed to exit strictly in the order they were inserted

(C) Starvation of low-priority tasks can be prevented via aging

(D) A Min-Priority Queue extracts the smallest key first

Correct Answer: (B)

[EN] Priority Queue deliberately overrides insertion order whenever priorities differ; only equal-priority items typically fall back to FIFO.

[HI] प्राथमिकता कतार में निकासी हमेशा आगमन क्रम से नहीं होती—उच्च प्राथमिकता वाला बाद में आकर भी पहले निकल सकता है।

Q17. Within Priority Queue: Min-Priority vs Max-Priority Queues, which implementation structure directly maps to: "Insert O(1), Extract O(n), Peek O(n)"?

(Priority Queue: Min-Priority vs Max-Priority Queues में कौन सा Implementation Structure सीधे "Insert O(1), Extract O(n), Peek O(n)" से संबंधित है?)

(A) Sorted Array

(B) Binary Heap (Min / Max)

(C) Balanced BST (AVL / RB)

(D) Unsorted Array / List

Correct Answer: (D)

[EN] In Priority Queue: Min-Priority vs Max-Priority Queues, 'Unsorted Array / List' handles 'Insert O(1), Extract O(n), Peek O(n)' (Fastest insertion; linear scan to extract).

[HI] Priority Queue: Min-Priority vs Max-Priority Queues में 'Unsorted Array / List' का कार्य/विवरण 'Insert O(1), Extract O(n), Peek O(n)' (Fastest insertion; linear scan to extract) है।

Q18. Which option accurately describes 'Sorted Array' in Priority Queue: Min-Priority vs Max-Priority Queues?

(Priority Queue: Min-Priority vs Max-Priority Queues के संदर्भ में 'Sorted Array' की सही विशेषता कौन सी है?)

(A) Insert O(log n), Extract O(log n), Peek O(1)

(B) Insert O(log n), Extract O(log n), Search O(log n)

(C) Insert O(1), Extract O(n), Peek O(n)

(D) Insert O(n), Extract O(1), Peek O(1)

Correct Answer: (D)

[EN] 'Sorted Array' provides 'Insert O(n), Extract O(1), Peek O(1)' — key point: Insertion shift overhead; instant max/min read.

[HI] 'Sorted Array' का मुख्य विवरण 'Insert O(n), Extract O(1), Peek O(1)' है (Insertion shift overhead; instant max/min read)।

Q19. In Priority Queue: Min-Priority vs Max-Priority Queues, identify the correct parameter for the specification: "Insert O(log n), Extract O(log n), Peek O(1)".

(Priority Queue: Min-Priority vs Max-Priority Queues में "Insert O(log n), Extract O(log n), Peek O(1)" विवरण किस विकल्प के लिए सही है?)

(A) Unsorted Array / List

(B) Sorted Array

(C) Binary Heap (Min / Max)

(D) Balanced BST (AVL / RB)

Correct Answer: (C)

[EN] 'Binary Heap (Min / Max)' corresponds to 'Insert O(log n), Extract O(log n), Peek O(1)' (Industry standard; O(n) initial buildHeap).

[HI] 'Binary Heap (Min / Max)' का संबंध 'Insert O(log n), Extract O(log n), Peek O(1)' (Industry standard; O(n) initial buildHeap) से है।

Q20. Considering Priority Queue: Min-Priority vs Max-Priority Queues, what key behavior defines 'Balanced BST (AVL / RB)'?

(Priority Queue: Min-Priority vs Max-Priority Queues में 'Balanced BST (AVL / RB)' की मुख्य भूमिका या मान क्या है?)

(A) Insert O(log n), Extract O(log n), Peek O(1)

(B) Insert O(n), Extract O(1), Peek O(1)

(C) Insert O(1), Extract O(n), Peek O(n)

(D) Insert O(log n), Extract O(log n), Search O(log n)

Correct Answer: (D)

[EN] 'Balanced BST (AVL / RB)' represents 'Insert O(log n), Extract O(log n), Search O(log n)' (Supports range queries & predecessor in O(log n)).

[HI] 'Balanced BST (AVL / RB)' का अर्थ/मान 'Insert O(log n), Extract O(log n), Search O(log n)' है (Supports range queries & predecessor in O(log n))।

Priority Queue: Min-Priority vs Max-Priority Queues — Exam FAQs

Q1: Is a Priority Queue the same thing as a Binary Heap?

क्या Priority Queue और Binary Heap दोनों एक ही चीज हैं?

[EN] No. Priority Queue is the Abstract Data Type (defining operations insert, extractMin/Max, peek), whereas Binary Heap is the most efficient concrete data structure used to implement it.

[HI] नहीं। Priority Queue एक अवधारणा (ADT) है जो कार्य बताती है, जबकि Binary Heap इसे O(log n) में लागू करने वाली सबसे प्रमुख डेटा संरचना है।

Q2: Can a Priority Queue store duplicate priority keys?

क्या एक प्राथमिकता कतार में समान प्राथमिकता वाले एक से अधिक तत्व रह सकते हैं?

[EN] Yes! Multiple jobs frequently share the exact same priority; implementations either break ties using FIFO sequence order or return any matching highest-priority item.

[HI] हाँ! समान प्राथमिकता वाले कई तत्व रह सकते हैं; ऐसे में सामान्यतः पहले आने वाले तत्व को पहले निकालने (FIFO tie-breaking) का नियम अपनाया जाता है।

Q3: How can a Min-Heap library (like Python heapq) act as a Max-Priority Queue?

यदि किसी भाषा में केवल Min-Heap लाइब्रेरी उपलब्ध हो (जैसे Python heapq), तो उससे Max-Priority कतार कैसे बनाएं?

[EN] Negate numeric keys before inserting (-key) and negate them back upon extraction, so the largest original key becomes the smallest negative key at the top.

[HI] सभी संख्यात्मक कुंजियों को ऋणात्मक (-key) करके जोड़ें और निकालते समय पुनः चिह्न पलट दें; इससे सबसे बड़ी कुंजी सबसे छोटी बनकर शीर्ष पर आ जाएगी।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)