ebook img

Python Data Structures and Algorithm PDF

303 Pages·2017·11.065 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Python Data Structures and Algorithm

Python Data Structures and Algorithms Improve the performance and speed of your applications Benjamin Baka BIRMINGHAM - MUMBAI Python Data Structures and Algorithms Copyright © 2017 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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. First published: May 2017 Production reference: 1260517 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78646-735-5 www.packtpub.com Credits Author Copy Editor Benjamin Baka Safis Editing Reviewer Project Coordinator David Julian Vaidehi Sawant Commissioning Editor Proofreader Kunal Parikh Safis Editing Acquisition Editor Indexer Denim Pinto Tejal Daruwale Soni Content Development Editor Graphics Zeeyan Pinheiro Abhinash Sahu Technical Editors Production Coordinator Pavan Ramchandani Melwyn Dsa Ketan Kamble About the Author Benjamin Baka works as a software developer and has over 10 years, experience in programming. He is a graduate of Kwame Nkrumah University of Science and Technology and a member of the Linux Accra User Group. Notable in his language toolset are C, C++, Java, Python, and Ruby. He has a huge interest in algorithms and finds them a good intellectual exercise. He is a technology strategist and software engineer at mPedigree Network, weaving together a dizzying array of technologies in combating counterfeiting activities, empowering consumers in Ghana, Nigeria, and Kenya to name a few. In his spare time, he enjoys playing the bass guitar and listening to silence. You can find him on his blog. Many thanks to the team at Packt who have played a major part in bringing this book to light. I would also like to thank David Julian, the reviewer on this book, for all the assistance he extended through diverse means in preparing this book. I am forever indebted to Lorenzo E. Danielson and Guido Sohne for their immense help in ways I can never repay. About the Reviewer David Julian has over 30 years of experience as an IT educator and consultant. He has worked on a diverse range of projects, including assisting with the design of a machine learning system used to optimize agricultural crop production in controlled environments and numerous backend web development and data analysis projects. He has authored the book Designing Machine Learning Systems with Python and worked as a technical reviewer on Sebastian Raschka’s book Python Machine Learning, both by Packt Publishing. www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. https://www.packtpub.com/mapt Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1786467356. If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface 1 Chapter 1: Python Objects, Types, and Expressions 7 Understanding data structures and algorithms 7 Python for data 10 The Python environment 10 Variables and expressions 11 Variable scope 12 Flow control and iteration 12 Overview of data types and objects 13 Strings 14 Lists 17 Functions as first class objects 20 Higher order functions 22 Recursive functions 24 Generators and co-routines 24 Classes and object programming 26 Special methods 28 Inheritance 29 Data encapsulation and properties 30 Summary 31 Chapter 2: Python Data Types and Structures 32 Operations and expressions 32 Boolean operations 32 Comparison and Arithmetic operators 33 Membership, identity, and logical operations 33 Built-in data types 34 None type 35 Numeric Types 35 Representation error 35 Sequences 37 Tuples 38 Dictionaries 39 Sorting dictionaries 41 Dictionaries for text analysis 43 Sets 44 Immutable sets 47 Modules for data structures and algorithms 47 Collections 48 Deques 48 ChainMaps 51 Counter objects 52 Ordered dictionaries 54 defaultdict 55 Named Tuples 56 Arrays 58 Summary 61 Chapter 3: Principles of Algorithm Design 62 Algorithm design paradigms 63 Recursion and backtracking 64 Backtracking 66 Divide and conquer - long multiplication 66 Can we do better? A recursive approach 67 Runtime analysis 70 Asymptotic analysis 78 Big O notation 79 Composing complexity classes 80 Omega notation (Ω) 82 Theta notation (ϴ) 82 Amortized analysis 83 Summary 85 Chapter 4: Lists and Pointer Structures 86 Arrays 87 Pointer structures 88 Nodes 88 Finding endpoints 89 Node 90 Other node types 90 Singly linked lists 92 Singly linked list class 93 Append operation 93 A faster append operation 94 Getting the size of the list 95 Improving list traversal 96 Deleting nodes 96 List search 98 Clearing a list 98 [ ii ]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.