Lecture 14: General Problem-Solving Methods

Similar documents
Algorithm classification

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

CS 440 Theory of Algorithms /

Greedy Algorithms and Huffman Coding

Algorithmic patterns

Backtracking and Branch-and-Bound

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Data Structures, Algorithms & Data Science Platforms

Search and Optimization


Chapter-6 Backtracking

CMSC Introduction to Algorithms Spring 2012 Lecture 16

L.J. Institute of Engineering & Technology Semester: VIII (2016)

5105 BHARATHIDASAN ENGINEERING COLLEGE

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Lecture 3. Brute Force

Backtracking. See Section 7.7 p of Weiss

Recursion as a Problem-Solving Technique. Chapter 5

DESIGN AND ANALYSIS OF ALGORITHMS


Algorithms for Integer Programming

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

CSE373: Data Structure & Algorithms Lecture 23: More Sorting and Other Classes of Algorithms. Catie Baker Spring 2015

6. Algorithm Design Techniques

Backtracking. Chapter 5

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING ECE 250 ALGORITHMS AND DATA STRUCTURES

The problem: given N, find all solutions of queen sets and return either the number of solutions and/or the patterned boards.

APCS-AB: Java. Recursion in Java December 12, week14 1

Contents. 1 Introduction. 2 Searching and Traversal Techniques. Preface... (vii) Acknowledgements... (ix)

CSC 427: Data Structures and Algorithm Analysis. Fall 2006

Practice Problems for the Final

An algorithm is a sequence of instructions that one must perform in order to solve a wellformulated

CS1 Lecture 31 Apr. 3, 2019

Recursion. Recursion is: Recursion splits a problem:

Graph Algorithms. Tours in Graphs. Graph Algorithms

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

Dr. Mustafa Jarrar. Chapter 4 Informed Searching. Artificial Intelligence. Sina Institute, University of Birzeit

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

Unit-2 Divide and conquer 2016

Probabilistic (Randomized) algorithms

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Dynamic Programming

Unit-5 Dynamic Programming 2016

Partha Sarathi Mandal

INSTITUTE OF AERONAUTICAL ENGINEERING

Algorithm Design Techniques (III)

Lecture 3, Review of Algorithms. What is Algorithm?

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

Artificial Intelligence (part 4a) Problem Solving Using Search: Structures and Strategies for State Space Search

mywbut.com Informed Search Strategies-II

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014

CS 151. Recursion (Review!) Wednesday, September 19, 12

CS Data Structures and Algorithm Analysis

TOTAL CREDIT UNITS L T P/ S SW/F W. Course Title: Analysis & Design of Algorithm. Course Level: UG Course Code: CSE303 Credit Units: 5

DESIGN AND ANALYSIS OF ALGORITHMS

Math 414 Lecture 30. The greedy algorithm provides the initial transportation matrix.

Dr. Mustafa Jarrar. Chapter 4 Informed Searching. Sina Institute, University of Birzeit

CAD Algorithms. Categorizing Algorithms

CS 206 Introduction to Computer Science II

R13 SET - 1. ''' '' ''' ' blog: anilkumarprathipati.wordpress.com. Code No: RT32054

In this chapter we will very briefly review the most common algorithmic techniques which are used in bioinformatics.

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

Chapter 3. A problem-solving agent is a kind of goal-based agent. It decide what to do by finding sequences of actions that lead to desirable states.

Lecture 6: Combinatorics Steven Skiena. skiena

Assignment No 2 (Group B)

Search means finding a path or traversal between a start node and one of a set of goal nodes. Search is a study of states and their transitions.

Chapter 6 Backtracking Algorithms. Backtracking algorithms Branch-and-bound algorithms

CS6402 Design and Analysis of Algorithm. 2 Marks Question & Answer UNIT I INTRODUCTION

CS159. Nathan Sprague. November 9, 2015

CSE 417 Branch & Bound (pt 4) Branch & Bound

International Journal of Modern Engineering and Research Technology

Problem solving paradigms

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Subset sum problem and dynamic programming

CMSC 132: Object-Oriented Programming II. Recursive Algorithms. Department of Computer Science University of Maryland, College Park

CS6402-DESIGN AND ANALYSIS OF ALGORITHM. TWO MARK QUESTION WITH ANSWERS Unit-I. Introduction

Lecture 6: Recursion RECURSION

12/30/2013 S. NALINI,AP/CSE

3 INTEGER LINEAR PROGRAMMING

CS61BL. Lecture 5: Graphs Sorting

Lecture Chapter 6 Recursion as a Problem Solving Technique

