SlideShare ist ein Scribd-Unternehmen logo
1 von 2
A three coloring of a graph labels each vertex v with one of three colors, say R, B or G, so that
the two endpoints of any edge have different colors. Consider an undirected graph which is a
single path, i.e., where the vertices are v_1...v_n, and there is an edge between each v_i and
V_i+1 for i = 1..n - 1. How many 3 colorings does this graph have? (2 points correct answer, 1
point short explanation). How many bits are required to describe such a 3-coloring? (2 points
correct answer, 1 point short explanation) Give coding and decoding algorithms that given the 3-
coloring, outputs a string of the length above that codes it, and given the code, outputs the
original 3-coloring. (3 points algorithm description, 1 point short explanation)
Solution
program :
#include<stdio.h>
int G[50][50],x[50]; //G:adjacency matrix,x:colors
void next_color(int k){
int i,j;
x[k]=1; //coloring vertex with color1
for(i=0;i<k;i++){ //checking all k-1 vertices-backtracking
if(G[i][k]!=0 && x[k]==x[i]) //if connected and has same color
x[k]=x[i]+1; //assign higher color than x[i]
}
}
int main(){
int n,e,i,j,k,l;
printf("Enter no. of vertices in the graph: ");
scanf("%d",&n); //total number of vertices in the graph
printf("Enter no. of edges in the graph : ");
scanf("%d",&e); //total edges in the graph
for(i=0;i<n;i++)
for(j=0;j<n;j++)
G[i][j]=0; //assign 0 to all index of adjacency matrix initially
printf("enter with which vertices there is an edge 1--> ");
for(i=0;i<e;i++){
scanf("%d %d",&k,&l);
G[k][l]=1;
G[l][k]=1;
}
for(i=0;i<n;i++)
next_color(i); //coloring each vertex
printf("Colors of vertices --> ");
for(i=0;i<n;i++) //displaying color of each vertex
printf("Vertex[%d] : %d ",i+1,x[i]);
return 0;
}

Weitere ähnliche Inhalte

Ähnlich wie A three coloring of a graph labels each vertex v with one of three col.docx

Color Image Processing.pptx
Color Image Processing.pptxColor Image Processing.pptx
Color Image Processing.pptx
Antu Chowdhury
 

Ähnlich wie A three coloring of a graph labels each vertex v with one of three col.docx (20)

A Hypocoloring Model for Batch Scheduling Problem
A Hypocoloring Model for Batch Scheduling ProblemA Hypocoloring Model for Batch Scheduling Problem
A Hypocoloring Model for Batch Scheduling Problem
 
CS6702 Unit III coloring ppt
CS6702   Unit III coloring pptCS6702   Unit III coloring ppt
CS6702 Unit III coloring ppt
 
graph theory
graph theorygraph theory
graph theory
 
List Coloring.pptx
List Coloring.pptxList Coloring.pptx
List Coloring.pptx
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Test
TestTest
Test
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 
Convolutional Codes And Their Decoding
Convolutional Codes And Their DecodingConvolutional Codes And Their Decoding
Convolutional Codes And Their Decoding
 
algo1
algo1algo1
algo1
 
Fuvest 2021 - fechada
Fuvest 2021 - fechadaFuvest 2021 - fechada
Fuvest 2021 - fechada
 
Cs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer keyCs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer key
 
Color to Gray and back’ using normalization of color components with Cosine, ...
Color to Gray and back’ using normalization of color components with Cosine, ...Color to Gray and back’ using normalization of color components with Cosine, ...
Color to Gray and back’ using normalization of color components with Cosine, ...
 
Algorithms Design Assignment Help
Algorithms Design Assignment HelpAlgorithms Design Assignment Help
Algorithms Design Assignment Help
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Hamiltonian Chromatic Number of Graphs
Hamiltonian Chromatic Number of GraphsHamiltonian Chromatic Number of Graphs
Hamiltonian Chromatic Number of Graphs
 
Hamiltonian Chromatic Number of Graphs
Hamiltonian Chromatic Number of GraphsHamiltonian Chromatic Number of Graphs
Hamiltonian Chromatic Number of Graphs
 
Logistics Management Assignment Help
Logistics Management Assignment Help Logistics Management Assignment Help
Logistics Management Assignment Help
 
