Title: An Introduction to Computer Science
1An Introduction to Computer Science
2Outline
- Misconceptions of Computer Science
- The Definition of Computer Science
- Algorithms
- Conclusion
3Introduction
4Misconceptions about CS (I)
- Computer Science is the study of computers
- Some earliest and most fundamental theoretical
work in CS took place during 1920 1940 (before
the development of computers) - Theoretical CS study the logical and
mathematical properties of problems and their
solutions (formal model) - CS is no more about computers than astronomy is
about telescopes, biology is about microscopes,
or chemistry is about beakers and test tubes.
Science is not about tools. It is about how we
use them, and what we find out when we do
5Misconceptions about CS (II)
- Computer Science is the study of how to write
computer programs - Programming is a tool by which researchers can
study new ideas and build and test new solutions - When a computer scientist has designed and
analyzed a new approach to solving a problem or
has created a new way to represent information,
then he will implement that idea as a computer
program in order to test it on an actual computer
system - Permit researchers to see how well these new
ideas work and whether they perform better than
previous methods - How much memory and time is required?
6Misconceptions about CS (II) (Cont.)
- Computer Science is the study of how to write
computer programs - In CS, it is not only the construction of a
high-quality program that is important, but also
the methods it embodies, the services it
provides, and the results it produces. - A program is only a means to an end, not an end
in itself - ????????
- ???????????,???????
7Misconceptions about CS (III)
- Computer Science is the study of the uses and
applications of computers and software - Word, Excel?
- A lot of people use software, but
- Computer scientist is responsible for specifying,
designing, building and testing software packages
as well as the computer systems on which they run.
8Definition of Computer Science
9Computer Science
- Computer Science is the study of algorithms,
including - Their formal and mathematical properties
- Study the behavior of algorithms to determine
whether they are correct and efficient - Their hardware realizations
- Design and build computer systems that are able
to execute algorithms - Their linguistic realizations
- Design programming languages and translating
algorithms into these languages so that they can
be executed by the hardware - Their applications
- Identify important problems and design correct
and efficient software packages to solve these
poroblems
10Whats An Algorithm?
Algorithm is everywhere, not only in CS
- Dictionary definition a procedure for solving a
mathematical problem in a finite number of steps
that frequently involves repetition of an
operation broadly a step-by-step method for
accomplishing some task - Informal definition an ordered sequence of
instructions (operations) that is guaranteed to
solve a specific problem - Step 1 Do something
- Step 2 Do something
- Step 3 Do something
-
- Step N Stop, you are finished
Operations
11Operations In An Algorithm (I)
- A sequential operation carries out a single
well-defined task. When that task is finished,
the algorithm moves on to the next operation. - Add 1 cup of butter to the mixture in the bowl
- Set the value of x to 1
- A conditional operation is the question-asking
instructions of an algorithm. It asks a question
and then select the next operation to be executed
according to the question answer - If the mixture is too dry, then add 0.5 cup of
water to the bowl - If x is not equal to 0, then set y equal to 1/x
otherwise, print an error message that says we
cannot divide by 0
12Operations In An Algorithm (II)
- An Iterative operation is a looping instruction
of an algorithm. It tells us not to go on to the
next instruction, but, instead, to go back and
repeat the execution of a pervious block of
instructions - Repeat the previous two operations until the
mixture has thickened - Repeat steps 1, 2, and 3 until the value of y is
equal to 1
When you want to command a computer to execution
your algorithm, you have to convert your
algorithm into a programming language.
13Algorithm for Programming Your VCR
Which instructions are sequential, conditional,
and iterative?
14Algorithm for Adding Two m-Digit Numbers
Which instructions are sequential, conditional,
and iterative?
15Algorithm for Adding Two m-Digit Numbers (Demo)
- Add (47 25)
- m2
- a14 a07
- b12 b05
- Step 1 carry0
- Step 2 i0
- Step 3 repeat 4-6, until i gt 1
- First iteration (i has the value 0)
- 4 Add (a0b0carry) ? c012
- 5 c0 gt 10 ? c02, carry1
- 6 Reset i to (01)1. Because i is not greater
than 1, go back to step 4
- Second iteration (i has the value 1)
- 4 Add (a1b1carry) ? c17
- 5 c1 lt 10 ? reset carry to 0
- 6 Reset i to (11)2. Because i is greater than
1, do not repeat but go to step 7 - Step 7 set c20 (cmcarry)
- Step 8 Print out the answerc2 c1 c0 072
- Step 9 Stop
??????,?????????
16Algorithm for Adding Two m-Digit Numbers (Demo)
i 0carry 0
i 1carry 1
Step 7
c2carry0
1 0
1 0
Step 8
a 4 7 b 2 5
a 4 7 b 2 5
c2 c1 c0 072
2
c
2
c
7
c0a0b0carry75012 c0 gt 10 ?
c012-102 carry 1
c1a1b1carry4217 c1 lt 10 ? c1 does not
change carry 0
First Iteration (i0)
Second Iteration (i1)
17Why Are Formal Algorithms So Important in CS?
- If we can specify an algorithm to solve a
problem, then we can automate its solution
(convert it into a program) - Computer Science ? the science of algorithmic
problem solving - Discover correct and efficient algorithms for a
wide range of interesting problems, studying
their properties, designing programming languages
into which those algorithms can be encoded, and
designing and building computer systems that can
automatically executed these algorithms in an
efficient manner
18Algorithms
19Formal Definition of An Algorithm
- An Algorithm is a well-ordered collection of
unambiguous and effectively computable operations
that, when executed, produces a result and halts
in a finite amount of time - Is the following an algorithm?
- Step 1 Wet hair
- Step 2 Lather
- Step 3 Rinse
- Step 4 Repeat
20a well-ordered collection
- Clear and un-ambiguous ordering to these
operations - Whats the next operation when we finish any one
operation? - At step 4, what operations should be repeated?
- Ambiguous ordering
- Go back and do it again
- Go back to step 3 and begin execution from that
point - Start over
- Start over from step 1
- If you understand this material, you may skip
ahead - If you understand this material, skip ahead to
line 21
??????,????????????!
21of unambiguous and effectively computable
operations
- An unambiguous operation is one that can be
understood and carried out directly by the
computing agent without needing to be further
simplified or explained - Primitive (operation)
- Effectively computable or doable operation
- There exists a computational process that allows
the computing agent to complete that operation
successfully
?????????????????! Sigh ????,??????
22of unambiguous and effectively computable
operations (Cont.)
- Step 1 Make the crust
- Step 2 Make the cherry filling
- Step 3 Pour the filling into the crust
- Step 4 Bake at 350F for 45 minutes
- Step 1 Make the crust
- 1.1 Take one and one-third cups flour
- 1.2 Sift the flour
- 1.3 Mix the sifted flour with one-half cup butter
and one-fourth cup water - Roll into two 9-inch pie crusts
- Step 2 make the cherry filling
- 2.1 open a 16-ounce can of cherry pie filling and
pour into the bowl - 2.2 add a dash of cinnamon and nutmeg, and stir
Algorithm for making a cherry pie
23of unambiguous and effectively computable
operations (Cont.)
- Which of the following are primitive operations
for a computer? - Add x and y to get the sum z
- See whether x is greater than, equal to, or less
than y - Sort a list of names into alphabetical order
- Factor an arbitrary integer into all of its prime
factors - Make a cherry pie
24of unambiguous and effectively computable
operations (Cont.)
- Find and Print out the 100th prime number
- Step 1 generate a list L of all the prime
numbers - Step 2 Sort the list L into ascending order
- Step 3 Print out the 100th element in the list
- Step 4 Stop
- Write out the exact decimal value of ?
- ? cannot be represented exactly
- Set Average to Sum/Number
- What if number 0
- Set the value of result to
- What if N lt 0
- Add 1 to the current value of x
- What if x currently has no value
25 that produces a result
- In order to know whether a solution is correct,
an algorithm must produce a result that is
observable to a user - What are the results of the VCR algorithm,
addition algorithms, cherry-pie making algorithm? - Sometimes it is not possible for an algorithm to
produce the correct answer because for a given
set of input, a correct answer does not exist - Error messages (result) should be produced instead
26 and halts in a finite amount of time
- The result must be produced after the execution
of a finite number of operations, and we must
guarantee that algorithm eventually reaches a
statement that says Stop, you are done - The original shampooing algorithm does not stop
27Algorithm for Shampooing Your Hair
- Wet your hair
- Set the value of WashCount to 0
- Repeat Steps 4 through 6 until the value of
WashCount equals 2 - Lather your hair
- Rinse your hair
- Add 1 to the value of WashCount
- Stop, you have finished shampooing your hair
28Alternative Algorithm for Shampooing Your Hair
- Wet your hair
- Lather your hair
- Rinse your hair
- Lather your hair
- Rinse your hair
- Stop, you have finished shampooing your hair
29Can every problem be solved algorithmically?
- There are problems for which no generalized
algorithmic solution can possibly exist
(unsolvable) - There are also problems where it is possible to
specify an algorithm, but it would take a
computing agent so long to execute that the
solution is essentially useless - Brute force algorithm for get a computer to play
winning chess ? examine every legal move and
response - There are problems that we dont know how to
solve algorithmically
30Conclusion
- Computer Science is the study of algorithms,
including - Their formal and mathematical properties
- Study the behavior of algorithms to determine
whether they are correct and efficient - Their hardware realizations
- Binary numbers, boolean logics, gates, and
computer organization (memory, cache, I/O, ALU,
Control) - Their linguistic realizations
- Programming Languages, Data Structures,
Object-oriented - Compiler
- Their applications
- Spreadsheet, computer networks, artificial
intelligence