Algorithm: definition An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.

Slides:



Advertisements
Similar presentations
Algorithms.
Advertisements

Solving IPs – Cutting Plane Algorithm General Idea: Begin by solving the LP relaxation of the IP problem. If the LP relaxation results in an integer solution,
Chapter 5 Algorithms. 2 Chapter 5: Algorithms 5.1 The Concept of an Algorithm 5.2 Algorithm Representation 5.3 Algorithm Discovery 5.4 Iterative Structures.
Problem of the Day Problem of the Day next Geometry - Connect the Dots
Software Engineering and Design Principles Chapter 1.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
Chapter 2 The Algorithmic Foundations of Computer Science
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Chapter 2: Algorithm Discovery and Design
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Eleventh Edition by J.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Copyright © 2015 Pearson Education, Inc. Chapter 5: Algorithms.
Introduction to Programming. What is a Program  Set of Instructions that tells the computer what to Do.  Driving force behind the computer  Without.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Additional Problems.
By the end of this session you should be able to...
Chapter 5 Algorithms © 2007 Pearson Addison-Wesley. All rights reserved.
“The study of algorithms is the cornerstone of computer science.” Algorithms Fall 2011.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Chapter 5 Algorithms Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas Faculty of Information Technology.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
PROGRAMMING PAPER 2 AS Algorithms.
Chapter 5 Algorithms. © 2005 Pearson Addison-Wesley. All rights reserved 5-2 Chapter 5: Algorithms 5.1 The Concept of an Algorithm 5.2 Algorithm Representation.
Chapter 5: 演算法 Algorithms 陳以德助理教授 : 高醫大舊二棟 轉 2586
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Chapter 5 Algorithms © 2007 Pearson Addison-Wesley. All rights reserved.
Computer Science: An Overview Eleventh Edition
17 November 2015Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
2 Chapter 21 Understanding Structure Programming Logic and Design, Second Edition, Comprehensive 2.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
MEASUREMENTS Janeth Giron Yanet Renteria Mariaelena Avila Ana Herrera Janeth Rodriguez Flor Olague.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Algorithms and Problem Solving
Q & A.
Computer Science: An Overview Eleventh Edition
Functions in C.
Chapter 5: Algorithms 5.1 The Concept of an Algorithm
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
MSIS 655 Advanced Business Applications Programming
Algorithm Discovery and Design
Chapter 6: Repetition Statements
Algorithms and Problem Solving
Computer Science: An Overview Tenth Edition
Presentation transcript:

Algorithm: definition An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.

Algorithms: levels of abstraction Problem = motivation for algorithm Algorithm = procedure to solve the problem –Often one of many possibilities Representation = description of algorithm sufficient to communicate it to the desired audience –Always one of many possibilities

Figure 5.2 Folding a bird from a square piece of paper

Figure 5.3 Origami primitives

Pseudocode primitives Assignment name  expression Conditional selection if condition then action Repeated execution while condition do activity repeat activity until condition Procedure procedure name (generic names)

Figure 5.8 The while loop structure

Figure 5.9 The repeat loop structure

Iterative Structures Pretest loop: while (condition) do (loop body) Posttest loop: repeat (loop body) until(condition)

Figure 5.7 Components of repetitive control

Figure 5.4 The procedure Greetings in pseudocode

Problem solving steps 1. Understand the problem. 2. Get an idea how an algorithmic procedure might solve the problem. 3. Formulate the algorithm and represent it as a program. 4. Evaluate the program for accuracy and its potential as a tool for solving other problems.

Techniques for “getting a foot in the door” Work the problem backwards Solve an easier related problem –Relax some of the problem constraints –Solve pieces of the problem first = bottom up methodology Stepwise refinement = top-down methodology –Popular technique because it produces modular programs

Sample problem Person A is charged with the task of determining the ages of B’s three children. B tells A that the product of the children’s ages is 36. A replies that another clue is required. B tells A the sum of the children’s ages. A replies that another clue is needed. B tells A that the oldest child plays the piano. A tells B the ages of the three children. How old are the three children?

Figure 5.5

Connect each of the nine dots using only four straight lines and without lifting your pen from the paper.

Arrange the numbers 1 through 9 on a tic tac toe board such that the numbers in each row, column, and diagonal add up to 15.

What's the largest number of U.S. coins you can have without having even change for a dollar? Mental Gymnastics A mountain goat attempts to scale a cliff sixty feet high. Every minute, the goat bounds upward three feet but slips back two. How long does it take for the goat to reach the top?

Mental Gymnastics Three switches can be turned on or off. One is the light switch for the overhead light in the next room, which is initially off, but you don't know which. The other two switches do nothing. From the room with the switches in it, you can't see whether the light in the next room is turned on or off. You may flip the switches as often and as many times as you like, but once you enter the next room to check on the light, you must be able to say which switch controls the light without flipping the switches any further. (And you can't open the door without entering, either!) How can you determine which switch controls the light?

Software verification Proof of correctness –Assertions Preconditions Loop invariants Testing

Example problem: Chain separating A traveler has a gold chain of seven links. He must stay at an isolated hotel for seven nights. The rent each night consists of one link from the chain. What is the fewest number of links that must be cut so that the traveler can pay the hotel one link of the chain each morning without paying for lodging in advance?

Figure 5.21 Separating the chain using only three cuts

Figure 5.22 Solving the problem with only one cut

Is This Program Segment Correct? Precondition: X is a positive integer and Y is a positive even integer Z X/Y if (Remainder is positive) then (Print X is odd) else (Print X is even)