CompSci 001 3.1 Today’s topics Networks and the Internet Problem Solving Pseudocode Upcoming ä Programming language syntax ä Python Reading Brookshear,

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 2.
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Efficiency of Algorithms
The Efficiency of Algorithms
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 10 Algorithmic Thinking. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives List the five essential.
MTH070 Elementary Algebra Chapter 1 Review of Real Numbers and Problem Solving Copyright © 2010 by Ron Wallace, all rights reserved.
Efficiency of Algorithms
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Chapter 2: Algorithm Discovery and Design
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
CS107 Introduction to Computer Science Lecture 2.
CSE 830: Design and Theory of Algorithms
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 9: Algorithms and Pseudo-code.
Introduction to a Programming Environment
Chapter 1 Program Design
SASE Contextualised group work – teaching a broader mathematics curriculum to first year science students: Case study – Problem solving Jo-ann Larkins.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Test Preparation Strategies
Algebra Problems… Solutions
Adapted from slides by Marie desJardins
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
The Node Voltage Method
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Sullivan – Fundamentals of Statistics – 2 nd Edition – Chapter 9 Section 1 – Slide 1 of 39 Chapter 9 Section 1 The Logic in Constructing Confidence Intervals.
Unultiplying Whole Numbers © Math As A Second Language All Rights Reserved next #5 Taking the Fear out of Math 81 ÷ 9 Division.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Misunderstood Minds 1.
CompSci Today’s topics Designing and Implementing Algorithms Problem solving Pseudocode Java Syntax and Grammars Upcoming More Java Acknowledgements.
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
Extending the Definition of Exponents © Math As A Second Language All Rights Reserved next #10 Taking the Fear out of Math 2 -8.
The Algorithmic Model. What is Computer Science What is Programming Algorithms –Definition –Properties of Good Algorithms –Describing Algorithms –Examples.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
1 Analysis of Algorithms CS 105 Introduction to Data Structures and Algorithms.
Introduction to Algorithms. What is Computer Science? Computer Science is the study of computers (??) This leaves aside the theoretical work in CS, which.
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
Thursday, May 9 Heuristic Search: methods for solving difficult optimization problems Handouts: Lecture Notes See the introduction to the paper.
CPS Topics l Networks revisited l Java intro l Decision Trees l Problem solving and computing with numbers l Upcoming ä Numeric computation Course.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
Chapter 10 Algorithmic Thinking. Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the.
Who is This Fermi and Why Does He Ask Questions? Throughout his work, Fermi was legendary for being able to figure out things in his head, using information.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Searching Topics Sequential Search Binary Search.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
CompSci Today’s topics Problem Solving Pseudocode Notes from Zachary Dodds’ CS 5 course at Harvey Mudd Upcoming ä More Python Reading Brookshear,
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
CPS Today’s topics l Algorithms and pseudocode l Notes adapted from Marti Hearst at UC Berkeley and David Smith at Georgia Tech Upcoming ä Beginning.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Advanced Algorithms Analysis and Design
CS1010 Programming Methodology
Fermi Questions Enrico Fermi.
Objective of This Course
Algorithm Discovery and Design
Algorithms and Problem Solving
Algorithms vs. Programming
Algorithms vs. Programming
Presentation transcript:

CompSci Today’s topics Networks and the Internet Problem Solving Pseudocode Upcoming ä Programming language syntax ä Python Reading Brookshear, Chapter 4

CompSci The Internet l Domain Name System: translates betweens names and IP addresses l Properties of the Internet ä Heterogeneity ä Redundancy ä Packet-switched ä 604 million online (CIA World Factbook 2002) l What country has the highest percentage of people online? 1. Aruba 2. Australia 3. Denmark 4. Hong Kong 5. Iceland 6. South Africa 7. South Korea 8. Sweden 9. UK 10. USA

CompSci Ethernet l Invented by Dr. Robert Metcalfe in 1970 at Xerox Palo Alto Research Center l Allows group of computers to communicate in Local Area Network

CompSci An Internet Ethernet 2 Ethernet Ace Network Red

