Algorithm Design Techniques. Hwansoo Han

Similar documents
Algorithm Design Techniques (III)

CAD Algorithms. Categorizing Algorithms

CPSC 436D Video Game Programming

Algorithm classification

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

State Space Search. Many problems can be represented as a set of states and a set of rules of how one state is transformed to another.

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

Search and Optimization

Artificial Intelligence. Game trees. Two-player zero-sum game. Goals for the lecture. Blai Bonet

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

Dynamic Programming Homework Problems

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

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

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

Theorem 2.9: nearest addition algorithm

SPANNING TREES. Lecture 21 CS2110 Spring 2016

Data Structures and Algorithms

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees. Lecture 22 CS2110 Spring 2017

University of the Western Cape Department of Computer Science

Travelling Salesman Problem. Algorithms and Networks 2015/2016 Hans L. Bodlaender Johan M. M. van Rooij

Parallel Programming. Parallel algorithms Combinatorial Search

Traveling Salesman Problem. Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij

DESIGN AND ANALYSIS OF ALGORITHMS

6. Algorithm Design Techniques

Optimal tour along pubs in the UK

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

CS 440 Theory of Algorithms /

Finding optimal configurations Adversarial search

tree follows. Game Trees

Computer Science and Software Engineering University of Wisconsin - Platteville. 3. Search (Part 1) CS 3030 Lecture Notes Yan Shi UW-Platteville

Artificial Intelligence (part 4d)

Artificial Intelligence (part 4d)

Artificial Intelligence CS 6364

looking ahead to see the optimum

Spanning Trees. Lecture 20 CS2110 Spring 2015

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

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

Lecture 8: The Traveling Salesman Problem

15CS43: DESIGN AND ANALYSIS OF ALGORITHMS

(Refer Slide Time: 01:00)

Chapter 6. Dynamic Programming

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

Data Structures, Algorithms & Data Science Platforms

HEURISTIC SEARCH. 4.3 Using Heuristics in Games 4.4 Complexity Issues 4.5 Epilogue and References 4.6 Exercises

Downloaded from ioenotes.edu.np

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

Monotonicity. Admissible Search: That finds the shortest path to the Goal. Monotonicity: local admissibility is called MONOTONICITY

Final. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013

CSCE 350: Chin-Tser Huang. University of South Carolina

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

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

CS 188: Artificial Intelligence. Recap Search I

The Algorithm Design Manual

Module 6 NP-Complete Problems and Heuristics

Unit-5 Dynamic Programming 2016

Foundations of Discrete Mathematics

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

Questions and exercises for Midterm and Final Review

Minimum-weight tree shortcutting for Metric TSP

CS 161 Fall 2015 Final Exam

Introduction HEURISTIC SEARCH. Introduction. Heuristics. Two main concerns of AI researchers. Two problems with the search process

35 Approximation Algorithms

Approximation Algorithms

Data Structures (CS 1520) Lecture 28 Name:

Design and Analysis of Algorithms

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

Artificial Intelligence

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

DESIGN AND ANALYSIS OF ALGORITHMS

3.6.2 Generating admissible heuristics from relaxed problems

Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games. Comp24412: Symbolic AI. Lecture 4: Search. Ian Pratt-Hartmann

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

2. (a) Explain when the Quick sort is preferred to merge sort and vice-versa.

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Assignment No 2 (Group B)

Introduction to Optimization

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

Dynamic Programming Homework Problems

Design and Analysis of Algorithms - - Assessment

Alpha-Beta Pruning in Mini-Max Algorithm An Optimized Approach for a Connect-4 Game

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS

Data Structures (CS 1520) Lecture 28 Name:

Monte Carlo Methods; Combinatorial Search

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

LECTURE 3 ALGORITHM DESIGN PARADIGMS

Algorithms. Algorithms ALGORITHM DESIGN

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

Partha Sarathi Mandal

GRAPH THEORY and APPLICATIONS. Matchings

Traveling Salesman Problem (TSP) Input: undirected graph G=(V,E), c: E R + Goal: find a tour (Hamiltonian cycle) of minimum cost

