TheHingineer

  • Data Structures & Algorithms


  • DSA Part-1

  • DSA Part-2

  • DSA Part-3

  • DSA Part-4

  • DSA Part-5

  • Priority Queue: Concept, Array and Heap Representation

    Priority Queue ek aisi special queue hoti hai jisme har element ke saath ek Priority Value associated hoti hai. Elements queue me unki arrival order ke bajay unki priority ke hisaab se process aur delete hote hain:

    • Higher priority element hamesha lower priority element se pehle service hota hai.
    • Agar do elements ki priority same ho, toh unhe standard FIFO order me process kiya jata hai.

    Types of Priority Queues

    • Max-Priority Queue: Sabse largest key/priority value wala element sabse pehle delete hota hai.
    • Min-Priority Queue: Sabse smallest key/priority value wala element sabse pehle delete hota hai (e.g. Dijkstra’s Shortest Path, Prim’s MST).

    Implementation Tradeoffs

    Underlying Data Structure Insertion Time Deletion (Extract Min/Max) Peek (Get Min/Max)
    Unordered Array O(1) at end O(n) linear search O(n)
    Ordered (Sorted) Array O(n) due to shifting O(1) from end O(1)
    Binary Heap (Optimal) O(log n) O(log n) O(1)

    Agli post me hum start karenge DSA Part-5: Non-Linear Data Structures (Trees, Graphs & Hashing), jisme pehla topic hoga Tree Data Structure: Terminology and Basic Concepts.

    Scroll to Top