Overview of this book

Data structures allow you to store and organize data efficiently. They are critical to any problem, provide a complete solution, and act like reusable code. Hands-On Data Structures and Algorithms with Python teaches you the essential Python data structures and the most common algorithms for building easy and maintainable applications. This book helps you to understand the power of linked lists, double linked lists, and circular linked lists. You will learn to create complex data structures, such as graphs, stacks, and queues. As you make your way through the chapters, you will explore the application of binary searches and binary search trees, along with learning common techniques and structures used in tasks such as preprocessing, modeling, and transforming data. In the concluding chapters, you will get to grips with organizing your code in a manageable, consistent, and extendable way. You will also study how to bubble sort, selection sort, insertion sort, and merge sort algorithms in detail. By the end of the book, you will have learned how to build components that are easy to understand, debug, and use in different applications. You will get insights into Python implementation of all the important and relevant algorithms.
Table of Contents (16 chapters)
Preface
Free Chapter
Python Objects, Types, and Expressions
Python Data Types and Structures
Principles of Algorithm Design
Lists and Pointer Structures
Stacks and Queues
Trees
Hashing and Symbol Tables
Graphs and Other Algorithms
Searching
Sorting
Selection Algorithms
String Algorithms and Techniques
Design Techniques and Strategies
Implementations, Applications, and Tools
Other Books You May Enjoy

Weighted graphs

A weighted graph is a graph that has a numeric weight associated with the edges in the graph. It can be either a directed or an undirected graph. This numerical value can possibly be used to indicate distance or cost, depending upon the purpose of the graph. Let's consider an example. The following graph indicates different ways to get from the A node to the D node. You can either go straight from A to D, or choose to pass through B and C, considering that the associated weight with each edge is the amount of time, in minutes, for the journey to the next node:

In this example, AD and ABCD represent two different paths. A path is simply a sequence of edges that you pass through between two nodes. Following these paths, you see that the AD journey takes 40 minutes, whereas the ABCD journey takes 25 minutes. If the only concern is time, then it would be better...