ch. 10 fit5, cis 110 13f

28
Chapter 10 Algorithmic Thinking Read pp. 291-304 only. Wednesday, April 9, 14

Upload: mh-108

Post on 24-Dec-2014

402 views

Category:

Education


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Ch. 10 FIT5, CIS 110 13F

Chapter 10Algorithmic Thinking

Read pp. 291-304 only.

Wednesday, April 9, 14

Page 2: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Learning Objectives• Learning to code is one of the best career choices you

can make today. But it's more than just a valuable job skill.

• Coding, and the computational thinking skills developed through coding, provide important insights into our software-enabled world.

• Coding is based on Algorithms

• Know the five essential properties of an algorithm

Wednesday, April 9, 14

Page 3: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

How to Solve It By Computer

1. Problem-Solving => Specify an algorithm to solve the problem.

2. Programming => Translate the algorithm into a program.

One algorithm can be translated into:

JavaScript, Java, C++, Ruby, Python, Lisp, Go

Wednesday, April 9, 14

Page 4: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

5 Categories of Information01001101 01101001 01101011 01100101

1. Numbers2. Text (characters)3. Graphics4. Sound5. Instructions (software programs)

Bias-Free Universal Medium Principle Bits can represent all discrete informationBits have no inherent meaning

Wednesday, April 9, 14

Page 5: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Bias-Free Universal Medium PrincipleInformation consists of a symbol (a representation), a referent (the thing represented) and an observer.

=> Information has an objective pole (representations & the mappings to their referents) and a subjective pole (the observer).

Representation: a pattern of symbols that stand for something. (01101100 ... )

Wednesday, April 9, 14

Page 6: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

IT: Basic TermsInformation: from Latin informare, to give form to, to form an idea of.

Information Processing: a cycle, where data (which may have no inherent meaning to the observer) is converted into information (which does have meaning to the observer).

An information process transforms representations.

Wednesday, April 9, 14

Page 7: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Recall from Ch. 8: Advantages of Digital Sound

• A key advantage of digital information is the ability to compute on the representation

• One computation of value is to compress the digital audio or reduce the number of bits needed

Wednesday, April 9, 14

Page 8: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

IT: Basic Terms

Computer: a machine that processes data according to a list of instructions. (Synonym: Information Processor.)

Process: a set of instructions in execution on a processor. (Synonym: computation.)

Algorithm: The list of instructions is called an algorithm or a program.

Wednesday, April 9, 14

Page 9: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm: Definition

Algorithm: a logically detailed and precise set of instructions which, when carried out, solve a problem in a finite amount of time.

(eg) musical scores, recipes, chess game notations, all software programs, ...

We understand a process when we can represent it as an algorithm

Wednesday, April 9, 14

Page 10: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm example

One of the simplest algorithms is to find the largest number in an (unsorted) list of numbers.

The solution necessarily requires looking at every number in the list, but only once at each.

From this follows a simple algorithm, which can be stated in English, as:

Wednesday, April 9, 14

Page 11: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm Example English Description

1. Assume the first item is largest.

2. Look at each of the remaining items in the list and if it is larger than the largest item so far, make a note of it.

3. The last noted item is the largest in the list when the process is complete.

Wednesday, April 9, 14

Page 12: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm Example Pseudocode Description

Algorithm LargestNumber largest ← first item in list for each item in the list do if the item > largest, then largest ← the item return largestEnd Algorithm LargestNumber.

Wednesday, April 9, 14

Page 13: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm for the math game bizz buzzprocedure bizzbuzzfor i := 1 to 100 do set print_number to true; if i is divisible by 3 then print "Bizz"; set print_number to false; if i is divisible by 5 then print "Buzz"; set print_number to false; if print_number, print i; print a newline;end

Wednesday, April 9, 14

Page 14: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm bizzbuzz in JavaScript

Wednesday, April 9, 14

Page 15: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Experience with Algorithms

• Programs are algorithms and all of the applications you use daily are programs

• You use algorithms all the time• You learn algorithms, too:

– In elementary school you learned basic algorithms—for the operations of addition, subtraction, multiplication, and division

Wednesday, April 9, 14

Page 16: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Is it an Algorithm?

• The process of doing something step-by-step may not be not an algorithm– An algorithm is a “systematic method for

producing a specified result”– Searching is purposeful, and provides

direction…with no guarantee of a result!– Algorithms ALWAYS work!

=> Synonym: Effective Procedure

Wednesday, April 9, 14

Page 17: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithm Properties

• An algorithm must have five properties:

1. Input specified2. Output specified3. Definiteness4. Effectiveness5. Finiteness

Wednesday, April 9, 14

Page 18: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

3. Definiteness

Definiteness means each step must be clear and unambiguous

Wednesday, April 9, 14

Page 19: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

4. Effectiveness

• For an algorithm to be effective, it means that all those steps that are required to get to output MUST BE DOABLE!

Wednesday, April 9, 14

Page 20: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

5. Finiteness

• The algorithm must stop, eventually!

• Stopping may mean that you get the expected output OR you get a response that no solution is possible

Wednesday, April 9, 14

Page 21: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Other Algorithmic Characteristics

Algorithms are language independent but must be clear and precise

• Natural languages are ambiguous in that words or phrases may have multiple meanings

• Programming languages are formal languages with clear, unambiguous rules

• Program: an algorithm expressed as statements in a programming language.

Wednesday, April 9, 14

Page 22: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Other Algorithmic Characteristics

A computing agent is required to execute the instructions of an algorithm

• human• machine• natural process

Wednesday, April 9, 14

Page 23: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Computer Science:The Study of Algorithms

• machines for executing algorithms• operating systems• programming languages• theory of algorithms• software engineering• information technology & databases• networks• artificial intelligence• etc

Wednesday, April 9, 14

Page 24: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithms & Natural Information Processes

• Although during its first 50 years, computing was viewed as a science of the artificial, information processes are now understood to be part of the deep structures of nature.

• Computers are used as tools to study these structures and processes (e.g., bioinformatics, quantum computing, ...)

Wednesday, April 9, 14

Page 25: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithms & Natural Information Processes

• Today computation is seen as a natural process as well as an artificial one. E.g., an information process transforms DNA codes into proteins.

• Computation is no longer tied to just computers.

• Computer no longer necessarily means machine.

Wednesday, April 9, 14

Page 26: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Algorithms & Natural Information Processes

• Example: genetic information processing.

The human genome represents, stores, replicates, transmits and processes genetic information

(i.e., controls activities of cells and the organism).

Wednesday, April 9, 14

Page 27: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

• An analogy to the human genome stored on DNA is that of instructions stored in a book (http://en.wikipedia.org/wiki/Genome)

The book (genome) would contain 23 chapters (chromosomes); each chapter contains 48 to 250 million letters (A,C,G,T) without spaces; hence, the book contains over 3.2 billion letters total; the book fits into a cell nucleus the size of a pinpoint; at least one copy of the book (all 23 chapters) is contained in most cells of our body.

Wednesday, April 9, 14

Page 28: Ch. 10 FIT5, CIS 110 13F

Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Computational Thinking (CT)CT is an approach to problem solving that (a) represents the problem as an information process relative to a computational model, and

(b) specifies an algorithmic solution.The model can either may be discovered (natural) or invented (artificial).

=> CT is the new "Freshman Comp".

Wednesday, April 9, 14