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
chevron up

Hashing


Hashing is the concept of converting data of arbitrary size into data of fixed size. A little bit more specifically, we are going to use this to turn strings (or possibly other data types) into integers. This possibly sounds more complex than it is so let's look at an example. We want to hash the expression hello world, that is, we want to get a numeric value that we could say represents the string.

By using the ord() function, we can get the ordinal value of any character. For example, the ord('f') function gives 102. To get the hash of the whole string, we could just sum the ordinal numbers of each character in the string:

>>> sum(map(ord, 'hello world'))
1116

This works fine. However, note that we could change the order of the characters in the string and get the same hash:

>>> sum(map(ord, 'world hello'))
1116

And the sum of the ordinal values of the characters would be the same for the string gello xorld as well, since g has an ordinal value which is one less than...

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