Handout 6: More Examples on DP and Shortest Path Problem

Similar documents
Dynamic Programming 11.1 AN ELEMENTARY EXAMPLE

Data Structures and Algorithms Written Examination

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

csci 210: Data Structures Recursion

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Chapter 15: Dynamic Programming

Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

6.231 Dynamic Programming and Stochastic Control Fall 2008

Section IV.1: Recursive Algorithms and Recursion Trees

Approximation Algorithms

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

The 2010 British Informatics Olympiad

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Module 2 Stacks and Queues: Abstract Data Types

Decision Mathematics 1 TUESDAY 22 JANUARY 2008

Scheduling Home Health Care with Separating Benders Cuts in Decision Diagrams

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Dynamic Programming. Lecture Overview Introduction

Analysis of Algorithms I: Binary Search Trees

Dynamic programming formulation

Section #6: Addressing

Call Admission Control and Routing in Integrated Service Networks Using Reinforcement Learning

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

Warshall s Algorithm: Transitive Closure

Math Exercise on the Abacus ( Suanpan in Chinese)

From Last Time: Remove (Delete) Operation

Pseudo code Tutorial and Exercises Teacher s Version

CRITICAL PATH ANALYSIS AND GANTT CHARTS

Analysis of Algorithms I: Optimal Binary Search Trees

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Mathematical Induction

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

GRAPH THEORY LECTURE 4: TREES

Lecture 1: Course overview, circuits, and formulas

Tower Of Hanoi & Reve Puzzles

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

The Goldberg Rao Algorithm for the Maximum Flow Problem

CSCE 310J Data Structures & Algorithms. Dynamic programming 0-1 Knapsack problem. Dynamic programming. Dynamic Programming. Knapsack problem (Review)

PARALLELIZED SUDOKU SOLVING ALGORITHM USING OpenMP

Decision Mathematics D1 Advanced/Advanced Subsidiary. Tuesday 5 June 2007 Afternoon Time: 1 hour 30 minutes

Social Media Mining. Graph Essentials

Lecture 13: The Knapsack Problem

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

1 Review of Newton Polynomials

Data Structures Fibonacci Heaps, Amortized Analysis

LARGE CLASSES OF EXPERTS

The ADT Binary Search Tree

Algorithms and Data S tructures Structures Stack, Queues, and Applications Applications Ulf Leser

Algorithm Design and Recursion

Hardware Configuration Guide

CS711008Z Algorithm Design and Analysis

Scheduling Algorithms for Downlink Services in Wireless Networks: A Markov Decision Process Approach

Binary Search Trees (BST)

10CS35: Data Structures Using C

Algorithms and Data Structures

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

CSC2420 Spring 2015: Lecture 3

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

An Introduction to The A* Algorithm

TU e. Advanced Algorithms: experimentation project. The problem: load balancing with bounded look-ahead. Input: integer m 2: number of machines

Lecture 13 - Basic Number Theory.

State History Storage in Disk-based Interval Trees

Analysis of Binary Search algorithm and Selection Sort algorithm

Vector storage and access; algorithms in GIS. This is lecture 6

Chapter 11 Monte Carlo Simulation

Problem Set 7 Solutions

Graph Theory Problems and Solutions

Load Balancing. Load Balancing 1 / 24

Sequential Data Structures

A hierarchical multicriteria routing model with traffic splitting for MPLS networks

SIMS 255 Foundations of Software Design. Complexity and NP-completeness

Reliability Reliability Models. Chapter 26 Page 1

SEQUENCES ARITHMETIC SEQUENCES. Examples

Discuss the size of the instance for the minimum spanning tree problem.

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

Optimizing College Degree Plan

Near Optimal Solutions

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Midterm Practice Problems

The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 72.

Project and Production Management Prof. Arun Kanda Department of Mechanical Engineering Indian Institute of Technology, Delhi

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Optimization Modeling for Mining Engineers

New Admissible Heuristics for Domain-Independent Planning

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Lecture 16 : Relations and Functions DRAFT

CS473 - Algorithms I

Brown Hills College of Engineering & Technology Machine Design - 1. UNIT 1 D e s i g n P h i l o s o p h y

A Branch and Bound Algorithm for Solving the Binary Bi-level Linear Programming Problem

Recursion vs. Iteration Eliminating Recursion

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

On the effect of forwarding table size on SDN network utilization

