






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An understanding of 'back of the envelope' estimates, a problem-solving technique used in Computer Science to make rapid estimates, eliminate candidate solutions, establish feasibility, and sketch out potential trade-offs. The technique involves finding the connection between givens and results, making plans, carrying out the plan, and examining the result.
What you will learn
Typology: Summaries
1 / 11
This page cannot be seen from the preview
Don't miss anything!
CompSci 001
5.
CompSci 001
G. Polya. Programming is a strenuous exercise in problem solving
(^) How to Solve It,
(^) nd
ed., Princeton University Press, 1957.^
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
Make a plan
Find the connection between givens and result
What kind of problem is it? Is it familiar?
Think about generalizations, specializations, variants
Carry out the plan
Check each step
Examine the result
Does it make sense?
CompSci 001
5.
Jon Bentley.
Programming Pearls.
2 nd
edition. A-W, 2000.^
http://www.vendian.org/envelope/
Engineering technique to approximate and check answers
Two answers are better than one
Quick checks
Rules of thumb
Practice
True?Ad claims that salesperson drove 100,000 miles in a year.
claim?coin has “an average life of 30 years.” How can you check thatNewspaper article states that a United States quarter dollar
CompSci 001
Often need to make rapid estimates
to eliminate candidate solutions
establish feasibility
sketch out potential trade-offs
Most remember key numbers related to their field, not every detail
Hence we need to estimate
which
numbers are important
values
(^) of numbers needed
how
to perform the calculation
Emphasis is on “order of magnitude” estimates
to nearest factor of 10 (or 2)
CompSci 001
5.
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
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
Use orders of magnitude as brackets to find reasonable range
CompSci 001
Approximately how many people are in New York City?
10,000,
Does every individual own a piano?
No
Reasonable to assert “individuals do not own pianos; families do”?
Yes
About how many families are there in a city of 10 million people?
Perhaps there are 2,000,000 families
Does every family own a piano?
No
Perhaps one out of every five does
That would mean there are about 400,000 pianos in NYC
CompSci 001
5.
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
then there are 400,000 every yearAssume "on the average" every piano gets tuned once a year,
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
How many piano tuners are needed in NYC?
Number of tuners is approximately 400,000/800 or 500
CompSci 001
“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
Piano Tuner example
# tuners = # pianos x # repairs / # repairs per day x # daysFormula:
#working days ~= 200 (5 x 50 – vacation, sickness)# repairs per day ~= 4# repairs ~= 1 per piano (some many, some none)# pianos ~= 400,000 (20% of 2,000,000 families own pianos)Estimates
# tuners ~= (400,000 x 1) / (4 x 200) = 500Calculation
CompSci 001
5.
Socrates, from Diogenes Laertius, Lives of Eminent Philosophers
CompSci 001
expressed More easily
preciseMore
CompSci 001
5.
CompSci 001
CompSci 001
5.
CompSci 001
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.
Is this class full?
Is there a time conflict?
Num Classes >= 4?
More classes on list?
CompSci 001
5.
Assign a value to a variable
Call a method
Arithmetic operation
Comparing two numbers
Indexing into an array
Following an object reference
Returning from a method
CompSci 001
Any computing algorithm will have AT MOST five
kinds of components:
abstraction, i.e., grouping related components
CompSci 001
5.
systems are involvedA distributed system is one where multiple separate computer
Electronic card catalogs
The web
Java was designed for the web
lives?Question: What are examples of a distributed task in your
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
Java a
high-level language
native tongue, machine languageHigh-level languages must be translated to a computer’s
and runintermediate form and then converted to machine languageInterpreted high-level languages are translated to an
Why?
We’ll learn more about this later
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
5.
reasonablyPrograms will have errors, but a good program degrades
down with itdo, but it should not bring down other unrelated programsA robust program may not do exactly what it is supposed to
have seen?Question: Give me an example of a non-robust program you
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
computer cannot be read or compromisedSecurity: techniques that ensure that data stored on a
from erasing all of your data, accidentally or otherwise?A program is running on your computer. What is to stop it
Question: Is Java really all that secure?
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
5.
particular type of computer architecturesA language is architecture-neutral if it does not prefer a
run faster on one than an other.weaknesses. It is not too hard to construct a program that will(x86-Pentium) family have their own respective strengths andE.g. The Macintosh processor family (PowerPC) and the PC
thoughA particular program is never entirely architecture neutral
Question: When is being architecturally neutral a bad thing?
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
many different computer systemsA program is portable if it will work the same (roughly) on
HTML is also platform-independent or portable
A whole lot of effort is currently spent
porting
(^) non-portable
code
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
5.
Performance: speed in completing some task
manufacturers.Performance is everything to most computer and software
Story:
could drive across country in 5 minutes for $35.industry, one would be able to now buy a Roll Royce thatIf the transportation industry kept up with the computer
Rebuttal:
It would crash once a week, killing everyone on board.
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
independently of its other partsA thread is a part of the program that can operate
Multi-threaded programs can do multiple things at once
other web pagese.g. download a file from the web while still looking at
at the same time?Question: What is the problem with multiple agents working
Synchronization
dynamic language.”portable, high performance, multi-threaded, andinterpreted, robust, secure, architecture-neutral, “Java is a simple, object-oriented, distributed,
CompSci 001
5.
Need a precise notation of syntax of a language
Grammars can be used for generation and also can be used
Context-free grammars
can be generated this waySubstitute as many times as necessary. All legal statements
Want
person
=
firstn
+
"
"
+
lastn;
How
do
we
get
this
from
our
grammar?
CompSci 001
Need a set of rules
Our first one was a good start:
any string of alphanumeric symbols that
begins with a letter
Let’s add something to define a simple statement:
= (^)
;
And then work on the details:
<oth-expression>
<string-expression>
=>
=>
” any sequence of charcters
”
CompSci 001
5.
Now have enough to generate a statement like:
(^) msg =
“hello”;
Start with:
(^)
Then using:
(^) any string of alphanumeric symbols that begins
with a letter
msg
<oth-expression>Then, using:
msg
(^) <string-expression>
Using: <string-expression> =>
msg =
(^)
Using:
any sequence of charcters
msg = ”hello” ;
CompSci 001
Including more rules to describe programs we have: 1.
(^) any string of alphanumeric symbols that begins with a letter
2.
(^)
3.
(^) new
(^)
4.
5.
(^) possibly empty list of
(^)
s separated
(^) by
commas
6.
expression>
7.
<string-expression> => <string-expression>
<string-expression>
8.
<string-expression> =>
9.
any sequence of characters
10.
CompSci 001
5.
Use this to generate:
person
=
firstn
”
”
lastn;
CompSci 001
5.
Why go through the process we went through?
grammarShows that desired statement can be generated from this
Actually
proves
(^) that the statement is grammatically correct!
Same rigor as a mathematical proof
(Doesn’t prove that logic is correct, though)
covered so farActually need more rules to handle the level of Java we’ve
Summary of rules shown on pages 78-79 of
(^) Great Ideas
Also give an example
for a complete applet
Too long to go through in class – Please Read!