Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Backtracking/Water Jug Problem/Images/ss1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Backtracking/Water Jug Problem/Images/ss2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions Backtracking/Water Jug Problem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Water Jug Problem

## Aim

The aim is to solve Water Jug Problem using BFS or DFS as per user's choice.


## Purpose

Given Problem: You are given a 'm' liter jug and a 'n' liter jug where '0<m<n'. Both the jugs are initially empty. The jugs don't have markings to allow measuring
smaller quantities. You have to use the jugs to measure 'd' liters of water where 'd<n'. Determine the minimum no of operations to be performed to obtain 'd' liters of
water in one of jug. The **purpose** is to come up with a solution for this problem.


## Short description of package/script

- The problem is solved by BFS/DFS as per user's choice.
- Backtracking is used for keeping track of all the visited nodes and possible solutions.
- Complete steps get printed with each and every state mentioned.


## Workflow of the Project

Description of functions used in the code and their purpose:

get_search_type --> This method accepts an input for asking the choice for type of searching required i.e. BFS or DFS.

get_jugs --> This method accept volumes of the jugs as an input from the user.

get_goal --> This method returns the desired amount of water as goal.

is_goal --> This method checks whether the given path matches the goal node.

been_there --> This method validates whether the given node is already visited.

next_transitions --> This method returns the list of all possible transitions.

print_path --> This method prints the goal path.

search --> This method searches for a path between starting node and goal node.

After the desired values are entered by the user, the 'search' function is called to find the path/solution (if one exists).


## Compilation Steps

After the script is run, enter:
1. The volume for first jug.
2. The volume of secong jug.
3. The desired amount of water.
4. Choose the search technique.
That's it! All the steps to the goal state (if found) will be listed.


## Output

<img width = 300 height = 600 src="https://github.com/prathimacode-hub/Learn-Data_Structure-Algorithm-by-Python/blob/master/Backtracking/Water%20Jug%20Problem/Images/ss1.png">
<img width = 300 height = 600 src="https://github.com/prathimacode-hub/Learn-Data_Structure-Algorithm-by-Python/blob/master/Backtracking/Water%20Jug%20Problem/Images/ss2.png">


Loading