Sample Questions Csci 1112 A. Bellaachia

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Week_11: Network Models

Decision Mathematics D1. Advanced/Advanced Subsidiary. Friday 12 January 2007 Morning Time: 1 hour 30 minutes. D1 answer book

Transcription:

SEEM 3470: Dynamic Optimization and Applications 2013 14 Second Term Handout 6: More Examples on DP and Shortest Path Problem Instructor: Shiqian Ma February 17, 2014 Suggested Reading: Bertsekas Lecture Slides on Dynamic Programming; Section 2.3 of Chapter 2 of Bertsekas, Dynamic Programming and Optimal Control: Volume I (3rd Edition), Athena Scientific, 2005. 1 The Three-Jug Puzzle An 8-gallon jug is filled with fluid. Given two empty 5- and 3-gallon jugs, we want to derive the 8 gallons of fluid into two equal parts using the three jugs. No other measuring devices are allowed. What is the smallest number of pourings needed to achieve this result? The solution process can be systemarized by representing the problem as a shortest path problem. A node is defined to represent the amount of fluid in the 8-, 5-, and 3-gallon jugs, respectively. This means that the network starts with node (8,0,0) and terminates with the desired solution node (4,4,0). A new node is generated from the current node by pouring fluid from one jug into another. Figure 1 shows different routs that lead from start node (8,0,0) to end node (4,4,0). The arc between two successive nodes represents a single pouring, and hence can be assumed to have a length of 1 unit. The problem reduces to determining the shortest path between node (8,0,0) to node (4,4,0). The optimal solution, given by the bottom path in Figure 1, requires 7 pourings. Figure 1: Three-jug puzzle as a shortest path problem 2 0/1 Knapsack Problem We want to select items from a collection of n items to put into a backpack. The total capacity of the backpack is W. The volumes of the n items are w 1,..., w n, and their values are v 1,..., v n. Decide which items should be put into the backpack to maximize the total value. 1

A binary integer programming formulation is: max s.t. n v i x i i=1 n w i x i W i=1 x i = {0, 1}, i = 1,..., n. Note that there are 2 n possible solutions to be investigated. A DP formulation: Stage i is represented by item i The state at stage i is the volume limit assigned to stages (items) i, i + 1,..., n. Define m[i, w] recursively as m[i, w] = m[i 1, w], m[i, w] = max{m[i 1, w], m[i 1, w w i ] + v i }, if w i w. if w i > w (the new item is more than the current volume limit) Note that m[i, w] is the optimal value using items 1,..., i, when the volume limit is w. The terminal value is m[0, w] = 0 for 0 w W, which corresponds to the situation that no item can be selected. The solution we want to compute is m[n, W ]. To do this efficiently we can use a table to store previous computations. Example: Let W = 10, and i 1 2 3 4 v i 10 40 30 50 w i 5 4 6 3 Then table based on the DP recursive formula is V [i, w] 0 1 2 3 4 5 6 7 8 9 10 i = 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 10 10 10 10 10 10 2 0 0 0 0 40 40 40 40 40 50 50 3 0 0 0 0 40 40 40 40 40 50 70 4 0 0 0 50 50 50 50 90 90 90 90 Clearly, total complexity is O(nW ). A shortest path formulation. Find the longest path in Figure 2. 3 Tower of Hanoi (Resource: http : //en.wikipedia.org/wiki/t ower of Hanoi) This puzzle of Tower of Hanoi consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 2

Figure 2: Knapsack problem as a shortest path problem Only one disk can be moved at a time. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. No disk may be placed on top of a smaller disk. A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached. For example: label the rods A, B, C. let n be the total number of disks number the discs from 1 (smallest, topmost) to n (largest, bottommost) 3

Figure 3: The Tower of Hanoi Puzzle To move n disks from rod A to rod C: move n 1 disks from A to B. This leaves disk n alone on rod A move disk n from A to C move n 1 disks from B to C so they sit on disk n The above is a recursive algorithm, to carry out steps 1 and 3, apply the same algorithm again for n 1. Let S(n) be the minimum number of moves. The DP recursive formula is S(n) = 2S(n 1) + 1. It can be shown that S(n) = 2 n 1, an exponential number! Figure 4: The Tower of Hanoi as a shortest path problem: 1 disk 4

Figure 5: The Tower of Hanoi as a shortest path problem: 2 disks Figure 6: The Tower of Hanoi as a shortest path problem: 3 disks 5