Notation Index 9 (there exists) Fn-4 8 (for all) Fn-4 3 (such that) Fn-4 B n (Bell numbers) CL-25 s ο t (equivalence relation) GT-4 n k (binomial coef

Midterm Examination CS540-2: Introduction to Artificial Intelligence

APHID: Asynchronous Parallel Game-Tree Search

Transcription:

Algorithm Design Techniques Hwansoo Han

Algorithm Design General techniques to yield effective algorithms Divide-and-Conquer Dynamic programming Greedy techniques Backtracking Local search 2

Divide-and-Conquer Towers of Hanoi A C B Move disks on A to C Without putting a larger disk on top of a smaller disk Assume a cycle consists of peg A, B, and C Repeat the following steps On odd-numbered moves, move the smallest disk to one peg clockwise On even-numbered moves, move the only legal move not involving the smallest disk 3

Divide-and-Conquer Hanoi tower (cont d) Previous solution is concise, but hard to understand why it works Solution with recursion Initially, n disks on peg A, we need to move all disks to peg B First, move n-1 smallest disks from peg A to peg C, exposing the n th smallest disk on peg A Then, move the n th smallest disk from peg A to peg B Now, we need to move n-1 disks from peg C to peg B We can solve this recursively T(1) = 1, T(n) = 2T(n-1) + 1 O(2 n ) 4

Divide-and-Conquer Multiplying long integers (two n-bit integers) XY = AC2 n + (AD + BC) 2 n/2 + BD 4 multiplications, 3 additions, 2 shifts T(1) = 1, T(n) = 4T(n/2) + cn O(n 2 ) XY = AC2 n + [(A-B)(D-C) + AC + BD] 2 n/2 + BD 3 multiplications, 6 additions/subtractions, 2 shifts T(1) = 1, T(n) = 3T(n/2) + cn O(n log 23 ) = O(n 1.59 ) 5

Dynamic Programming Use dynamic programming approach When a problem cannot be divided into a small number of subproblems Dynamic programming Divide into as many subproblems as necessary Divide each subproblem into smaller subproblems, To achieve polynomial-time algorithm, instead of exponentialtime one Define a polynomial number of subproblems Keep track of the solution to each subproblem Look up the solution when needed 6

Dynamic Programming Triangulation problem Use triangulation of a polygon to apply shading Minimum cost triangulation Selecting a set of chords that minimize the sum of Euclidean lengths of chords Chords - lines between non-adjacent vertexes 7

Dynamic Programming Triangulation Two subproblems when (v 0, v 3 ) is chosen as a chord 8

Dynamic Programming Triangulation v 2 v 3 v 2 v 3 v 1 S 04 v 4 v 1 S 04 T 034 v 4 v 2 v 3 v 0 S 35 v 5 v 0 S 44 v 5 v 1 v 4 v 6 v 6 v 0 v 5 v 2 v 3 v 6 v 1 S 05 v 4 v 0 v 6 S 44 v 5 Solution for S 44 can be reused in finding minimum cost triangulation 9

Greedy Algorithms Making changes with as few as possible coins Coins with values of 25, 10, 5, 1 E.g. make 63 in change Two 25, one 10 and three 1 Used a greedy algorithm 1. Use the largest value coin not to exceed the amount 2. Subtract the coin value from the current amount 3. Make the current amount be the subtracted amount 4. Repeat step 1 10

Greedy Algorithms At any individual stage, a greedy algorithm selects a locally optimal option A greedy algorithm can produce globally optimal solution Making changes Dijkstra s shortest path algorithm (for non-negative cost graph) Kruskal s minimum cost spanning tree algorithm Not all greedy algorithms are globally optimal E.g., 63 : coins with 32, 25, 15, 1 11

Greedy Algorithms as Heuristics Greedy algorithms as heuristics for some problems No known greedy algorithm produces an optimal solution Yet, greedy algorithms can be relied upon to produce good solutions with high probability A suboptimal solution with a cost of a few percent above optimal is quite satisfactory, if we can find one fast. 12

Greedy Algorithms as Heuristics Travelling salesman problem (TSP) Optimal solution can only be found by exploring all possibilities this leads to exponential time (NP) Example Six cities Cost of travel = distance Find a Hamiltonian cycle Include all vertexes Sum of the all costs of edges is a minimum 13

Greedy Algorithms as Heuristics A heuristic for Travelling Salesman Problem (TSP) Similar algorithm to Kruskal s algorithm Try to include the shortest edge in turn Accept the edge, if the following condition holds Not causing a vertex to have degree three or more Not forming a cycle with already accepted edges (except the last edge which completes a cycle) 14

Backtracking A problem has no theory to find the optimum, except exhaustive search Systematic exhaustive search Backtracking Alpha-beta pruning 15

Backtracking game tree Example of backtracking in games Chess, checkers, or tic-tac-toe Game tree All possible moves from the starting position tic-tac-toe example X playing 1: win, 0: draw, -1: lose Label from the leaves Propagate according to turns X moves prefer 1 (MAX) O moves prefer -1 (MIN) turns 16

Backtracking - payoff Payoff Functions in Game Tree Leaf nodes has values (e..g., -1, 0, 1) Interior nodes can have payoff values, too In general, payoff values at leaves are ambiguous Extending downward for several levels requires a great computing power in complex games (such as chess, go, ) Payoff function uses board positions to estimate the probability of winning Assuming each side chooses best play, computer chooses the move with the highest payoff MiniMax (MinMax) algorithm 17

Backtracking recursive search Backtrack search Construct a game tree and visit nodes in postorder? Space to store tree can be prohibitively large Build only one path, from the root to some node Postorder recursive search actively builds a node when visits Free the space after return 18

Backtracking Alpha-Beta Pruning May skip some of children visits Set a tentative value for node when at least one child has a final value If further visit cannot change the tentative value, prun the subtree 19

Backtracking Alpah-Beta Pruning α-β pruning example Postorder visit max A min B I P max C F J M Q T D E G H K L N O R S U V 2 1 6 1 8 3 5 2 3 4 2 6 20

Local Search General local search algorithm Start with a random solution Apply a transformation to the current solution to improve the improvement becomes the new current solution Repeat until no transformation improves the current solution 21

Local search minimal spanning tree Add an edge not in MST which results in a cycle Eliminate the highest cost edge in the cycle 22

Local Search for Minimum Spanning Tree Select randomly for an initial MST Improve by replacing one edge at a time 23