Framework for Design of Dynamic Programming Algorithms

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

Backtracking is a refinement of the brute force approach, which systematically searches for a

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

Algorithm Design and Analysis

Outline of the talk. Local search meta-heuristics for combinatorial problems. Constraint Satisfaction Problems. The n-queens problem

Algorithm Concepts. 1 Basic Algorithm Concepts. May 16, Computational Method

SPANNING TREES. Lecture 21 CS2110 Spring 2016

Mathematical Tools for Engineering and Management

Design and Analysis of Algorithms

Constraint (Logic) Programming

Introduction to Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Math 98 - Introduction to MATLAB Programming. Fall Lecture 2

EE 368. Weeks 4 (Notes)

Heuristic Optimisation

Transcription:

Lecture 14: General Problem-Solving Methods

Problem Solving Methods Greedy Method Divide-and-Conquer Backtracking Dynamic Programming Branch-and-Bound

Greedy Method The greedy method consists of an iteration of the following computations: selection procedure-a selection procedure is created to choose the next item to add to a list of locally optimalsolutions to sub problems feasibility check-a test is made to see if the current set of choices satisfies some locally optimal criterion. solution check -when a complete set is obtained it is checked to verify that it constitutes a solution for the original problem. Aquestionthatshouldcometomindis:Whatismeantbylocallyoptimal? This term refers to the amount of work necessary to determine a solution or to measure the level to which a criterion is met. If the computation leading to an optimal solution or the evaluation of a criterion does not involve an exhaustive search then that activity may be considered local.

Divide-and-Conquer As its name implies this method involves dividing a problem into smaller problems that can be more easily solved. While the specifics can vary from one application to another, divide-and-conquer always includes the following three steps in some form: Divide-Typically this steps involves splitting one problem into two problems of approximately 1/2 the size of the original problem. Conquer-The divide step is repeated (usually recursively) until individual problem sizes are small enough to be solved (conquered) directly. Recombine-The solution to the original problem is obtained by combining all the solutions to the sub-problems. Divide and Conquer is not applicable to every problem class. Even when D&C works it may not produce an efficient solution.

Backtracking Backtracking is used to solve problems in which a feasible solution is needed rather than an optimal one, such as the solution to a maze or the arrangement of squares in the 15-puzzle. Typically, the solution to a backtracking problem is a sequence of items(or objects) chosen from a set of alternatives that satisfy some criterion. A backtracking algorithm is a scheme for solving a series of sub-problems each of which may have multiple possible solutions and where the solution chosen for one sub-problem can affect the possible solutions of later sub-problems. To solve the overall problem, we find a solution to the first sub-problem and then attempt to recursively solve the other sub-problems based on this first solution. If wecannot,orwewantallpossiblesolutions,webacktrackandtrythenextpossible solution to the first sub-problem and so on. Backtracking terminates when there are no more solutions to the first sub-problem orasolutiontotheoverallproblemisfound. http://dictionary.die.net/backtracking

Dynamic Programming In mathematics and computer science, dynamic programming is a method of solving complex problems by breaking them down into simpler steps. It is applicable to problems that exhibit the properties of overlapping sub problems and optimal substructure. Overlapping sub problems means that the space of sub problems must be small, that is, any recursive algorithm solving the problem will solve the same sub problems over and over, rather than generating new sub problems. Dynamic programming takes account of this fact and solves each sub problem only once. Optimal substructure means that the solution to a given optimization problem can be obtained by the combination of optimal solutions to its sub problems. Consequently, the first step towards devising a dynamic programming solution is to check whether the problem exhibits an optimal substructure.

Branch-and-Bound Graph traversal refers to the problem of visiting all the nodes in a graph in a particular manner. Graph traversal can be used as a problem-solving method when a problem state can be represented as a graph and its solution can be represented as a path in the graph. When the graph is a tree it can represent the problem space for a wide variety of combinatorial problems. In these cases the solution is usually at one of the leaf-nodes of the tree or is the path to a particular leaf-node. To make graph traversal efficient we need to avoid searching paths that can be determined will not result in good (or optimal) solutions. Techniques such a branch-and-bound can be used to reduce the number of operations required to search the graph or tree problem space by eliminating infeasible or unpromising branches.

Coin Changing An optimal solution to the coin changing problem is the minimum number of coins whose total value equals a specified amount. For example what is the minimum number of coins (current U.S. mint) needed to total 83 cents. 83-25 = 58 58-25 = 33 33-25 = 8 8-5 = 3 3-1 = 2 2-1 = 1 1-1 = 0 A Greedy Algorithm for Coin Changing 1. Set remval=initial_value 2. Choose largest coin that is less than remval. 3. Add coin to set of coins and set remval:=revamal-coin_value 4. repeat Steps 2 and 3 until remval = 0;