Color Image Processing.pptx
Color Image Processing.pptxColor Image Processing.pptx
Color Image Processing.pptx
 
Extended online graph edge coloring
Extended online graph edge coloringExtended online graph edge coloring
Extended online graph edge coloring
 
Retooling of Color Imaging in ihe Quaternion Algebra
Retooling of Color Imaging in ihe Quaternion AlgebraRetooling of Color Imaging in ihe Quaternion Algebra
Retooling of Color Imaging in ihe Quaternion Algebra
 

Mehr von janettjz6sfehrle

-Conley is the CEO of a major academic med- ical center in the midwest.docx
-Conley is the CEO of a major academic med- ical center in the midwest.docx-Conley is the CEO of a major academic med- ical center in the midwest.docx
-Conley is the CEO of a major academic med- ical center in the midwest.docx
janettjz6sfehrle
 
-10 Points- Description In this assignment you will translate a system.docx
-10 Points- Description In this assignment you will translate a system.docx-10 Points- Description In this assignment you will translate a system.docx
-10 Points- Description In this assignment you will translate a system.docx
janettjz6sfehrle
 
----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docx
janettjz6sfehrle
 
- Interpret the data in each of the cases using 2 different nontechnic.docx
- Interpret the data in each of the cases using 2 different nontechnic.docx- Interpret the data in each of the cases using 2 different nontechnic.docx
- Interpret the data in each of the cases using 2 different nontechnic.docx
janettjz6sfehrle
 

Mehr von janettjz6sfehrle (20)

1 - how do you think Telehealth will impact and expand healthcare prac.docx
1 - how do you think Telehealth will impact and expand healthcare prac.docx1 - how do you think Telehealth will impact and expand healthcare prac.docx
1 - how do you think Telehealth will impact and expand healthcare prac.docx
 
01 (10 points) Create a file called 01-py- This file will use one posi.docx
01 (10 points) Create a file called 01-py- This file will use one posi.docx01 (10 points) Create a file called 01-py- This file will use one posi.docx
01 (10 points) Create a file called 01-py- This file will use one posi.docx
 
0-05) (Give three decimal places).docx
0-05) (Give three decimal places).docx0-05) (Give three decimal places).docx
0-05) (Give three decimal places).docx
 
-The melanocortin 1 receptor(MC1R) has emerged as a melanoma susceptib.docx
-The melanocortin 1 receptor(MC1R) has emerged as a melanoma susceptib.docx-The melanocortin 1 receptor(MC1R) has emerged as a melanoma susceptib.docx
-The melanocortin 1 receptor(MC1R) has emerged as a melanoma susceptib.docx
 
-Reuploaded since the solution I got before was not what the assignmen.docx
-Reuploaded since the solution I got before was not what the assignmen.docx-Reuploaded since the solution I got before was not what the assignmen.docx
-Reuploaded since the solution I got before was not what the assignmen.docx
 
-Please give me some time to put away my laptop- We can have a convers.docx
-Please give me some time to put away my laptop- We can have a convers.docx-Please give me some time to put away my laptop- We can have a convers.docx
-Please give me some time to put away my laptop- We can have a convers.docx
 
-H1-3- (inverse- py) Write a complete Python program- It should prompt.docx
-H1-3- (inverse- py) Write a complete Python program- It should prompt.docx-H1-3- (inverse- py) Write a complete Python program- It should prompt.docx
-H1-3- (inverse- py) Write a complete Python program- It should prompt.docx
 
-Ferns differ from mosses in having A function of the roots is to abso.docx
-Ferns differ from mosses in having A function of the roots is to abso.docx-Ferns differ from mosses in having A function of the roots is to abso.docx
-Ferns differ from mosses in having A function of the roots is to abso.docx
 
-Choose- A line that can be applied above- below or to the sides of a.docx
-Choose- A line that can be applied above- below or to the sides of a.docx-Choose- A line that can be applied above- below or to the sides of a.docx
-Choose- A line that can be applied above- below or to the sides of a.docx
 
-Conley is the CEO of a major academic med- ical center in the midwest.docx
-Conley is the CEO of a major academic med- ical center in the midwest.docx-Conley is the CEO of a major academic med- ical center in the midwest.docx
-Conley is the CEO of a major academic med- ical center in the midwest.docx
 
