0% found this document useful (1 vote)
304 views

Dr. Basant Agarwal - Hands-On Data Structures and Algorithms With Python - Store, Manipulate, and Access Data Effectively, 3rd Edition-Packt (2022)

Uploaded by

Almir Polverini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
304 views

Dr. Basant Agarwal - Hands-On Data Structures and Algorithms With Python - Store, Manipulate, and Access Data Effectively, 3rd Edition-Packt (2022)

Uploaded by

Almir Polverini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Download Packt Books Free

https://t.me/prog_books_Pack

Hands-On Data Structures and


Algorithms with Python
Third Edition

Store, manipulate, and access data effectively and boost the


performance of your applications

Dr. Basant Agarwal

BIRMINGHAM—MUMBAI

“Python” and the Python Logo are trademarks of the Python Software Foundation.
Download Packt Books Free
https://t.me/prog_books_Pack

Hands-On Data Structures and Algorithms with Python


Third Edition
Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in
any form or by any means, without the prior written permission of the publisher, except in the case of brief
quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express or
implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any
damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee
the accuracy of this information.

Senior Publishing Product Manager: Denim Pinto


Acquisition Editor – Technical Reviews: Saby Dsilva
Project Editor: Rianna Rodrigues
Content Development Editor: Rebecca Robinson
Copy Editor: Safis Editing
Technical Editor: Karan Sonawane
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Presentation Designer: Ganesh Bhadwalkar

First published: May 2017


Second edition: October 2018
Third edition: July 2022

Production reference: 1150722

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-80107-344-8
www.packt.com
Download Packt Books Free
https://t.me/prog_books_Pack

Contributors

About the author


Dr. Basant Agarwal is working as an Assistant Professor at the Department of Computer
Science and Engineering, Indian Institute of Information Technology Kota (IIIT-Kota), India,
which is an Institute of National Importance. He holds a Ph.D. and M.Tech. from the Department
of Computer Science and Engineering, Malaviya National Institute of Technology Jaipur, India.
He has more than 9 years of experience in research and teaching. He has worked as a Postdoc
Research Fellow at the Norwegian University of Science and Technology (NTNU), Norway, under
the prestigious European Research Consortium for Informatics and Mathematics (ERCIM)
fellowship in 2016. He has also worked as a Research Scientist at Temasek Laboratories, National
University of Singapore (NUS), Singapore. His research interests are in artificial intelligence,
cyber-physical systems, text mining, natural language processing, machine learning, deep learning,
intelligent systems, expert systems, and related areas.

This book is dedicated to my family, and friends.

Thank you to Benjamin Baka for his hard work in the first edition.

– Dr. Basant Agarwal


Download Packt Books Free
https://t.me/prog_books_Pack

About the reviewers


Patrick Arminio is a software engineer based in London. He’s currently the chair of Python
Italia, an association that organizes Python events in Italy.

He’s been working with Python for more than 10 years, focusing on web development using Django.
He’s also the maintainer of Strawberry GraphQL, an open source Python library for creating
GraphQL APIs.

Dong-hee Na is a software engineer and an open-source enthusiast. He works at Line Corporation


as a backend engineer. He has professional experience in machine learning projects based on
Python and C++. As for his open-source works, he focuses on the compiler and interpreter area,
especially for Python-related projects. He has been a CPython core developer since 2020.
Join our community on Discord
Join our community’s Discord space for discussions with the author and other readers:
https://packt.link/MEvK4
Table of Contents

Preface xvii

Chapter 1: Python Data Types and Structures 1

Introducing Python 3.10 ..................................................................................................... 2


Installing Python ................................................................................................................ 2
Windows operating system • 2
Linux-based operating systems • 3
Mac operating system • 3
Setting up a Python development environment .................................................................. 3
Setup via the command line • 3
Setup via Jupyter Notebook • 4
Overview of data types and objects ..................................................................................... 5
Basic data types .................................................................................................................. 7
Numeric • 7
Boolean • 8
Sequences • 9
Strings • 9
Range • 10
Lists • 11
Membership, identity, and logical operations • 15
Membership operators • 15
Identity operators • 16
viii Table of Contents

Logical operators • 17
Tuples • 18
Complex data types ........................................................................................................... 19
Dictionaries • 19
Sets • 23
Immutable sets • 26
Python’s collections module ............................................................................................. 27
Named tuples • 27
Deque • 28
Ordered dictionaries • 29
Default dictionary • 29
ChainMap object • 30
Counter objects • 31
UserDict • 32
UserList • 32
UserString • 33
Summary .......................................................................................................................... 33

Chapter 2: Introduction to Algorithm Design 35

Introducing algorithms ..................................................................................................... 35


Performance analysis of an algorithm ............................................................................... 38
Time complexity • 38
Space complexity • 40
Asymptotic notation ......................................................................................................... 41
Theta notation • 42
Big O notation • 44
Omega notation • 47
Amortized analysis ............................................................................................................ 49
Composing complexity classes .......................................................................................... 50
Computing the running time complexity of an algorithm ................................................ 52
Summary .......................................................................................................................... 54
Table of Contents ix

Exercises ........................................................................................................................... 55

Chapter 3: Algorithm Design Techniques and Strategies 57

Algorithm design techniques ............................................................................................ 58


Recursion .......................................................................................................................... 59
Divide and conquer ........................................................................................................... 60
Binary search • 61
Merge sort • 63
Dynamic programming ..................................................................................................... 68
Calculating the Fibonacci series • 70
Greedy algorithms ............................................................................................................ 74
Shortest path problem • 76
Summary .......................................................................................................................... 89
Exercises ........................................................................................................................... 90

Chapter 4: Linked Lists 93

Arrays ................................................................................................................................ 94
Introducing linked lists ..................................................................................................... 95
Nodes and pointers • 95
Singly linked lists .............................................................................................................. 98
Creating and traversing • 98
Improving list creation and traversal • 99
Appending items • 100
Appending items to the end of a list • 100
Appending items at intermediate positions • 103
Querying a list • 106
Searching an element in a list • 107
Getting the size of the list • 107
Deleting items • 108
Deleting the node at the beginning of the singly linked list • 108
Deleting the node at the end in the singly linked list • 109

You might also like