Lecture Note
University
University of California San DiegoCourse
CSE 100/101 | Data Structures and AlgorithmsPages
2
Academic year
2023
anon
Views
26
Efficient Priority Queue Implementations Data structures called priority queues are used to store elements so that the maximum (or minimum) element may always be found in a fixed amount oftime. However, unsophisticated implementations of priority queues that useunordered arrays or lists contain an extract max operation that runs in lineartime. The efficient implementations of priority queues with constant timeextract max and either logarithmic or constant time insertion operations will becovered in this paper. Naive Implementations Inserting a new element is simple if the contents of a priority queue are kept in an unsorted array or list. Simply add the new element to the list orarray's end. The extract max operation has a linear running time of O(n) sinceobtaining the maximum element in this scenario necessitates scanning the entirearray or list. Arranged Arrays Keeping the array's contents ordered is a fair strategy to try to optimize the extract max operation. Since the maximum element in this situation issimply the array's final element, the extract max procedure is quite simple. Thedrawback is that the insertion process now requires linear time. Binarizedsearch, which may be completed in logarithmic time, can be used to determinethe ideal position for the new element. To have a linear running time for theinsertion process, we must first locate the ideal position and then moveeverything one step to the right of it. Listed Ordered The first benefit of using a sorted list rather than a sorted array is that the extract max operation still completes in constant time. Just the last member inthe list is the maximum element. The fact that inserting in the midst of the list isa constant-time operation is an additional benefit.
Priority queues are a significant data structure with numerous uses, to sum up.The extract max method runs linearly in naive implementations using unsortedarrays or lists. Constant time extract max operations and either logarithmic orconstant time insertion operations are features of effective implementationsusing sorted arrays or sorted lists. It's crucial to pick the appropriate datastructure for a priority queue implementation based on the needs of theapplication.
Naive Implementations of Priority Queues
Please or to post comments