19
Computer Science 101 Theory of Computing

Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Embed Size (px)

Citation preview

Page 1: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Computer Science 101

Theory of Computing

Page 2: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Computer Science is . . .

• The study of algorithms, with respect to

– their formal properties

– their linguistic realizations (in programming languages, from Python down to machine code)

– their hardware realizations (machine architecture, logic circuits, transistors)

Page 3: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Things to Desire in an Algorithm

• Correctness

• Maintainability

• Efficiency

Page 4: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Wait, can it be solved?

• There are problems that do not have any algorithmic solution!

• Algorithms are carried out by computing agents

• What can these agents do, and what can’t they do?

Page 5: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

What is a model?

• Models

– Capture the essence of the real thing

– Probably differ in scale from the real thing

– Omit some of the details of the real thing

– Lack the full functionality of the real thing

Page 6: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

A Model of a Computing Agent

• Computing agent should be able to:

– Accept input

– Store information in and retrieve it from memory

– Take actions according to algorithmic instructions

– Produce output

Page 7: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The Turing Machine

• Developed by Alan Turing to demonstrate theoretical properties of computation

• 1935, before real computers

• Still the theoretical basis of computing

Page 8: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The Turing Machine

• Developed by Alan Turing to demonstrate theoretical properties of computation

• 1935, before real computers

• Still the theoretical basis of computing

Page 9: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Components of a TM

• Memory – a paper tape to which symbols can be written or from which they can be read

• States – a set of descriptions of actions to be performed (reading, writing, and moving the read/write head on the tape)

• Alphabet – a set of symbols to be input or output

Page 10: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The TM Tape

Consists of squares in which symbols are written

Extends an infinite distance in both directions (can always buy more tape)

Can read or write a symbol from/to one square at a time

Page 11: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The Read/Write Head and States

At startup, the read/write head (the arrow) is placed next to a square on the tape

State 1 says “if the tape symbol is a 0, write a 1, move one square to the right, and go into state 2”

Page 12: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The Read/Write Head and a State

The change from one state to the next one is called a transition

On each transition, an input symbol is read, an output symbol is written, the read/right head moves left or right, and the machine goes into the next state

Page 13: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

The Read/Write Head and a State

Sometimes, the current state and the next state are the same (like a loop)

Sometimes, the input and output symbols are the same

The alphabet can contain any symbols

Page 14: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

What Can a TM Do?

• Can execute a whole sequence of instructions

• Can accept input

• Can store information in and retrieve it from memory

• Can take actions according to algorithm instructions

• Can produce output

Page 15: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

A Model of an Algorithm

• An algorithm must:– Be a well-ordered collection– Consist of unambiguous and effectively

computable operations– Halt in a finite amount of time– Produce a result

Page 16: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Turing Machine Examples

• Turing machine

– Must begin in state 1 on the leftmost nonblank cell

– Machine state 1 must be a state in which 0s are changed to 1s and 1s are changed to 0s

Page 17: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Bit Inverter

• State diagram

– Visual representation of a Turing machine

algorithm

– Circles represent states, and arrows represent transitions from one state to another

Page 18: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Invert the Bits

This TM needs another transition, which reads a blank, writes a blank, moves left, and goes into State 2

State 2 then has no transitions (no actions), so it’s the halt state

Page 19: Computer Science 101 Theory of Computing. Computer Science is... The study of algorithms, with respect to –their formal properties –their linguistic realizations

Tuple Representation of StatesA state can also be represented as a set of tuples

Each tuple has the form IN OUT NEXT DIR

States for the bit inverter TM:

IN OUT NEXT DIR0 1 1 R1 0 1 Rb b 2 L

State 1

State 2 (halt state)