Chapter 1 An Introduction to Computer Science - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Chapter 1 An Introduction to Computer Science

Description:

Step 6: Pull the wheel off the car and place on ground. ... Step 12: Drive safe and get your flat tire repaired. Qingzhao Guo, Spring 2004 ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 15
Provided by: bonita4
Category:

less

Transcript and Presenter's Notes

Title: Chapter 1 An Introduction to Computer Science


1
Chapter 1An Introduction to Computer Science
2
Misconceptions of CS
  • CS is the study of computers
  • Incomplete definition since theory of computers
    was done even before the first computer was
    invented.
  • CS is the study of how to write computer programs
  • The idea of how to solve a problem is more
    important.
  • A program is only a means to an end, not end
    itself.
  • CS is the study of the uses and applications of
    computers and software
  • Many people use software but a computer scientist
    is responsible for specifying, designing,
    building and testing software packages as well as
    computer systems on which they are run.

3
Definition of CS
  • CS is the study of algorithms, including
  • Their formal and mathematical properties(Ch 2
    3)
  • Studying the behavior of algorithms to determine
    whether they are correct and efficient.
  • Their hardware realizations (Ch 4, 5 6)
  • Designing and building computer systems that are
    able to execute algorithms
  • Their linguistic realizations (Ch 7 10)
  • Designing programming languages and translating
    algorithms into these languages so that they can
    be executed by hardware
  • Their applications (Ch 11 14)
  • Identifying important problems and designing
    correct and efficient software packages to solve
    these problems.

4
Algorithms
  • An algorithm is a step by step set of finite
    instructions to accomplish a task.
  • All algorithms are written using one or more of
    these three operations.
  • Sequential Operation Carries out a single well
    defined task. After which it moves on to the
    next instruction. Expressed as simple
    declarative sentences.Eg. Add the value of x to
    1.Eg. Subtract check amount from account
    balance.
  • Conditional operations Question asking
    instructions of an algorithm. Ask and select.Eg.
    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.

5
  • 3. Iterative operations looping instructions
    of an algorithm. They tell us to go back and
    repeat the execution of a previous block of
    instructions.
  • Eg. Repeat Steps 1, 2 and 3 until value of y
    is equal to 1Eg. Repeat the following 5 steps
    until there are no more checks to be processed.

6
Example of how an algorithm looks in plain
English.
  • ALGORITHM TO CHANGE A FLAT TIRE
  • Step 1 Gather your spare tire, lug wrench, jack.
  • Step 2 If car has hubcap, remove it
  • Step 3 Using lug wrench loosen lug nuts. Try
    jumping on lug wrench if difficult to loosen.
    Only loosen, do not remove.
  • Step 4 Position the jack under car and raise the
    jack until it contacts the frame. Extend jack
    until car is about 6 inches off the ground.
  • Step 5 Remove lug nuts from the bolts and put
    them aside.
  • Step 6 Pull the wheel off the car and place on
    ground.
  • Step 7 Position the spare tire directly in front
    of the wheel and align the holes in the center of
    the spare tire with the bolts on the car
  • Step 8 Lift the spare tire and position it on
    the threaded bolts and push the tire onto the car
    until it cannot go any farther
  • Step 9 Replace the lugnuts on the bolts and
    tighten them, but not too tight. Just enough to
    hold the tire in place while you lower the car
  • Step 10 Lower the car with the jack until the
    car is again resting on all four tires
  • Step 11 Tighten all the lugnuts one by one.
  • Step 12 Drive safe and get your flat tire
    repaired.

7
Algorithm to add two m-digit numbers
  • Step 1 Set the value of carry to 0
  • Step 2 Set the value of I equal to value of 0
  • Step 3 Repeat Steps 4 through 6 until I is
    greater than m-1
  • Step 4 Add the two digits ai and bi to the
    current value of
  • carry to get ci
  • Step 5 If ci gt 10 then reset ci to (ci-10)
    and reset the
  • value of carry to 1
  • otherwise set the new
    value of carry to 0.
  • Step 6 Add 1 to I, effectively moving one
    column to the left.
  • Step 7 Set cm to the value of carry.
  • Step 8 Print out the final answer,
    cmcm-1cm-2.c0
  • Step 9 Stop
  • (TRACE WITH 5648)

8
  • Why do we do this complicated technique for a
    simple task of adding two numbers?
  • In order to automate the solution and make our
    life easier.
  • Imagine adding millions of numbers in a few
    seconds or minutes.
  • Computing agent The machine, robot, person or
    thing carrying out the steps of the algorithm is
    called a computing agent.
  • An algorithm should be both correct and
    efficient.

9
  • Not every problem can be solved with an algorithm
  • Sometimes specifying an algorithm is possible but
    the computation would take so long that the
    solution is useless. (eg. the game of chess,
    1028 years)
  • Other times there are problems we dont know how
    to solve (eg. modeling how a baby recognizes and
    learns). Impossible to write an algorithm to
    paint a picture.
  • ALGORITHM ENCODE IN PROGRAMMING LANGUAGE
    AUTOMATED SOLUTION
  • This means we use the machine/computer for its
    speed and power to do these monotonous mundane
    tasks.

10
Formal definition of an Algorithm
  • It is a well ordered collection of unambiguous
    and effectively computable operations that when
    executed produces a result that halts in a finite
    amount of time.
  • Unambiguous one that can be understood and
    carried out directly by the computing agent
    without needing to be further simplified or
    explained. This is called a primitive operation
    or just a primitive.
  • Primitives vary on different machines as well as
    individuals.
  • Effectively computable means that it should be
    doable.
  • E.g. no matter how long you try to flap your
    arms, you wont fly right?E.g. x sqrt(n)
    (What if n lt 0? Then it is undefined)
  • Result Now how do we know if the result we get
    from an algorithm is correct? We observe and
    test various inputs. Note that the algorithm
    should work for all possible valid inputs.
  • Finite means it cannot go on forever. Otherwise
    it will be an infinite loop.

11
Importance of algorithmic problem solving
  • Algorithms are encoded into some appropriate
    language and given to a computing agent to
    execute.
  • This lets us use algorithms to mechanize and
    automate repetitive tasks.
  • People make better use of their time creating
    better algorithms instead of doing the repetitive
    tasks.
  • We use algorithms all the time, baking a cake,
    registering for courses.
  • See page 6 for an algorithm on how to program
    your VCR

12
Problems to think about
  • On Page 23
  • Exercise 3
  • Exercise 4
  • Exercise 7

13
Review
  • Misconceptions of Computer Science
  • The Definition of Computer Science
  • Formal definition of an Algorithm
  • Describe and Identify sequential, iterative and
    conditional operations.
  • Examples of Algorithms
  • Tracing an Algorithm
  • Importance of Algorithmic Problem Solving
  • What is a computing agent? What is an effectively
    computable operation.

14
  • THE END OF CHAPTER 1
Write a Comment
User Comments (0)
About PowerShow.com