Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Python Data Structures and Algorithms
  • Table Of Contents Toc
  • Feedback & Rating feedback
Python Data Structures and Algorithms

Python Data Structures and Algorithms

By : Benjamin Baka
2.7 (11)
close
close
Python Data Structures and Algorithms

Python Data Structures and Algorithms

2.7 (11)
By: Benjamin Baka

Overview of this book

Data structures allow you to organize data in a particular way efficiently. They are critical to any problem, provide a complete solution, and act like reusable code. In this book, you will learn the essential Python data structures and the most common algorithms. With this easy-to-read book, you will be able to understand the power of linked lists, double linked lists, and circular linked lists. You will be able to create complex data structures such as graphs, stacks and queues. We will explore the application of binary searches and binary search trees. You will learn the common techniques and structures used in tasks such as preprocessing, modeling, and transforming data. We will also discuss how to organize your code in a manageable, consistent, and extendable way. The book will explore in detail sorting algorithms such as bubble sort, selection sort, insertion sort, and merge sort. By the end of the book, you will learn how to build components that are easy to understand, debug, and use in different applications.
Table of Contents (14 chapters)
close
close
5
Stacks and Queues
7
Hashing and Symbol Tables

Finding endpoints


We have created three nodes: one containing eggs, one ham, and another spam. The eggs node points to the ham node, which in turn points to the spam node. But what does the spam node point to? Since this is the last element in the list, we need to make sure its next member has a value that makes this clear.

If we make the last element point to nothing then we make this fact clear. In python, we will use the special value None to denote nothing:

The last node has its next point pointing to None. As such it is the last node in the chain of nodes.

Node

Here is a simple node implementation of what we have discussed so far:

    class Node: 
        def __init__(self, data=None): 
            self.data = data 
            self.next = None 

Note

Do not confuse the concept of a node with Node.js, a server-side technology implemented in JavaScript.

The next pointer is initialized to None, meaning that unless you change the value of next, the node is going to be an end-point. This is a good...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY