logo资料库

Algorithms.pdf

第1页 / 共435页
第2页 / 共435页
第3页 / 共435页
第4页 / 共435页
第5页 / 共435页
第6页 / 共435页
第7页 / 共435页
第8页 / 共435页
资料共435页,剩余部分请下载后查看
Title Page
Copyright Page
Table of Contents
Introduction
About This Book
Foolish Assumptions
Icons Used in This Book
Beyond the Book
Where to Go from Here
Part 1 Getting Started
Chapter 1 Introducing Algorithms
Describing Algorithms
Defining algorithm uses
Finding algorithms everywhere
Using Computers to Solve Problems
Leveraging modern CPUs and GPUs
Working with special-purpose chips
Leveraging networks
Leveraging available data
Distinguishing between Issues and Solutions
Being correct and efficient
Discovering there is no free lunch
Adapting the strategy to the problem
Describing algorithms in a lingua franca
Facing hard problems
Structuring Data to Obtain a Solution
Understanding a computer’s point of view
Arranging data makes the difference
Chapter 2 Considering Algorithm Design
Starting to Solve a Problem
Modeling real-world problems
Finding solutions and counterexamples
Standing on the shoulders of giants
Dividing and Conquering
Avoiding brute-force solutions
Starting by making it simpler
Breaking down a problem is usually better
Learning that Greed Can Be Good
Applying greedy reasoning
Reaching a good solution
Computing Costs and Following Heuristics
Representing the problem as a space
Going random and being blessed by luck
Using a heuristic and a cost function
Evaluating Algorithms
Simulating using abstract machines
Getting even more abstract
Working with functions
Chapter 3 Using Python to Work with Algorithms
Considering the Benefits of Python
Understanding why this book uses Python
Working with MATLAB
Considering other algorithm testing environments
Looking at the Python Distributions
Obtaining Analytics Anaconda
Considering Enthought Canopy Express
Considering pythonxy
Considering WinPython
Installing Python on Linux
Installing Python on MacOS
Installing Python on Windows
Downloading the Datasets and Example Code
Using Jupyter Notebook
Defining the code repository
Understanding the datasets used in this book
Chapter 4 Introducing Python for Algorithm Programming
Working with Numbers and Logic
Performing variable assignments
Doing arithmetic
Comparing data by using Boolean expressions
Creating and Using Strings
Interacting with Dates
Creating and Using Functions
Creating reusable functions
Calling functions
Using Conditional and Loop Statements
Making decisions using the if statement
Choosing between multiple options using nested decisions
Performing repetitive tasks using the for loop
Using the while statement
Storing Data Using Sets, Lists, and Tuples
Creating sets
Creating lists
Creating and using tuples
Defining Useful Iterators
Indexing Data Using Dictionaries
Chapter 5 Performing Essential Data Manipulations Using Python
Performing Calculations Using Vectors and Matrixes
Understanding scalar and vector operations
Performing vector multiplication
Creating a matrix is the right way to start
Multiplying matrixes
Defining advanced matrix operations
Creating Combinations the Right Way
Distinguishing permutations
Shuffling combinations
Facing repetitions
Getting the Desired Results Using Recursion
Explaining recursion
Eliminating tail call recursion
Performing Tasks More Quickly
Considering divide and conquer
Distinguishing between different possible solutions
Part 2 Understanding the Need to Sort and Search
Chapter 6 Structuring Data
Determining the Need for Structure
Making it easier to see the content
Matching data from various sources
Considering the need for remediation
Stacking and Piling Data in Order
Ordering in stacks
Using queues
Finding data using dictionaries
Working with Trees
Understanding the basics of trees
Building a tree
Representing Relations in a Graph
Going beyond trees
Building graphs
Chapter 7 Arranging and Searching Data
Sorting Data Using Mergesort and Quicksort
Defining why sorting data is important
Ordering data naïvely
Employing better sort techniques
Using Search Trees and the Heap
Considering the need to search effectively
Building a binary search tree
Performing specialized searches using a binary heap
Relying on Hashing
Putting everything into buckets
Avoiding collisions
Creating your own hash function
Part 3 Exploring the World of Graphs
Chapter 8 Understanding Graph Basics
Explaining the Importance of Networks
Considering the essence of a graph
Finding graphs everywhere
Showing the social side of graphs
Understanding subgraphs
Defining How to Draw a Graph
Distinguishing the key attributes
Drawing the graph
Measuring Graph Functionality
Counting edges and vertexes
Computing centrality
Putting a Graph in Numeric Format
Adding a graph to a matrix
Using sparse representations
Using a list to hold a graph
Chapter 9 Reconnecting the Dots
Traversing a Graph Efficiently
Creating the graph
Applying breadth-first search
Applying depth-first search
Determining which application to use
Sorting the Graph Elements
Working on Directed Acyclic Graphs (DAGs)
Relying on topological sorting
Reducing to a Minimum Spanning Tree
Discovering the correct algorithms to use
Introducing priority queues
Leveraging Prim’s algorithm
Testing Kruskal’s algorithm
Determining which algorithm works best
Finding the Shortest Route
Defining what it means to find the shortest path
Explaining Dijkstra’s algorithm
Chapter 10 Discovering Graph Secrets
Envisioning Social Networks as Graphs
Clustering networks in groups
Discovering communities
Navigating a Graph
Counting the degrees of separation
Walking a graph randomly
Chapter 11 Getting the Right Web page
Finding the World in a Search Engine
Searching the Internet for data
Considering how to find the right data
Explaining the PageRank Algorithm
Understanding the reasoning behind the PageRank algorithm
Explaining the nuts and bolts of PageRank
Implementing PageRank
Implementing a Python script
Struggling with a naive implementation
Introducing boredom and teleporting
Looking inside the life of a search engine
Considering other uses of PageRank
Going Beyond the PageRank Paradigm
Introducing semantic queries
Using AI for ranking search results
Part 4 Struggling with Big Data
Chapter 12 Managing Big Data
Transforming Power into Data
Understanding Moore’s implications
Finding data everywhere
Getting algorithms into business
Streaming Flows of Data
Analyzing streams with the right recipe
Reserving the right data
Sketching an Answer from Stream Data
Filtering stream elements by heart
Demonstrating the Bloom filter
Finding the number of distinct elements
Learning to count objects in a stream
Chapter 13 Parallelizing Operations
Managing Immense Amounts of Data
Understanding the parallel paradigm
Distributing files and operations
Employing the MapReduce solution
Working Out Algorithms for MapReduce
Setting up a MapReduce simulation
Inquiring by mapping
Chapter 14 Compressing Data
Making Data Smaller
Understanding encoding
Considering the effects of compression
Choosing a particular kind of compression
Choosing your encoding wisely
Encoding using Huffman compression
Remembering sequences with LZW
Part 5 Challenging Difficult Problems
Chapter 15 Working with Greedy Algorithms
Deciding When It Is Better to Be Greedy
Understanding why greedy is good
Keeping greedy algorithms under control
Considering NP complete problems
Finding Out How Greedy Can Be Useful
Arranging cached computer data
Competing for resources
Revisiting Huffman coding
Chapter 16 Relying on Dynamic Programming
Explaining Dynamic Programming
Obtaining a historical basis
Making problems dynamic
Casting recursion dynamically
Leveraging memoization
Discovering the Best Dynamic Recipes
Looking inside the knapsack
Touring around cities
Approximating string search
Chapter 17 Using Randomized Algorithms
Defining How Randomization Works
Considering why randomization is needed
Understanding how probability works
Understanding distributions
Simulating the use of the Monte Carlo method
Putting Randomness into your Logic
Calculating a median using Quickselect
Doing simulations using Monte Carlo
Ordering faster with Quicksort
Chapter 18 Performing Local Search
Understanding Local Search
Knowing the neighborhood
Presenting local search tricks
Explaining hill climbing with n-queens
Discovering simulated annealing
Avoiding repeats using Tabu Search
Solving satisfiability of Boolean circuits
Solving 2-SAT using randomization
Implementing the Python code
Realizing that the starting point is important
Chapter 19 Employing Linear Programming
Using Linear Functions as a Tool
Grasping the basic math you need
Learning to simplify when planning
Working with geometry using simplex
Understanding the limitations
Using Linear Programming in Practice
Setting up PuLP at home
Optimizing production and revenue
Chapter 20 Considering Heuristics
Differentiating Heuristics
Considering the goals of heuristics
Going from genetic to AI
Routing Robots Using Heuristics
Scouting in unknown territories
Using distance measures as heuristics
Explaining Path Finding Algorithms
Creating a maze
Looking for a quick best-first route
Going heuristically around by A*
Part 6 The Part of Tens
Chapter 21 Ten Algorithms That Are Changing the World
Using Sort Routines
Looking for Things with Search Routines
Shaking Things Up with Random Numbers
Performing Data Compression
Keeping Data Secret
Changing the Data Domain
Analyzing Links
Spotting Data Patterns
Dealing with Automation and Automatic Responses
Creating Unique Identifiers
Chapter 22 Ten Algorithmic Problems Yet to Solve
Dealing with Text Searches
Differentiating Words
Determining Whether an Application Will End
Creating and Using One-Way Functions
Multiplying Really Large Numbers
Dividing a Resource Equally
Reducing Edit Distance Calculation Time
Solving Problems Quickly
Playing the Parity Game
Understanding Spatial Issues
Index
EULA
Algorithms by John Paul Mueller and Luca Massaron
Algorithms For Dummies® Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright © 2017 by John Wiley & Sons, Inc., Hoboken, New Jersey Media and software compilation copyright © 2017 by John Wiley & Sons, Inc. All rights reserved. Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE.  NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT.  NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM.  THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit https://hub.wiley.com/community/support/dummies. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2017936606 ISBN 978-1-119-33049-3 (pbk); ISBN 978-1-119-33053-0 (ebk); ISBN 978-1-119-33052-3 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1
Contents at a Glance Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Part 1: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 CHAPTER 1: Introducing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CHAPTER 2: Considering Algorithm Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 CHAPTER 3: Using Python to Work with Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 CHAPTER 4: Introducing Python for Algorithm Programming . . . . . . . . . . . . . . . . . . . 67 CHAPTER 5: Performing Essential Data Manipulations Using Python . . . . . . . . . . . . . 91 Part 2: Understanding the Need to Sort and Search . . . . . . 113 CHAPTER 6: Structuring Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 CHAPTER 7: Arranging and Searching Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Part 3: Exploring the World of Graphs . . . . . . . . . . . . . . . . . . . . . . . 153 CHAPTER 8: Understanding Graph Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 CHAPTER 9: Reconnecting the Dots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 CHAPTER 10: Discovering Graph Secrets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 CHAPTER 11: Getting the Right Web page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Part 4: Struggling with Big Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 CHAPTER 12: Managing Big Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 CHAPTER 13: Parallelizing Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 CHAPTER 14: Compressing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Part 5: Challenging Difficult Problems . . . . . . . . . . . . . . . . . . . . . . . 281 CHAPTER 15: Working with Greedy Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 CHAPTER 16: Relying on Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 CHAPTER 17: Using Randomized Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 CHAPTER 18: Performing Local Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 CHAPTER 19: Employing Linear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 CHAPTER 20: Considering Heuristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Part 6: The Part of Tens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 CHAPTER 21: Ten Algorithms That Are Changing the World . . . . . . . . . . . . . . . . . . . . . 391 CHAPTER 22: Ten Algorithmic Problems Yet to Solve . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Table of Contents INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Foolish Assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Icons Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Beyond the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 PART 1: GETTING STARTED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 CHAPTER 1: Introducing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Describing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Defining algorithm uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Finding algorithms everywhere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Using Computers to Solve Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Leveraging modern CPUs and GPUs . . . . . . . . . . . . . . . . . . . . . . . . . 16 Working with special-purpose chips . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Leveraging networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Leveraging available data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Distinguishing between Issues and Solutions . . . . . . . . . . . . . . . . . . . . . 19 Being correct and efficient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Discovering there is no free lunch . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Adapting the strategy to the problem . . . . . . . . . . . . . . . . . . . . . . . . 20 Describing algorithms in a lingua franca . . . . . . . . . . . . . . . . . . . . . . 20 Facing hard problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Structuring Data to Obtain a Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Understanding a computer’s point of view . . . . . . . . . . . . . . . . . . . . 22 Arranging data makes the difference . . . . . . . . . . . . . . . . . . . . . . . . . 22 CHAPTER 2: Considering Algorithm Design . . . . . . . . . . . . . . . . . . . . . . . . 23 Starting to Solve a Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Modeling real-world problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Finding solutions and counterexamples . . . . . . . . . . . . . . . . . . . . . . 26 Standing on the shoulders of giants . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Dividing and Conquering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Avoiding brute-force solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Starting by making it simpler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Breaking down a problem is usually better . . . . . . . . . . . . . . . . . . . . 30 Learning that Greed Can Be Good . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Applying greedy reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31 Reaching a good solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Table of Contents v
Computing Costs and Following Heuristics . . . . . . . . . . . . . . . . . . . . . . . 33 Representing the problem as a space . . . . . . . . . . . . . . . . . . . . . . . . 33 Going random and being blessed by luck . . . . . . . . . . . . . . . . . . . . . 34 Using a heuristic and a cost function . . . . . . . . . . . . . . . . . . . . . . . . . 35 Evaluating Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Simulating using abstract machines . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Getting even more abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Working with functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 CHAPTER 3: Using Python to Work with Algorithms . . . . . . . . . . . . . . 43 Considering the Benefits of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Understanding why this book uses Python . . . . . . . . . . . . . . . . . . . . 45 Working with MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Considering other algorithm testing environments . . . . . . . . . . . . . 48 Looking at the Python Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Obtaining Analytics Anaconda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Considering Enthought Canopy Express . . . . . . . . . . . . . . . . . . . . . . 50 Considering pythonxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Considering WinPython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Installing Python on Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Installing Python on MacOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Installing Python on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Downloading the Datasets and Example Code . . . . . . . . . . . . . . . . . . . . 58 Using Jupyter Notebook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Defining the code repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Understanding the datasets used in this book . . . . . . . . . . . . . . . . . 65 CHAPTER 4: Introducing Python for Algorithm Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Working with Numbers and Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Performing variable assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Doing arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Comparing data by using Boolean expressions . . . . . . . . . . . . . . . . 72 Creating and Using Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Interacting with Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Creating and Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Creating reusable functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Calling functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Using Conditional and Loop Statements . . . . . . . . . . . . . . . . . . . . . . . . . 81 Making decisions using the if statement . . . . . . . . . . . . . . . . . . . . . . 81 Choosing between multiple options using nested decisions . . . . . 82 Performing repetitive tasks using the for loop . . . . . . . . . . . . . . . . . 83 Using the while statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Storing Data Using Sets, Lists, and Tuples . . . . . . . . . . . . . . . . . . . . . . . . 85 vi Algorithms For Dummies
分享到:
收藏