logo

Water Jug Problem

   

Added on  2023-01-19

9 Pages845 Words66 Views
 | 
 | 
 | 
Running head: WATER JUG PROBLEM
WATER JUG PROBLRM
Name of the Student
Name of the University
Author Note
Water Jug Problem_1

WATER JUG PROBLEM 1
WATER JUG PROBLEM:
Two jugs are given, one is a 5 gallon jug and another one is a 3 gallon jug. The
challenge here is to find 3 gallons of water in a 5 gallon jug.
1) What type of graph would you use to model the problem input and how would you
construct this graph?
For the solution the BFS (Breadth-first search) technique can be used by making a
tree to solve the water jug problem. The graph is a directed graph and it is weighted too and
the graph is vertex labelled.
2. Give pseudo code for an algorithm to compute the amount of water that takes the most
moves to reach?
Pseudo code:
Class Jug {
value as integer
capacity as integer
public:
jug is integer
{
initial value is zero
initial capacity is n
}
void Fill() //fill
{
store capacity to value
}
Water Jug Problem_2

2WATER JUG PROBLEM
empty function
{
empty value
}
value is full
{
value is greater than or equal to capacity
}
value is empty
{
empty
}
Transfer the contents hold by B to A till A shows full
{
store new value to old value
store value with b's value to value
if value is greater than capacity
omit old value from new value
}
get new value
{
return to value
}
};
Water Jug Problem_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents