slides courtesy of Eric Roberts

Slides:



Advertisements
Similar presentations
Procedural Recursion Eric Roberts CS 106B April 15, 2009.
Advertisements

1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
“The study of algorithms is the cornerstone of computer science.” Algorithms Winter 2012.
Software Engineering and Design Principles Chapter 1.
CS102 Algorithms and Programming II1 Recursion Recursion is a technique that solves a problem by solving a smaller problem of the same type. A recursive.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Early Term Test Some Study Reminders. General Topics Sources for information to be tested are –My slides and classroom presentations of slides –Chapter.
Karel The Robot In the beginning… software. Karel the Robot  All robots are controlled by software  Artificially intelligent robots that can “think”
School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving.
Slides prepared by Rose Williams, Binghamton University Chapter 11 Recursion.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com If you.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Chapter 7: Designing solutions to problems OCR Computing for A Level © Hodder Education 2009.
AP CSP: Creating Functions & Top-Down Design
Algorithms and Problem Solving
Topic: Programming Languages and their Evolution + Intro to Scratch
In the beginning… software
IST256 : Applications Programming for Information Systems
Recursion: The Mirrors
Algorithms IV Top-Down Design.
Eric Roberts and Jerry Cain
Copyright © 2008 by Helene G. Kershner
CSE 374 Programming Concepts & Tools
Storage Management.
Copyright © 2008 by Helene G. Kershner
CMSC201 Computer Science I for Majors Lecture 11 – Program Design
SOFTWARE DESIGN AND ARCHITECTURE
Roadmap to Programming work, right, fast KISS
Chapter 14 Recursion. Chapter 14 Recursion Overview 14.1 Recursive Functions for Tasks 14.2 Recursive Functions for Values 14.3 Thinking Recursively.
MTH 221 TUTORIALS Lessons in Excellence -- mth221tutorials.com.
Problem Solving Techniques
Stepwise Refinement Eric Roberts CS 106A January 8, 2010.
Written Description of Algorithms
Mechanics of Functions
Designing Programs.
Binary Search Trees One of the tree applications in Chapter 10 is binary search trees. In Chapter 10, binary search trees are used to implement bags.
Programming Fundamentals (750113) Ch1. Problem Solving
Problem Solving and Algorithm Design
slides courtesy of Eric Roberts
Chapter 0 : Introduction to Object Oriented Design
4. Computational Problem Solving
Programming We have seen various examples of programming languages
Data Structures and Algorithms for Information Processing
Algorithms IV Top-Down Design.
Create – Performance Task
Algorithms and Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Week 4 Lecture-2 Chapter 6 (Methods).
Lecture 6 Architecture Algorithm Defin ition. Algorithm 1stDefinition: Sequence of steps that can be taken to solve a problem 2ndDefinition: The step.
Programming Fundamentals (750113) Ch1. Problem Solving
Design Your Own 3R Symbol (Reduce, Reuse, Recycle)
Computational Thinking
Basic Concepts of Algorithm
Rocky K. C. Chang September 11, 2018
Computational Thinking
SOFTWARE ENGINEERING LECTURE 4
Early Midterm Some Study Reminders.
Digital Literacies for learning
Presentation transcript:

slides courtesy of Eric Roberts Stepwise Refinement Jerry Cain CS 106AJ September 28, 2018 slides courtesy of Eric Roberts

Stepwise Refinement The most effective way to solve a complex problem is to break it down into successively simpler subproblems. You start by breaking the whole task down into simpler parts. Some of those tasks may themselves need subdivision. This process is called stepwise refinement or decomposition. Complete Task Subtask #1 Subtask #2 Subtask #3 Subsubtask #2a Subsubtask #2b

Criteria for Choosing a Decomposition The proposed steps should be easy to explain. One indication that you have succeeded is being able to find simple names. 1. The steps should be as general as possible. Programming tools get reused all the time. If your methods perform general tasks, they are much easier to reuse. 2. The steps should make sense at the level of abstraction at which they are used. If you have a method that does the right job but whose name doesn’t make sense in the context of the problem, it is probably worth defining a new method that calls the old one. 3.

Exercise: Banishing Winter In this problem (which is described in detail in Handout #4), Karel is supposed to usher in springtime by placing bundles of leaves at the top of each "tree" in the world. Given this initial world, the final state should look like this: + 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Understanding the Problem One of the first things you need to do given a problem of this sort is to make sure you understand all the details. According to the handout, Karel stops when it runs out of beepers. Why couldn’t it just stop at the end of 1st Street? + 1 2 3 4 5 6 7 8 9 10 11 12 13 14 + 1 2 3 4 5 6 7 8 9 10 11 12 13 14

The Top-Level Decomposition You can break this program down into two tasks that are executed repeatedly: Find the next tree. Decorate that tree with leaves.     6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Preconditions and Postconditions Many of the bugs that you are likely to have come from being careless about the conditions under which you use a particular method. As an example, it would be easy to forget the turnLeft call at the end of the addLeavesToTree method. To reduce the likelihood of such errors, it is useful to define pre- and postconditions for every method you write. A precondition specifies something that must be true before a method is called. A postcondition specifies something that must be true after the method call returns.

Algorithmic Programming in Karel In computer science, a well-specified strategy for solving a problem is called an algorithm. The goal for the rest of this lecture is to write a program that solves a maze using the right-hand rule:

The End