EXAMPLES OF FUNCTIONS/ALGORITHMS
please in c++
b. Write a function that return true if an undirected graph is complete, false otherwise
The question is quite ambiguous. You should have specified how the edges are stored (like adjacency matrix or adjacency list, etc,.). Any way I will write two functions because the task can be done in two ways. The parameters to the functions will be different.
1. If a graph with 'V' vertices is complete, then total number of edges should be V*(V-1)/2; The time compexity for this approach would be O(1) the function for this would look like.
bool checkGraph(int v, int e)
{
int must_edges = v*(v-1)/2;
if(must_edges==e) return true;
else return false;
}
2. If we have an Adjacency matrix then all the vertices must be connected and this has to be checked in matrix. If we found any connection is missing we return false. The time compexity for this approach would be O(V^2), The function for it would look like
bool checkGraph(vector<vector<int> > v)
{
for(int i=0;i<v.size()-1;i++)
{
for(int j=i+1;j<v.size();j++)
{
if(v[i][j]==0) return false;
}
}
return true;
}
EXAMPLES OF FUNCTIONS/ALGORITHMS please in c++ b. Write a function that return true if an undirected graph is complete, false otherwise
Modify the function to return true if both arguments are true, and return false otherwise. function areBoth True(bool1, bool2) console.log(areBoth True(true, false), 'should be false'); console.log(areBoth True(true, true), 'should be true');
10. TRUE or FALSE: Write TRUE if the statement is always true; otherwise, write FALSE. _a. {0} c{{0}, {{0}}} _b. Ø $ ({1, 2}), the power set of {1,2} c. If5<3 then 8 is an odd integer. d. The relation R = {(a,b), (b,a)} is symmetric but not transitive on the set X = {a,b}. e. The relation {(1,2), (2,2)} is a function from A={1,2} to B={1,2,3} _f. If the equivalence relation R = {(1,1), (2,2), (3,3), (4,4), (1,3), (3,1),...
Answer the following true or false questions with a brief justification. A) There exists an undirected graph on 6 vertices whose degrees are 4, 5, 8, 9, 3, 6. B) Every undirected graph with n vertices and n − 1 edges is a tree. C) Let G be an undirected graph. Suppose u and v are the only vertices of odd degree in G. Then G contains a u-v path.
17.True or False: Algorithms should be specified in pseudocode before they are implemented in C. 18. True or False: In C, false is defined as any result that is zero. 19. True or False: An advantage to defining functions in C is that they may be reused in other projects. 20. True or False: Suppose a function main calls a function f. As a parameter to f, main passes a pointer p to a struct. Further suppose that f's body modifies p by...
Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...
A large, commercial program will define one functions Select one: True False Function return-type specifies the type of data returned by the function. This can (int, double, array, float). Select one: True False
C# - Write C# method IsSymmetricArray that returns true if the array is symmetric and false otherwise. You need to call this method in the Main Method . Example: b={ 6,3,2,3,6} is symmetric. d= {6,3,3,6} is symmetric. e= { 1,3,3,2} is not symmetric.
Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...
Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...
Please write a python function for :
greedy: This function takes two inputs: one a graph, and the other an ordering of the vertices as a list, and returns the proper vertex-coloring produced by the greedy algorithm over the ordering in the list. Examples: greedy({"A" : ["B", "C"], "B" : ["A"], "C" : ["A"]},[“A”, “B”, “C”]) should return {“A” : 1, “B” : 2, "C" : 2} greedy({“A” : ["B"], "B" : [“A”, “C”],"C" : [“B”, “D”), “D" : ["C"]},[“A”,...