Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Only need the code, thank you so much Problem Description In this lab you will be writing your first Java methods. Declare them all as
Only need the code, thank you so much
Problem Description In this lab you will be writing your first Java methods. Declare them all as static as shown in Chapter 8 of the textbook In graph theory, a clique, also known as a complete graph, is a collection of nodes and edges where every node is connected to every other node through an edge. In a clique with n nodes, we can label the nodes with the integers 0,1 A common way to represent a graph IS through an adjacency matrix. This is a matnx where element at position x y that is the cell at row x and column y, denotes whether nodes x and y are connected through an edge. If the nodes are connected, then the value of the (x, y) cell is 1; otherwise, the value is 0. An adjacency matrix representing a clique graph should have 1 in all positions but the diagonal: since the (x, x) connection is trivial, the value of all elements in the diagonal of the matrix should be 0 Another matrix that we can use to represent a graph is what we will call a links matrix. This is again an n x n matrix. However, if nodes x and y are connected through an edge, then the cell at row x and column y should contain the edge represented as (x, y) Example For a clique of size 4, the adjacency matrix will be e111 1e11 1 10 1 11 1 8 while the links matrix will be (2, 3) Tasks Write a class CliqueGeneration that contains the following methods public static int[)[) adjace This method should create and return an adjacency matrix given the size of the clique public static int[J linksMatrix (int n) This method should create and return a links matrix given the size of the clique Suppose that a is the int[] [ ] [ ] links array Note that a[i] [j) an array tself if nodes i and J are connected then a [1] [j] should be the array [i, j]. So, a [1] [j] [0] should be set to i and a [i] [j] 1] should be equal to j. fi = j, then a [i] [j] should be null public static void printAdjMatrix (int []] a) This method should print on the screen a given adjacency matrix. public static void printlinksMatrix (int[]010] a) This method should print on the screen a given links matrix. public static void main (String[] args) The nain method should receive the integer n as input through the command line and the args array. Then, the main method should create and print the adjacency matrix and the links matrix. The args array is the array that is passed as argument to the main method. It contains the strings that we may pass as input to our code when we run it. Consult with the TAs on how to use the args array, this example is also useful. Sample Output If you provide the argument 9 through the args array, then the output of your nain should be 111101111 (2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8) (3, 4) (3, 5) (3, 6) (3, 7) (3, 8) 4, 5) (4, 6) (4, 7) (4, 8) (5, 6) (5, 7) (5, 8) (6, 7) (6, 8) (7, 8)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started