1. Trang chủ
  2. » Tất cả

221360348-Algorithms-in-Python

218 42 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 218
Dung lượng 5,03 MB

Nội dung

♥ Python and Algorithms ♥ Mari Wahl, mari.wahl9@gmail.com University of New York at Stony Brook May 24, 2013 “There’s nothing to fear but the fear itself That’s called recursion, and that would lead you to infinite fear.” Hello, human! Welcome to my book on Python and algorithms! If you are reading this you probably agree with me that those two can be a lot of fun together (or you might be lost, and in this case I suggest you give it a try anyway!) Also, many of the examples shown here are available in my git repository, together with several other (more advanced) examples for abstract data structures, trees, graphs, and solutions for the Euler Project and the Topcoder website Don’t forget to check them out! This text was written purely for fun (I know, I know, this is a broad definition of the word fun ) with no pretensions for anything big, so please forgive me (or better, let me know) if you find any typo or mistake I am not a computer scientist by formation (I am actually an almost-I-swear-it-is-close-Ph.D in Physics) so this maybe makes things a little less usual (or risky?) I hope you have fun! Mari, Stony Brook, NY Summer/2013 Contents I Flying with Python Numbers 1.1 Integers 1.2 Floats 1.3 Complex Numbers 1.4 The fractions Module 1.5 The decimal Module 1.6 Other Representations 1.7 Additional Exercises 11 11 12 13 14 15 15 16 Built-in Sequence Types 2.1 Strings 2.2 Tuples 2.3 Lists 2.4 Bytes and Byte Arrays 25 27 33 35 43 Collection Data Structures 3.1 Sets 3.2 Dictionaries 3.3 Python’s collection Data Types 3.4 Additional Exercises 45 45 49 54 58 63 63 66 72 79 81 83 Python’s Structure and Modules 4.1 Modules in Python 4.2 Control Flow 4.3 File Handling 4.4 Multiprocessing and Threading 4.5 Error Handling in Python 4.6 Debugging and Profiling CONTENTS 4.7 Unit Testing Object-Oriented Design 5.1 Classes and Objects 5.2 Principles of OOP 5.3 Python Design Patterns 5.4 Additional Exercises II Algorithms are Fun 86 89 90 91 94 96 99 Additional Abstract Data Structures 6.1 Stacks 6.2 Queues 6.3 Deques 6.4 Priority Queues and Heaps 6.5 Linked Lists 6.6 Additional Exercises 101 101 104 108 110 114 120 Asymptotic Analysis 133 7.1 Complexity Classes 133 7.2 Recursion 135 7.3 Runtime in Functions 136 Sorting 8.1 Quadratic Sort 8.2 Linear Sort 8.3 Loglinear Sort 8.4 Comparison Between 8.5 Additional Exercises Sorting Methods 139 139 142 142 148 149 Searching 153 9.1 Sequential Search 153 9.2 Binary Search 154 9.3 Additional Exercises 156 10 Dynamic Programming 163 10.1 Memoization 163 10.2 Additional Exercises 165 CONTENTS III Climbing Graphs and Trees 169 11 Introduction to Graphs 171 11.1 Basic Definitions 171 11.2 The Neighborhood Function 173 11.3 Introduction to Trees 176 12 Binary Trees 12.1 Basic Concepts 12.2 Representing Binary Trees 12.3 Binary Search Trees 12.4 Self-Balancing BST 12.5 Additional Exercises 179 179 179 183 186 193 13 Traversals and Problems on Graphs and Trees 13.1 Depth-First Search 13.2 Breadth-First Search 13.3 Representing Tree Traversals 13.4 Additional Exercises 207 207 208 209 211 CONTENTS Part I Flying with Python

Ngày đăng: 13/04/2019, 01:34