How to create a CSS 3D BUTTON Design – **CSS Animation Button Design Tutorial Free Download**

Continue…

**Hands-on Graph Algorithms**

Then it is seen that it either increases by 2 or decreases by 2 or remains the same, so the number of nodes of odd degree is always even.

Similarly, it can be shown that the sum of the degrees of a graph is twice the number of edges. In the graph above, the sum of degrees is 10, and the number of edges is 5.

Part 2: Graph Representation

We will now learn how to take the graph input and save it in a variable. There are many methods, 2 methods are more convenient, they are:

Adjacency matrix

Adjacency list

Adjacency Matrix:

We have learned what are called adjacent nodes in a graph. The concept of the adjacency matrix is very simple, we will take a 2D array or matrix, then if there is an edge between two nodes i,j then we will put 1 in that position of the array. See the image below:

Edges can be weighted, for example an edge from Dhaka to Chittagong can say the distance between the two cities is 300 km. Then you have to put weights in the matrix as well.

The above graph is bidirectional or undirected, i.e. if you can go from 1 to 2, you can also go from 2 to 1. If the graph were directed then there would be arrows between the edges. We can still store in the matrix as before. All the cases are nicely shown in the image below:

Note that if the graph is undirected, the matrix becomes symmetric, i.e. mat[i][j]=mat[j][i].

Exercise 1.1:

a) Imagine a graph with 3 nodes with edge number 3, and all edges are bidirectional. The edges are 1-2 (cost 5), 2-3 (cost 8), 1-3 (cost 3). How will its adjacency matrix?

b) Programming Exercise: You will be given a directed graph input. The first line will have node number N and edge number E. Then there will be E lines, in each line the edges will be given in the format “node-1 node-2 cost”. The output will be the grafter adjacency matrix.

**CSS Animation Button Design Tutorial Free Download**

Problems with using adjacency matrix:

We will do a short exercise to understand the pitfalls of using adjacency matrix.

Exercise 1.2:

a) You have a graph of 100 nodes. Using a 2D integer array you create the adjacency matrix. How many megabytes of memory will this matrix take up?

b) How many megabytes of space will be required if the number of nodes is N?

c) Does the matrix take up more space in memory as the number of edges in the graph increases?

d) What is the maximum number of nodes you need to check to find out which nodes are adjacent to a node?

Advantages of using adjacency matrix:

We can easily check mat[u][v] whether there is an edge between the u-v nodes or how much the cost is. That is, the time complexity is O(1).

Adjacency List:

Now we will create a list like the list to market:

Now create a list like the marketing list:

Node 1 is connected -> Nodes 2 and 4

Node 2 is connected -> Node 1, 4 and 5

Node 3 is connected -> Node 5 and 6

Node 4 is connected -> Node 1,2 and 5

Node 5 is connected -> Node 2,3 and 4

6 is associated with Node -> Node 3 and 6

This is the adjacency list, a list of which nodes are connected to which nodes. This is the adjacency list. Each node will have a list containing the names of adjacent nodes.

Advantages of Adjacency List:

We can save the graph in memory as many edges as there are. Memory complexity for saving graph in matrix was O(N*N), here complexity is O(E). But in a graph, the number of edges can be E but N*N, in which case the memory will be the same. The smaller the edge, the less memory the list takes.

It is not necessary to check each node to see which nodes are adjacent to a node, just look at the list.

Disadvantages of Adjacency List:

Loop over the list to check if there is an edge between two nodes u-v. Not possible to extract in O(1) like matrix.

Exercise 1.3

a) Programming Exercise: Take a 2D integer vector. For example it could be: “vector<int>adj_list[number_of_nodes]”. Now input the following directed graph into this vector:

6 8 //node-edge

1 2 //node1-node2

1 4

2 4

2 5

4 5

5 3

3 6

6 6

b) Programming Exercise: Cost is not given with edge in the previous exercise. If the cost is given, the rule is to take another vector in parallel, like “vector<int>cost[number_of_nodes]”. When v pushes the node in adj_list[u], the cost of the u-v edge in cost[u] must be pushed. Another way is to make the adj_list vector instead of an integer and create a structure that contains the node name and cost. Either way, slightly modify the previous code and make it code to take graph input with cost. Test your code with input in the format node1-node2-cost.

**CSS Animation Button Design Tutorial Free Download**

You can now take graph input, and create matrices and lists. Now we will learn some graph algorithms. Before that, another short exercise:

Exercise 1.4:

Programming Exercise: Construct an adjacency list with a directed graph input. Then:

a) For each node print its adjacent nodes in one line.

b) Indegree is the number of nodes entering a node, outdegree is its opposite. Print the outdegree and indegree of each node.

Graph Algorithm 1: Breathed First Search

The task of breathed first search is to find the shortest path in the graph. Breathed first search only works on unweighted graphs, meaning each edge has a cost of 1. Then the path from one node to another node with the least number of edges is the shortest path in the unweighted graph.

In the above graph, the shortest path from 1 to 8 is 1->3->8. There may be multiple shortest paths between two nodes, but with breathed first search we will find only one path.

In the breathed first search, given a source node, at the end of the algorithm, all other nodes find the shortest path from that node.

## Before Download

## You must Join our Facebook Group and Subscribe YouTube Channel

**All Links in Below:**

**Join Our FreeWebsiteCreate Facebook Group to get an instant update for projects, templates, design resources, and solutions.**

**Join Our YouTube Channel & Subscribe with Bell Icon for New Video:**

## Join Our Official Facebook Page For the Latest updates All Code Projects are Free:

## Visit our service page to get **premium services.**

Free Website Create – HTML CSS, PHP, JavaScript Programming Projects For Free

**Follow Us**

**Thank You,**

## Before Download

## You must Join our Facebook Group and Subscribe YouTube Channel

FreeWebsiteCreate.net tries to provide HTML, CSS, SCSS, JavaScript, React, Android Studio, Java, PHP, Laravel, Python, Django, C#(C Sharp), and ASP.net-related projects 100% free. We try to make learning easier. Free Website Create always tries to give free projects to new learners. Free projects and source code will help to learn quickly.

They can save time and learn more. In this post, we share a free portfolio project website code with HTML and CSS. This free code portfolio contains a single landing page with a responsive design. In this post, we get a free best carpenter and craftsman service website designed by FreeWebsiteCreate with HTML, CSS, Bootstrap, and JavaScript.