-51003i+2i2.docx
-51003i+2i2.docx-51003i+2i2.docx
-51003i+2i2.docx
 
-2- num_list ---.docx
-2- num_list ---.docx-2- num_list ---.docx
-2- num_list ---.docx
 
-10 Points- Description In this assignment you will translate a system.docx
-10 Points- Description In this assignment you will translate a system.docx-10 Points- Description In this assignment you will translate a system.docx
-10 Points- Description In this assignment you will translate a system.docx
 
----------Evaluator-java---------------- package evaluator- import j.docx
----------Evaluator-java---------------- package evaluator-   import j.docx----------Evaluator-java---------------- package evaluator-   import j.docx
----------Evaluator-java---------------- package evaluator- import j.docx
 
---During period of illness - infection can easily be spread- It is al.docx
---During period of illness - infection can easily be spread- It is al.docx---During period of illness - infection can easily be spread- It is al.docx
---During period of illness - infection can easily be spread- It is al.docx
 
- Write-up (Individual) What is the EI Nio Southern Oscillation (ENSO).docx
- Write-up (Individual) What is the EI Nio Southern Oscillation (ENSO).docx- Write-up (Individual) What is the EI Nio Southern Oscillation (ENSO).docx
- Write-up (Individual) What is the EI Nio Southern Oscillation (ENSO).docx
 
- yoars (Round to two decimal places as needed).docx
- yoars (Round to two decimal places as needed).docx- yoars (Round to two decimal places as needed).docx
- yoars (Round to two decimal places as needed).docx
 
- This person- role- or group will be a subject matter expert who can.docx
- This person- role- or group will be a subject matter expert who can.docx- This person- role- or group will be a subject matter expert who can.docx
- This person- role- or group will be a subject matter expert who can.docx
 
- Interpret the data in each of the cases using 2 different nontechnic.docx
- Interpret the data in each of the cases using 2 different nontechnic.docx- Interpret the data in each of the cases using 2 different nontechnic.docx
- Interpret the data in each of the cases using 2 different nontechnic.docx
 
- Python Programming Section 01 Spring 2023 CO Write a Python program.docx
- Python Programming Section 01 Spring 2023 CO Write a Python program.docx- Python Programming Section 01 Spring 2023 CO Write a Python program.docx
- Python Programming Section 01 Spring 2023 CO Write a Python program.docx
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

A three coloring of a graph labels each vertex v with one of three col.docx

  • 1. A three coloring of a graph labels each vertex v with one of three colors, say R, B or G, so that the two endpoints of any edge have different colors. Consider an undirected graph which is a single path, i.e., where the vertices are v_1...v_n, and there is an edge between each v_i and V_i+1 for i = 1..n - 1. How many 3 colorings does this graph have? (2 points correct answer, 1 point short explanation). How many bits are required to describe such a 3-coloring? (2 points correct answer, 1 point short explanation) Give coding and decoding algorithms that given the 3- coloring, outputs a string of the length above that codes it, and given the code, outputs the original 3-coloring. (3 points algorithm description, 1 point short explanation) Solution program : #include<stdio.h> int G[50][50],x[50]; //G:adjacency matrix,x:colors void next_color(int k){ int i,j; x[k]=1; //coloring vertex with color1 for(i=0;i<k;i++){ //checking all k-1 vertices-backtracking if(G[i][k]!=0 && x[k]==x[i]) //if connected and has same color x[k]=x[i]+1; //assign higher color than x[i] } } int main(){ int n,e,i,j,k,l; printf("Enter no. of vertices in the graph: "); scanf("%d",&n); //total number of vertices in the graph printf("Enter no. of edges in the graph : "); scanf("%d",&e); //total edges in the graph for(i=0;i<n;i++) for(j=0;j<n;j++) G[i][j]=0; //assign 0 to all index of adjacency matrix initially printf("enter with which vertices there is an edge 1--> ");
  • 2. for(i=0;i<e;i++){ scanf("%d %d",&k,&l); G[k][l]=1; G[l][k]=1; } for(i=0;i<n;i++) next_color(i); //coloring each vertex printf("Colors of vertices --> "); for(i=0;i<n;i++) //displaying color of each vertex printf("Vertex[%d] : %d ",i+1,x[i]); return 0; }