Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Data Structures and Algorithms

You're reading from   Python Data Structures and Algorithms Improve application performance with graphs, stacks, and queues

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781786467355
Length 310 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Benjamin Baka Benjamin Baka
Author Profile Icon Benjamin Baka
Benjamin Baka
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Python Objects, Types, and Expressions 2. Python Data Types and Structures FREE CHAPTER 3. Principles of Algorithm Design 4. Lists and Pointer Structures 5. Stacks and Queues 6. Trees 7. Hashing and Symbol Tables 8. Graphs and Other Algorithms 9. Searching 10. Sorting 11. Selection Algorithms 12. Design Techniques and Strategies 13. Implementations, Applications, and Tools

Priority queues and heaps


A priority queue is basically a type of queue that will always return items in order of priority. This priority could be, for example, that the lowest item is always popped off first. Although it is called a queue, priority queues are often implemented using a heap, since it is very efficient for this purpose.

Consider that, in a store, customers queue in a line where service is only rendered at the front of the queue. Each customer will spend some time in the queue to get served. If the waiting times for the customers in the queue are 4, 30, 2, and 1, then the average time spent in the queue becomes (4 + 34 + 36 + 37)/4, which is 27.75. However, if we change the order of service such that customers with the least amount of waiting time are served first, then we obtain a different average waiting time. In doing so, we calculate our new average waiting time by (1 + 3 + 7 + 37)/4, which now equals 12, a better average waiting time. Clearly, there is merit to serving...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image