Question

I saw other student's Q&A that expert answered. but I can't understand this problem. please solve this probl...

I saw other student's Q&A that expert answered. but I can't understand this problem.

please solve this problem.

24. Write an algorithm for the 2-coloring problem whose time complexity is not worst-case exponential in n.

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

Graph coloring problem is NP-Hard. But 2-coloring problem can be solved easily. So, firstly pick any vertex v mark its color to red (lets say) and then mark its all neighbours with the second color (blue lts say). Continue doing this till all the vertices are colored. Now, we check if there is any bad edge (i.e. both the nodes connected to that particular edge have the same color) then the graph cannot be colored with 2 colors else it is possible. This property will hold only for bipartite graphs.

So the algorithm that we are going to use for this is BFS for the graph. Here's the pseudo code

BFS(s):

mark s as visited and push it into the queue

cnt = 0

while(queue is not empty):

v<- queue.remove()

if cnt == 0

color[v] = 1

else

color[v] = 0

for all unvisited neighbours w of v:

mark w as visited

queue.insert(w)

if color[v] == 0:

color[w] = 1

else

color[w] = 0

This was just the BFS part now just check every edge and check if their adjacent nodes have same colors or not

Add a comment
Know the answer?
Add Answer to:
I saw other student's Q&A that expert answered. but I can't understand this problem. please solve this probl...
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
  • Please show the work. I already know the answers, but don't understand how to get there....

    Please show the work. I already know the answers, but don't understand how to get there. 5. Q5. Algorithm Efficiency I. Algorithm A performs (n) binary searches in an array of size n/2. Algorithm B performs e(n) sequential searches in an array of size 4n. Answer the following questions. (a) 1) What is the worst case running time of Algorithm A, in terms of e? (b) [1] What is the worst case running time of Algorithm B, in terms of...

  • please solve this question easiest way I saw the other answers but those are not solve...

    please solve this question easiest way I saw the other answers but those are not solve my program Twin primes are two consequetive odd numbers that are prime. Write a function that returns 1 if the input is a prime and O otherwise. int is_prime(int number) { Write a C Program to generate all twin primes in a given range of numbers using the is_prime function. Your program will input following from the command line: min : start of range,...

  • Please provide solution/methods so I can understand how this work. Given a algorithm with f(n) 5n2...

    Please provide solution/methods so I can understand how this work. Given a algorithm with f(n) 5n2 + 4n + 14 in the worst case, f(n) 3n2 + 17 log, n + 1in the average case, and f(n) in 17 the best case. Which of the following would be the tightest possible asymptotic descriptions of the algorithm? The following statement that would be tightest possible asymptotic description of the algorithm above A) O(n) B) o (n) C) (n?) D) On Log...

  • please I need it urgent thanks algorithms 2.1 Searching and Sorting- 5 points each 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Ex...

    please I need it urgent thanks algorithms 2.1 Searching and Sorting- 5 points each 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Give pseudocode for an algorithm that will solve the following problem. Given an array AlL..n) that contains every number between 1 and n +1 in...

  • problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to...

    problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...

  • Could you please help me to solve the problem. Also, could you please answer questions in...

    Could you please help me to solve the problem. Also, could you please answer questions in clear hand-writing and show me the full process, thank you (Sometimes I get the answer which was difficult to read).Thanks a lot What is the smallest positive value of n, where n is an integer, such that Algorithm A, whose running time is 100n2  runs faster than Algorithm B, whose running time is 2n , on the same machine (give your answer in whole number(s))

  • Would an expert please solve this homework problem. I have not done this in a few...

    Would an expert please solve this homework problem. I have not done this in a few years. Thank you Table 3 The following table gives information on the price, quantity, and total cost of production for a monopolist. Price Output Total Costs $5   0 $3 $4   5   $8 $3 10 $20 $2 15 $33 $1 20 $53 $0 25 $78 10. Refer to Table 15-13. If the monopolist maximizes profits, he will charge a price of a. $2. b. $1....

  • Please show a clean way to organize and solve this problem so I can understand problem...

    Please show a clean way to organize and solve this problem so I can understand problem similar to it in the future A flea jumps by exerting a force of 1.12 x 10-5 N straight down on the ground. A breeze blowing on the flea parallel to the ground exerts a force of 1.16 x 106 N on the flea. Find the direction and magnitude (in m/s2) of the acceleration of the flea if its mass is 6.0 × 10-7...

  • For each problems segment given below, do the following: Create an algorithm to solve the problem...

    For each problems segment given below, do the following: Create an algorithm to solve the problem Identify the factors that would influence the running time, and which can be known before the algorithm or code is executed. Assign names (such as n) to each factor. Identify the operations that must be counted. You need not count every statement separately. If a group of statements always executes together, treat the group as a single unit. If a method is called, and...

  • Please solve #22 with step by step. I need to understand clearly from your solution. also,...

    Please solve #22 with step by step. I need to understand clearly from your solution. also, please use the Hint. When you provide the solution, please write it clearly to be recognizable. 22. Find Z[GL2(R)]. 6. (Center of the matrix group.) Solve Problem 22, Section 2.3, asking you to find the center of the group GL2(R). Hint: Let A= ( 2) be in the center, and write down explicitly the condition that AB = BA for all matrices B= (%)...

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
ADVERTISEMENT