DISCRETE STRUCTURES AND ITS APPLICATIONS. MATH (DISCRETE MATHEMATICS)
(ONLY ANSWER IF YOU KNOW THE ANSWER PLEASE DON'T GUESS)
PLEASE WRITE A FULL C++ PROGRAM. A PROGRAM THAT TAKES IN USER INPUT AND CAN BE DEBUGGED AND PRODUCES THE OUTPUT(DISPLAY).. (Please use comments to explain if you can)
1. WRITE A FUNCTION WHICH TAKES A DEGREE SEQUENCE AND CHECKS THAT THE SUM OF THE DEGREES IS EVEN AND ALSO THAT THERE IS AN EVEN NUMBER OF VERTICES OF ODD DEGREE. IF THE DEGREE SEQUENCE IS NOT A VALID GRAPH, RETURN FALSE. IF THERE IS A 'POSSIBILITY' IT IS VALID GRAPH RETURN TRUE. (NOTE: IN THIS CASE TRUE JUST MEANS 'MAYBE')
Following is a C++ program which takes n(number of vertices in the graph) and degree sequence of length n as input and outputs the result according to the possibility of validity of the sequence.
the function is_valid() return FALSE if the given degree sequence is not a valid graph and TRUE if there is a possibility of the given sequence to be a valid graph.
1.SUM OF ALL DEGREES OF VERTICES IS EVEN
2,NUMBER OF ODD DEGREE VERTICES IS EVEN
BOTH CONDITION 1 AND 2 ARE SAME THING, JUST A DIFFERENT WAY OF SAYING SAME THINGS, AS IF NUMBER OF ODD DEGREE VERTICES ARE NOT EVEN THEN THE SUM WILL ALWAYS BE ODD AND VICE-VERSA.
please see the code below:
//code begins............
#include <iostream>
using namespace std;
//function to check validity of the degree sequence.
bool is_valid(int degree_sequence[],int n){
int sum=0;//sum stores the sum of all degrees of vertices of given
graph.
int odd_degree_vertices=0;//odd_degree_vertices stores the number
of vertices having odd degree.
for(int i=0;i<n;i++){
if(degree_sequence[i]%2!=0){//check for odd degree vertex.
odd_degree_vertices+=1;
}
sum=sum+degree_sequence[i];//adding to sum variable.
}
//these two conditions mentioned in the if condition below will
occur
// simultaneously as these are one and the same thing but due to
the problem statement
// which tells us to check both conditions so i checked it for the
sake of the problem statement.
if(sum%2!=0 || odd_degree_vertices%2!=0){
return false;
}
else{
return true;
}
}
int main(){
// n is the number of vertices in the graph(size of degree
sequence)
cout<<"Enter number of vertices in the graph or the size of
given degree sequence."<<"\n";
int n;
cin>>n;
//dynamic allocation of array.
int *degree_sequence=new int[n];
cout<<"Enter the degree
sequence."<<"\n";
for(int i=0;i<n;i++){
int d;
//input degree sequence one by one and storing it in
array.
cin>>d;
degree_sequence[i]=d;
}
//boolean returned by function to check
validity.
bool check_validity=is_valid(degree_sequence,n);
if(check_validity){
cout<<"There is a possibility that the given
degree sequence represent a valid graph."<<"\n";
}
else{
cout<<"The degree sequence is not a valid graph
as the sum of all degrees is not even."<<"\n";
}
return 0;
}
//code ends.
Below is the attachment of the snapshot of the code in the editor and the output corresponding to a particular input.
INPUT :
6
5 5 4 3 2 1
As the sum of given degree sequence is 20 which is even and the number of odd degree vertex is 4(which is even) so there is a possibility that the given degree sequence is a valid graph.
You can read about havel-hakimi theorem for more understanding of concept of checking if a degree sequence is a valid graph or not..
SO ABOVE IS THE SOLUTION TO THE PROBLEM , I HAVE GIVEN MY BEST EFFORT TO MAKE YOU UNDERSTAND THE CODE SNIPPET WITH SUITABLE COMMENTS AND EXAMPLE INPUT AND PLEASE COMMENT IF YOU HAVE ANY QUERY . SO IF IT HELPED(MAY IT BE VERY LITTLE) YOU IN ANY WAY, PLEASE UPVOTE MY SOLUTION.ALWAYS IN YOUR SERVICE.
THANK YOU.
DISCRETE STRUCTURES AND ITS APPLICATIONS. MATH (DISCRETE MATHEMATICS) (ONLY ANSWER IF YOU KNOW THE ANSWER PLEASE...
Please write your answer clearly and easy to read. Please only answer the ones you can. I will upvote all the submitted answers. Question 5. Prove by contradiction that every circuit of length at least 3 contains a cycle Question 6. Prove or disprove: There exists a connected graph of order 6 in which the distance between any two vertices is even Question 7. Prove formally: If a graph G has the property that every edge in G joins a...
DISCRETE MATH: Please help verify if my answers are correct, thanks! If wrong please explain why Leap year 6. True CFalse7059 days after a Monday is a Friday 7. True False In a group of 200 people, we can be sure there are at least 30 born on the same day of the week. 7 8. True (False There is no closed form formula for the Fibonacci sequence. 9. True (False:an is a solution to the recurrence ao -0 and...
Discrete Math and Computer Science I need help with #2 the programming part is in C++ Thank you! Main topic and problems for the final project The main purpose of the project is to introduce you how to use a computer as a research tool in an Introductory Discrete Mathematics. In this project you will be asked to show how the Fibonacci sequence (F,) is related to Pascal's triangle using the following identities by hand for small n and then...
w Problem Statement: In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many quantities, one after the other, to a given starting quantity. The study of series is a major part of calculus and its generalization, mathematical analysis. Mathematically, the n" number of a mathematical series is defined as follows: T. -Σ . . Write a CH program that: Reads a positive integer k from the user. If the user enters a negative value,...
please help me make this into a contradiction or a direct proof please. i put the question, my answer, and the textbook i used. thank you also please write neatly proof 2.5 Prove har a Simple sraph and 13 cdges cannot be bipartite CHint ercattne gr apn in to ertex Sets and Court tne忤of edges Claim Splitting the graph into two vertex, Sets ves you a 8 Ver ices So if we Change tne书 apn and an A bipartite graph...
Discrete Math Answer all questions on another sheet of paper. You do not need to print out or recopy the questions. Please skip lines and write legibly. Reading Worksheet-Sections 2.1 and 2.2 1. s the sentence below a "proposition"? Why or why not? Maurice is enrolled in Discrete Math this semester. 2. Let p: "Arnold likes to read science fiction." Let q: "Arnold is a baseball player." a) If p is false and q is true, what can you say...
Please do it by C++ programming! By completing this project, you will demonstrate your understanding of: 1) Arithmetic operations (addition, subtraction, multiplication, division, modulus) 2) Conditional statements (If, If-Else, If-ElseIf-Else, Conditional Operator, Switch) 3) Precondition, postcondition, and indexing loops (Do-While, While, For) 4) Standard text file operations (open, close, read, write) 5) Modularizing code by breaking into functions (including functions with input parameters, and ones that return a specific data type) There is a number guessing game similar to MasterMind...
MAT243 Project #3 MAT 243: Discrete Math Structures Project 3 Sequencing Sequences of numbers are a useful mathematical tool for exploring transitions and trends. Sequences of symbols create words, and sequences of words create languages, both Human and Computer. While sequences of nucleotides create DNA, which in turn create new sequences of nucleotides called RNA, which in turn creates sequences of amino acids called proteins, which in turn create, among other things, humans that create, among other things, computers. The...
Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...
IT Review JAVASCRIPT (Can someone please help me answer the below questions. It would be nice if you add comments explaining what you are doing? If unable to add comments the answer would be fantastic. Thank you. Given the following function definition: function percent(x) { return x / 100; } Which of the following statements correctly calls the percent function: percent(10); percent: 10; percent(); percent = 10; Indicate whether each of the following evaluates to true or false, given...