Coin Changing - Another Example The greedy method works for the U.S. minted coin set, but will it work for any coin set? Consider the coin set below and a change value of 82 cents.. 82-26 = 56 56-26 = 30 30-26 = 4 4-1 = 3 3-1 = 2 2-1 = 1 1-1 = 0 By the coin-changing algorithm we obtain 3 26 cent pieces and 4 pennies, but we can use 2 26 cent pieces and 3 dimes to total 82 cents. Hence the greedy approach does not work for this coin set.

Quicksort Example i j 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 1 6 9 8 5 7 4 6 3 5 4 7 6 0 5 4 2 6 5 8 9 7 4 6 3 5 4 7 6 0 5 6 3 6 5 4 9 7 8 6 3 5 4 7 6 0 5 8 4 6 5 4 3 7 8 6 9 5 4 7 6 0 5 9 5 6 5 4 3 5 8 6 9 7 4 7 6 0 5 10 6 6 5 4 3 5 4 6 9 7 8 7 6 0 5 13 7 6 5 4 3 5 4 0 9 7 8 7 6 6 5 14 8 6 5 4 3 5 4 0 5 7 8 7 6 6 9 8 5 5 4 3 5 4 0 6 7 8 7 6 6 6 pivot value items being swapped new sublists for next pass of quicksort

N-Queens Problem A classic backtracking algorithm is the solution to the N-Queens problem. In this problem you are to place queens (chess pieces) on an NxN chessboard in such a way that no two queens are directly attacking one another. That is no two queens share the same row, column or diagonal on the board. Backtracking Approach -Version 1: Until all queens are placed, choose the first available location and put the next queen in this position. If queens remain to be placed and no space is left, backtrack (by removing the last queens placed and placing it in the next available position).

N-Queens Problem Backtracking Approach - Version 2: A more efficient backtracking approach is to note that each queen must be in its own column and row. This reduces the search from (N 2 )! to N!.

The Binomial Coefficient (a+b) 0 = 1 (a+b) 1 = a+b (a+b) 2 = a 2 +2ab+b 2 The binomial theorem gives a closed-form expression for the coefficient of any term in the expansion of a binomial raised to the nth power. (a+b) 3 = a 3 +3a 2 b+3ab 2 +b 3 (a+b) 4 = a 4 +4a 3 b+6a 2 b 2 +4ab 3 +b 4 ( a + b) n n! n = k= 0 k! ( n k )! a k b n k The binomial coefficient is also the number of combinations of n items taken k at a time, sometimes called n-choose-k. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 n 1 n 1 n + = k 1 k k 1 for 0 < k k = 0 or < n k = n

Traveling Salesperson with Branch-and-Bound In the most general case the distances between each pair of cities is a positive value with dist(a,b) dist(b,a). In the matrix representation, the main diagonal values are omitted (i.e. dist(a,a) 0). A B C D E F G H A B A - 5 7 6 4 10 8 9 H C B C 8-14 9 3 4 6 2 7 9-11 10 9 5 7 D 16 6 8-5 7 7 9 G D E F 1 3 2 5-8 6 7 12 8 5 3 2-10 13 F E G H 9 5 7 9 6 3-4 3 9 6 8 5 7 9 -

The live-node list is ordered by bounding value and then by level of completion. That is, if two nodes have the same bounding value we place the one that is closer to completion ahead of the other node. This is because the bounding value of the of the nodeclosertocompletionismorelikelytobeclosertotheactualtourlength.

An Example Branch-and-Bound TSP The initial tour is A-F-E-D-B-C-A with a total length of 32. The sum of the minimum costs of leaving every node is 29 so we know that a minimal tour cannot have length less than 29.

The node shown in red were expanded from an active node (F 3 ) with a possible tour length of 29. However the completed tours turned out to be significantly larger.

Expanding D 3 we find an actual tour that is shorter than our initial tour. We do not yet know if this is a minimal tour but we can remove nodes from our live-node list that have a bounding value of >= 31. Now we expand D 2 to find that it leads to tours oflength>=33.

Expansion of E 2 eliminates this path as a candidate for a minimal tour.

When the live-node list is empty we are finished. In this example a minmal tour is A-C-E-D-B-F-Awithalengthof31wehavefoundatourthatisshorterthantheoriginal candidate tour.