Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Algorithmic problems?. The 3 water jug problem There are three jugs on the table - 3, 5, and 8 ltr. The first two are empty, the last contains 8 ltr.

Similar presentations


Presentation on theme: "The Algorithmic problems?. The 3 water jug problem There are three jugs on the table - 3, 5, and 8 ltr. The first two are empty, the last contains 8 ltr."— Presentation transcript:

1 The Algorithmic problems?

2 The 3 water jug problem There are three jugs on the table - 3, 5, and 8 ltr. The first two are empty, the last contains 8 ltr. of water. By pouring water from one glass to another make at least one of them contain exactly 4 ltr. of water.

3 3 Water Jug Problem

4 The 3 water jug solution Move from 3 to 1 Move from 1 to 2 Move from 3 to 1 Move from 1 to 2 Move from 2 to 3 Move from 1 to 2 Move from 3 to 1 Final - Jug1: 3, Jug2: 1, Jug3:4

5 The Tower of Hanoi The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It 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 rules: Only one disk may be moved at a time. Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod. No disk may be placed on top of a smaller disk.

6 The Tower of Hanoi

7 The Tower of Hanoi (Solution) If Disks are 3: Move from Src to Dst Move from Src to Aux Move from Dst to Aux Move from Src to Dst Move from Aux to Src Move from Aux to Dst Move from Src to Dst

8 The Tower of Hanoi (Solution) If Disks are 4: Move from Src to Aux Move from Src to Dst Move from Aux to Dst Move from Src to Aux Move from Dst to Src Move from Dst to Aux Move from Src to Aux Move from Src to Dst Move from Aux to Dst Move from Aux to Src Move from Dst to Src Move from Aux to Dst Move from Src to Aux Move from Src to Dst Move from Aux to Dst

9 The Tower of Hanoi (Solution) 1.Move top N-1 disks from Src to Aux (using Dst as intermediary peg). 2.Move bottom disk from source to destination. 3.Move N-1 disks from Aux to Dst (using Src as an intermediary peg).


Download ppt "The Algorithmic problems?. The 3 water jug problem There are three jugs on the table - 3, 5, and 8 ltr. The first two are empty, the last contains 8 ltr."

Similar presentations


Ads by Google