Question

Using python; We wish to use graph theory in order to solve the following problem. A...

Using python; We wish to use graph theory in order to solve the following problem. A company should carry dierent chemical products P1, P2, : : :, Pk from the factory to a city. For security reasons, some products should not be carried in the same truck: 8i; 0 < i < k; Pi is not compatible with Pi+1. Moreover Pk is not compatible with P1. 1) Write a comment: how can we state an undirected graph that visually represents this problem: 1. What are the vertices, what are the edges? 2. What is the specic property of this graph? 2 2) Write an algorithm that, given an integer k > 1, returns the minimum number of trucks necessary to carry all the products.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

1. There are k vertices in this graph; each corresponding to a chemical product. There will be an edge between two nodes in the graph if and only if they are compatible.

2. This graph will be the complement graph to the cycle graph with k nodes.

2)

Algorithm to find the minimum number of trucks necessary to carry all the products:

## Python code begins ##

def minTrucks(k):
   if k % 2 == 0:
       return 2
   else:
       return 3

## Python code ends ##

How this works:

If there are even number of products, you can do just 2 trucks --- even numbered products in one truck and odd numbered products in the other. The first and kth product will go in separate trucks.

If there are odd number of products, you can still do a similar distribution but now the first and the kth product will go in the same truck. That can't be allowed, so you'll need a third truck to take the kth product.

Add a comment
Know the answer?
Add Answer to:
Using python; We wish to use graph theory in order to solve the following problem. A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT