Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views2 pages

Water Jug Problem Seudo Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Water Jug Problem Seudo Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Water Jug Problem

Jug = A(4L), Jug = B(3L)

Problem = we have to fill the jug A with 2 liter, And B with N liter

This problem can be solve by the three steps


1. Initialization/state description
2. Possible Action
3. Final Output

STEP 1:
Initialization and stare description

Let P= Jug A

Let Q = Jug B

P = 0<=P<=4

Q= 0<=Q<=3

Initial state = Both jug are empty, P=0,Q=0

Goal Stae = P=2, q= N

STEP 2=
1. Fill jug A with 4L OF WATER

[P=4, Q]

2. Fill Jug B with 3l Of water

[P=0, Q= 3]

3. EMPTY JUG A [P=0, Q]


4. EMPTY JUG B[ P,Q=0]
5. Transfer complete water from B to A[P,Q]….>[P+Q, 0]
6. Transfer Complete water from A to B[0, Q+P]
7. Transfer some water from B to A till A gets full [P, Q-(4-P)]
8. Transfer some water from A to B till B gets full [P-(3-Q), Q ]
STEP 3
P=0, Q=0

P=0, Q=3(RULE 2)

P=3, Q=0(RULE 5)

P=3, Q=3(RULE= 2)

P=4, Q=2(RULE 7)

P=0, Q= 2(RULE 3)

P=2, Q=0(RULE 5) Goal State

You might also like