CompSci Network transfers l A network transfer is the passage of a message from one network to another through a gateway machine. l We wish to connect 100 machines having 2 network controllers each. l Each network has at most 4 computers on it. l How many computers can a message reach without leaving the 2 networks the originating computer is attached to? l How many networks can a message reach in after 1 network transfer or 2 network transfers? l How many network transfers are necessary to reach 100 computers or 1024 computers?

CompSci Problem Solving Programming is a strenuous exercise in problem solving G. Polya. How to Solve It, 2 nd ed., Princeton University Press, l Understand the problem ä What are its parts? unknown, data, condition ä Does the problem make sense? Is it feasible? ä Think about the problem, get a sense of what it needs l Make a plan ä Find the connection between givens and result ä What kind of problem is it? Is it familiar? ä Think about generalizations, specializations, variants l Carry out the plan ä Check each step l Examine the result ä Does it make sense?

CompSci Are problem solving skills primarily domain-specific? You’re first told: A fortress surrounded by a moat is connected to land by numerous narrow bridges. An attacking army successfully captures the fortress by sending only a few soldiers across each bridge, converging upon it simultaneously. l Then you’re asked: A patient has a cancerous tumor. Beams of radiation will destroy the tumor, but in high doses will also destroy healthy tissue surrounding the tumor. How can you use radiation to safely eradicate the tumor? Do the skills transfer between subjects? Is a good math problem solver a good computer science problem solver? How about English to Physics?

CompSci Programming and Problem Solving l Latin school movement in the 1600s ä Teach proper habits of the mind ä Thorndike’s classic “transfer of training” studies found that learning Latin did not produce strong transfer to other domains l Programming teaches problem solving movement of late 1900s ä Seymour Papert, 1980, In learning to program, “powerful intellectual skills are learned in the process  The activity of programming computers is fundamentally an exercise in problem solving. The program represents the solution to some problem and the execution behavior of that program becomes a means to judge, unemotionally, the success of the problem solution. ä Programming is a strenuous exercise in problem solving post hoc, ergo propter hoc.

CompSci Back of the envelope calculations Jon Bentley. Programming Pearls. 2 nd edition. A-W, l Engineering technique to approximate and check answers ä Two answers are better than one ä Quick checks ä Rules of thumb ä Practice l Ad claims that salesperson drove 100,000 miles in a year. True? l Newspaper article states that a United States quarter dollar coin has “an average life of 30 years.” How can you check that claim?

CompSci Why “back of the envelope” estimates? l Often need to make rapid estimates ä to eliminate candidate solutions ä establish feasibility ä sketch out potential trade-offs l Most remember key numbers related to their field, not every detail l Hence we need to estimate ä which numbers are important ä values of numbers needed ä how to perform the calculation l Emphasis is on “order of magnitude” estimates ä to nearest factor of 10 (or 2)

CompSci Orders of Magnitude l How far away is home? Is it more like 1, or 10, or 100 miles? ä Probably do not know exactly ä Is it approximately "a couple", or "a few", or "a lot” ä Estimate based on powers rather than multiples of 10 l How tall is your dorm? More like 1, 10, 100, 1000 feet? ä 1 foot tall is like a doll house, so that’s out ä What do we know that is about 10 feet big? Hmm... People ä If building is a couple of people high, 10 sounds good. ä But that means 1000, would be 100 people high, so that’s out ä So 10 or 100 depending on how many people tall the building is l Use orders of magnitude as brackets to find reasonable range

CompSci Example: How many piano tuners in NYC l Approximately how many people are in New York City? ä 10,000,000 l Does every individual own a piano? ä No l Reasonable to assert “individuals do not own pianos; families do”? ä Yes l About how many families are there in a city of 10 million people? ä Perhaps there are 2,000,000 families l Does every family own a piano? ä No l Perhaps one out of every five does ä That would mean there are about 400,000 pianos in NYC

CompSci Example: Piano Tuners continued l How many piano tuners are needed for 400,000 pianos? ä Some people never get around to tuning their piano ä Some people tune their piano every month ä Assume "on the average" every piano gets tuned once a year, then there are 400,000 every year l How many piano tunings can one piano tuner do? ä Assume that average piano tuner can tune four pianos a day ä Assume that there are 200 working days per year ä That means every tuner can tune about 800 pianos per year l How many piano tuners are needed in NYC? ä Number of tuners is approximately 400,000/800 or 500

CompSci Example: Piano Tuners summary l “Back of the Envelope” estimates have ä Formulas: provide roadmap to upcoming calculations ä Estimates: brief justification of approximations in formula ä Calculations: estimates and known facts are use in formula l Piano Tuner example ä Formula: # tuners = # pianos x # repairs / # repairs per day x # days ä Estimates # pianos ~= 400,000 (20% of 2,000,000 families own pianos) # repairs ~= 1 per piano (some many, some none) # repairs per day ~= 4 #working days ~= 200 (5 x 50 – vacation, sickness) ä Calculation # tuners ~= (400,000 x 1) / (4 x 200) = 500

CompSci Estimation General Principles l Recall Einstein's famous advice ä Everything should be made as simple as possible, but no simpler l Do not worry about constant factors of 2, π, etc. ä Round to “easy” number or nearest order of magnitude l Guess numbers you do not know ä Within bounds of common sense (accuracy increases with experience) l Adjust geometry, etc., to suit you ä Assume a cow is spherical if it helps l Extrapolate from what you do know ä Use ratios to assume unknown value is similar to known quantity l Apply a ‘plausibility’ filter ä If answer seems unbelievable, it probably is ä Can usually set range of reasonable values that indicates major mistake (e.g., speed cannot be faster than light!)

CompSci What’s wrong with this algorithm? (From back of shampoo bottle) Directions: Wet Hair Apply a small amount of shampoo Lather Rinse Repeat

CompSci Properties of good algorithms l Good algorithms must be ä Correct ä Complete ä Precise ä Unambiguous l And should be ä Efficient ä Simple ä Contain levels of abstraction

CompSci Algorithms l Hand-waving not allowed! l Specifying algorithms requires you to say what is really involved in making it work. l Example: ä How does a computer work? ä Hand-wave: zeros & ones ä Real answer: see later part of class. l You learn to know when you don’t know ä “I know nothing except the fact of my ignorance.” ä Socrates, from Diogenes Laertius, Lives of Eminent Philosophers

CompSci Describing Algorithms Pictures Natural language (English) Pseudo-code Specific high-level programming language More easily expressed More precise

CompSci Pseudocode l A shorthand for specifying algorithms l Leaves out the implementation details l Leaves in the essence of the algorithm l What does this algorithm do? l How many times does it print Hello? <

CompSci Sequential search

CompSci Picking courses 1.Make a list of courses you want to register for, in order of priority 2.Start with empty schedule. Number of courses = 0. 3.Choose highest priority class on list. 4.If the chosen class is not full and its class time does not conflict with classes already scheduled, then register for the class (2 steps): 1.Add the class to the schedule 2.Increment the number of classes scheduled 5.Cross that class off of your list. 6.Repeat steps 3 through 5 until the number of classes scheduled is >= 4, or until all classes have been crossed out. 7.Stop.

CompSci Flowcharts End Begin Make list of classes you want to take Num Classes = 0 Choose highest priority class on list Add the class to your schedule. Increment Num Classes. Cross the class off your list. yes no Is this class full? Is there a time conflict? Num Classes >= 4? More classes on list? yes no

CompSci Programming Primitive Operations l Assign a value to a variable l Call a method l Arithmetic operation l Comparing two numbers l Indexing into an array l Following an object reference l Returning from a method

CompSci Components of Computing Algorithms Any computing algorithm will have AT MOST five kinds of components: Data structures to hold data Instructions change data values Conditional expressions to make decisions Control structures to act on decisions Modules to make the algorithm manageable by abstraction, i.e., grouping related components

CompSci Game l 10 coins ä You and a friend have a stack of 10 coins ä On each person’s turn, they remove either 1 or 2 coins from the stack ä The person who removes the last coin wins. ä Can you win? l 10 coins with a twist ä 10 coins, can now ALSO place 1 or 2 coins back on the stack ä Person who removes last coin wins ä Should you go first or second, and what’s your strategy