Program Development by Stepwise Refinement

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

Algorithm Design Techniques
Software Design Fundamentals
Solving N+k Queens Using Dancing Links Matthew A. Wolff Morehead State University May 19, 2006.
Lecture 19: Parallel Algorithms
Parallel Programming Patterns Eun-Gyu Kim June 10, 2004.
1 Transportation problem The transportation problem seeks the determination of a minimum cost transportation plan for a single commodity from a number.
Object-Oriented Software Construction Bertrand Meyer 2nd ed., Prentice Hall, 1997.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
B ACKTRACK SEARCH ALGORITHM. B ACKTRACKING Suppose you have to make a series of decisions, among various choices, where You don’t have enough information.
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
SIGCSE Nifty assignments: Brute force and backtracking Steve Weiss Department of Computer Science University of North Carolina at Chapel Hill
Science1 Welcome to: Chapel Hill UNC Computer Science.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Backtracking What is backtracking?
Damian Gordon.  This module is concerned with program design skills, with particular reference to using flowcharts, pseudocode and programming language.
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.
Chapter 10: Algorithm Design Techniques
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Backtracking.
1 Applications of Recursion (Walls & Mirrors - Chapter 5)
New Mexico Computer Science For All Introduction to Algorithms Maureen Psaila-Dombrowski.
03 - ParnasCSC4071 A Sketchy Evolution of Software Design 1960s –Structured Programming (“Goto Considered Harmful”, E.W.Dijkstra) Emerged from considerations.
Program Design ENGR 1181 MATLAB 01. Program Design in Real Life Complex manufacturing processes require careful logic mapping to determine what actions.
Data Structures Using C++ 2E Chapter 6 Recursion.
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Data Structures Using C++ 2E Chapter 6 Recursion.
C OMPUTER S CIENCE G EMS 5 Challenging Projects. P ROJECT 1: M ASTERMIND Summary: A code breaking game 12 guesses Feedback is # correct and # correct.
COSC2007 Data Structures II
An introduction to decomposition: Tut, clap or Jive Key Stage 1: Although decomposition is not explicitly mentioned in the key stage 1 programme of study,
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
SOFTWARE DESIGN.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
UHD::3320::CH121 DESIGN PHASE Chapter 12. UHD::3320::CH122 Design Phase Two Aspects –Actions which operate on data –Data on which actions operate Two.
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Please snarf the code for today’s class. Then think about the famous 8-Queen’s Puzzle. The question is: is there a way to arrange 8 queens on a (8x8) chessboard.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Spectral Clustering Jianping Fan Dept of Computer Science UNC, Charlotte.
Software Engineering CS103 February 13, How Do You Solve Big Problems? Thousands of programmers Thousands of programmers Months or years of coding.
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4.
“Architecture” The outcome of top-level design, reflecting principal design decisions Can (and should) be modified and updated Analogous to architecture.
Backtracking & Brute Force Optimization Intro2CS – weeks
Problem Decomposition and Abstraction. Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems?
Introduction to State Space Search
Search in State Spaces Problem solving as search Search consists of –state space –operators –start state –goal states A Search Tree is an efficient way.
CompSci Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze ä Certain mazes can be solved using the.
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Analysis & Design of Algorithms (CSCE 321)
Contest Algorithms January 2016 Pseudo-code for backtracking search, and three examples (all subsets, permutations, and 8- queens). 4. Backtracking 1Contest.
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
Fundamental Data Structures and Algorithms Ananda Guna March 18, 2003 Dynamic Programming Part 1.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Software Design and Development Development Methodoligies Computing Science.
Systems in the Small: An Introduction to Algorithms David Millard
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
Chapter 7: Designing solutions to problems OCR Computing for A Level © Hodder Education 2009.
Recursion Data Structure Submitted By:- Dheeraj Kataria.
Depth-First Search N-Queens Problem Hamiltonian Circuits
Intro to Computer Science II
Data Structures and Algorithms
Parallel Programming Patterns
Haskell Tips You can turn any function that takes two inputs into an infix operator: mod 7 3 is the same as 7 `mod` 3 takeWhile returns all initial.
The N-Queens Problem Search The N-Queens Problem Most slides from Milos Hauskrecht.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Presentation transcript:

Program Development by Stepwise Refinement Niklaus Wirth

Motivation Programming is usually taught via examples Examples normally demonstrate what a computer can do Examples are not normally chosen by their suitability for a technique Programming is not just mastering of a language – more important to master the methods of design and construction.

Aim The paper aims to demonstrate the development of an example program through a sequence of refinement steps Today, we refer to this approach as top-down design (or top-down decomposition) The program and data specification are refined in parallel

Refinement Each refinement implies design decisions It is important to make these explicit Be aware of the critieria for the refinement Be aware there are alternatives (after all, this might not work out) Decompose decisions as much as possible Defer decisions about data as long as possible

The 8-Queens Problem Given an 8X8 chessboard and 8 queens which are hostile to each other, find a position for each queen such that no queen may be taken by any other queen. NOTE: Eight-Queens on wikipedia has an animated example of the Recursive solution solving this problem

Brute Force Approach A = Set of candidates for the solution One exists that satisfies condition p Repeat Generate the next element of A and call it x until p(x) OR (no more elements in A) if p(x) then x = solution

Issues Problem space is too large We need a way to preselect solutions Computers at the time would take ~ 7 hrs We need a way to preselect solutions Criteria Smaller than A Elements easily generated Easier to test than p(x)

8-Queens: Unique Columns Every column must have exactly 1 queen Now we are just testing rows and diagonals We also need the ability to “try” a row for a queen and backtrack if the test for the row/diagonal fails.

Program At This Point repeat trycolumn; if safe then setqueen; considernextcolumn; else regress until lastcoldone OR regressoutoffirstcol

Define the Instructions Considerfirstcolumn Considernextcolumn Reconsiderpriorcolumn Advancepointer Testsquare Setqueen removeQueen

Refining the Instructions Upon realizing that we can store the indexes of occupied rows, and thru carefully choosing our array structures, we can reduce the instruction set to: testsquare setqueen regress movequeen

A recursive alternative View the problem as starting with one column Extend the board by one column at each step

Generalizing the Problem We often need to change our program based on new requirements… What if we want ALL possible solutions?

Conclusions Programs are constructed thru a sequence of refinement tasks Each task is decomposed into subtasks The degree of decomposition (modularity) will determine the ease with which we can modify the program

Conclusions Use a notation that is natural for the problem Each refinement implies a design decision, criteria include efficiency, storage, clarity The development of this simple problem formed a long story, programming is not trivial – simplifying the problem is important.