The Wayback Machine - https://web.archive.org/web/20240818030708/https://www.geeksforgeeks.org/what-is-unidrected-graph-undirected-graph-meaning/
Open In App

What is Undirected Graph? | Undirected Graph meaning

Last Updated : 30 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

An undirected graph is a type of graph where the edges have no specified direction assigned to the them.

Example of undirected graph

Example of undirected graph

Characteristics of an Undirected Graph:

  • Edges in an undirected graph are bidirectional in nature.
  • In an undirected graph, there is no concept of a “parent” or “child” vertex as there is no direction to the edges.
  • An undirected graph may contain loops, which are edges that connect a vertex to itself.
  • Degree of each vertex is the same as the total no of edges connected to it.

Applications of Undirected Graph:

  • Social Networks: Undirected graphs are used to model social networks where people are represented by nodes and the connections between them are represented by edges.
  • Traffic flow optimization: Undirected graphs are used in traffic flow optimization to model the flow of vehicles on road networks. The vertices of the graph represent intersections or road segments, and the edges represent the connections between them. The graph can be used to optimize traffic flow and plan transportation infrastructure.
  • Website analysis: Undirected graphs can be used to analyze the links between web pages on the internet. Each web page is represented by a vertex, and each link between web pages is represented by an edge.

Advantages of Undirected Graph:

  • It provides simplicity as they are basic and easy to grasp, making them valuable for representing a wide range of real-world systems.
  • It provides flexibility as they are versatile and may be used to describe a broad range of systems.

Disadvantages of Undirected Graph:

  • It may be undesirable for some applications that need directionality due to their lack of directionality.
  • It provides limited information, In some cases, it may not give enough information about certain systems since they merely capture the existence or absence of edges.

What else can you read?



Similar Reads

Convert the undirected graph into directed graph such that there is no path of length greater than 1
Given an undirected graph with N vertices and M edges and no self loops or multiple edges. The task is to convert the given undirected graph into a directed graph such that there is no path of length greater than 1. If it is possible to make such a graph then print two space-separated integers u and v in M lines where u, v denotes source and destin
10 min read
Convert undirected connected graph to strongly connected directed graph
Given an undirected graph of N vertices and M edges, the task is to assign directions to the given M Edges such that the graph becomes Strongly Connected Components. If a graph cannot be converted into Strongly Connected Components then print "-1". Examples: Input: N = 5, Edges[][] = { { 0, 1 }, { 0, 2 }, { 1, 2 }, { 1, 4 }, { 2, 3 }, { 3, 4 } } Ou
14 min read
What is Directed Graph? | Directed Graph meaning
A directed graph is defined as a type of graph where the edges have a direction associated with them. Characteristics of Directed Graph Directed graphs have several characteristics that make them different from undirected graphs. Here are some key characteristics of directed graphs: Directed edges: In a directed graph, edges have a direction associ
3 min read
Maximum cost path in an Undirected Graph such that no edge is visited twice in a row
Given an undirected graph having N vertices and M edges and each vertex is associated with a cost and a source vertex S is given. The task is to find the maximum cost path from source vertex S such that no edge is visited consecutively 2 or more times. Examples: Input: N = 5, M = 5, source = 1, cost[] = {2, 2, 8, 6, 9}, Below is the given graph: Ou
12 min read
Print all the cycles in an undirected graph
Given an undirected graph, print all the vertices that form cycles in it. Pre-requisite: Detect Cycle in a directed graph using colors In the above diagram, the cycles have been marked with dark green color. The output for the above will be 1st cycle: 3 5 4 6 2nd cycle: 5 6 10 93rd cycle: 11 12 13 Approach: Using the graph coloring method, mark all
11 min read
Product of lengths of all cycles in an undirected graph
Given an undirected and unweighted graph. The task is to find the product of the lengths of all cycles formed in it.Example 1: The above graph has two cycles of length 4 and 3, the product of cycle lengths is 12. Example 2: The above graph has two cycles of length 4 and 3, the product of cycle lengths is 12. Approach: Using the graph coloring metho
12 min read
Find if an undirected graph contains an independent set of a given size
Given an undirected graph, check if it contains an independent set of size k. Print 'Yes' if there exists an independent set of size k. Print 'No' otherwise. Independent Set: An independent set in a graph is a set of vertices that are not directly connected to each other. Example 1: Input : K = 4, graph = [[1, 1, 0, 0, 0], [1, 1, 1, 1, 1], [0, 1, 1
10 min read
Kth largest node among all directly connected nodes to the given node in an undirected graph
Given two arrays u and v, representing a graph such that there is an undirected edge from u[i] to v[i] (0 ? v[i], u[i] < N) and each node has some value val[i] (0 ? i < N). For each node, if the nodes connected directly to it are sorted in descending order according to their values (in case of equal values, sort it according to their indices
7 min read
Shortest cycle in an undirected unweighted graph
Given an undirected unweighted graph. The task is to find the length of the shortest cycle in the given graph. If no cycle exists print -1. Examples: Input: Output: 4 Cycle 6 -> 1 -> 5 -> 0 -> 6 Input: Output: 3 Cycle 6 -> 1 -> 2 -> 6 Prerequisites: Dijkstra Approach: For every vertex, we check if it is possible to get the shor
8 min read
Find all cliques of size K in an undirected graph
Given an undirected graph with N nodes and E edges and a value K, the task is to print all set of nodes which form a K size clique. A clique is a complete subgraph of a graph.Examples: Input: N = 5, edges[] = { {1, 2}, {2, 3}, {3, 1}, {4, 3}, {4, 5}, {5, 3} }, K = 3 Output: 1 2 3, 3 4 5 Explanation: Clearly from the image, 1->2->3 and 3->4
11 min read
Minimum labelled node to be removed from undirected Graph such that there is no cycle
Given an undirected graph of N nodes labelled from 1 to N, the task is to find the minimum labelled node that should be removed from the graph such that the resulting graph has no cycle. Note: If the initial graph has no cycle, i.e. no node needs to be removed, print -1. Examples: Input: N = 5, edges[][] = {{5, 1}, {5, 2}, {1, 2}, {2, 3}, {2, 4}} O
15+ min read
Count total ways to reach destination from source in an undirected Graph
Given an undirected graph, a source vertex ‘s’ and a destination vertex ‘d’, the task is to count the total paths from the given ‘s’ to ‘d’. Examples Input: s = 1, d = 4 Output: 2 Explanation: Below are the 2 paths from 1 to 4 1 -> 3 -> 4 1 -> 2 -> 3 -> 4 Input: s = 3, d = 9 Output: 6 Explanation: Below are the 6 paths from 3 to 9 3
12 min read
Count of unique lengths of connected components for an undirected graph using STL
Given an undirected graph, the task is to find the size of each connected component and print the number of unique sizes of connected components As depicted above, the count(size of the connected component) associated with the connected components is 2, 3, and 2. Now, the unique count of the components is 2 and 3. Hence, the expected result is Coun
10 min read
Nodes with prime degree in an undirected Graph
Given an undirected graph with N vertices and M edges, the task is to print all the nodes of the given graph whose degree is a Prime Number.Examples: Input: N = 4, arr[][] = { { 1, 2 }, { 1, 3 }, { 1, 4 }, { 2, 3 }, { 2, 4 }, { 3, 4 } } Output: 1 2 3 4 Explanation: Below is the graph for the above information: The degree of the node as per above gr
8 min read
Conversion of an Undirected Graph to a Directed Euler Circuit
Given an undirected graph with V nodes (say numbered from 1 to V) and E edges, the task is to check whether the graph is an Euler Graph or not and if so then convert it into a Directed Euler Circuit. A Directed Euler Circuit is a directed graph such that if you start traversing the graph from any node and travel through each edge exactly once you w
10 min read
Check if longest connected component forms a palindrome in undirected graph
Given an undirected graph with V vertices and E edges, the task is to check that if the largest connected component of the graph forms a palindrome in the undirected graph. Examples: Input: Output: Longest connected component is Palindrome Explanation: Longest connected component is {5, 15, 5} which forms an palindrome by values. Input: Output: Lon
15+ min read
Count the number of Prime Cliques in an undirected graph
Given a graph with N nodes and E edges, the task is to count the number of clique having their size as a prime number or prime number of nodes in the given graph. A clique is a complete subgraph of a given graph. Examples: Input: N = 5, edges[] = { {1, 2}, {2, 3}, {3, 1}, {4, 3}, {4, 5}, {5, 3} } Output: 8 Explanation: In the given undirected graph
13 min read
Largest subarray sum of all connected components in undirected graph
Given an undirected graph with V vertices and E edges, the task is to find the maximum contiguous subarray sum among all the connected components of the graph. Examples: Input: E = 4, V = 7 Output: Maximum subarray sum among all connected components = 5 Explanation: Connected Components and maximum subarray sums are as follows: [3, 2]: Maximum suba
14 min read
Find if there is a path between two vertices in an undirected graph
Given an undirected graph with N vertices and E edges and two vertices (U, V) from the graph, the task is to detect if a path exists between these two vertices. Print "Yes" if a path exists and "No" otherwise. Examples: U = 1, V = 2 Output: No Explanation: There is no edge between the two points and hence its not possible to reach 2 from 1. Input:
15+ min read
Print all shortest paths between given source and destination in an undirected graph
Given an undirected and unweighted graph and two nodes as source and destination, the task is to print all the paths of the shortest length between the given source and destination.Examples: Input: source = 0, destination = 5 Output: 0 -> 1 -> 3 -> 50 -> 2 -> 3 -> 50 -> 1 -> 4 -> 5 Explanation: All the above paths are of
13 min read
Building an undirected graph and finding shortest path using Dictionaries in Python
Prerequisites: BFS for a GraphDictionaries in Python In this article, we will be looking at how to build an undirected graph and then find the shortest path between two nodes/vertex of that graph easily using dictionaries in Python Language. Building a Graph using Dictionaries Approach: The idea is to store the adjacency list into the dictionaries,
3 min read
Maximal Independent Set in an Undirected Graph
Given an undirected graph defined by the number of vertex V and the edges E[ ], the task is to find Maximal Independent Vertex Set in an undirected graph. Independent Set: An independent set in a graph is a set of vertices which are not directly connected to each other. Note: It is a given that there is at least one way to traverse from any vertex
11 min read
Minimize cost to color all the vertices of an Undirected Graph
Given an Undirected Graph consisting of N vertices and M edges, where node values are in the range [1, N], and vertices specified by the array colored[] are colored, the task is to find the minimum color all vertices of the given graph. The cost to color a vertex is given by vCost and the cost to add a new edge between two vertices is given by eCos
11 min read
Minimize cost to color all the vertices of an Undirected Graph using given operation
Given two integers V and E representing the number of vertices and edges of an undirected graph G(V, E), a list of edges EdgeList, and an array A[] representing the cost to color each node, the task is to find the minimum cost to color the graph using the following operation: When a node is colored, all the nodes that can be reached from it are col
8 min read
Queries to check if vertices X and Y are in the same Connected Component of an Undirected Graph
Given an undirected graph consisting of N vertices and M edges and queries Q[][] of the type {X, Y}, the task is to check if the vertices X and Y are in the same connected component of the Graph. Examples: Input: Q[][] = {{1, 5}, {3, 2}, {5, 2}} Graph: 1-3-4 2 | 5 Output: Yes No No Explanation: From the given graph, it can be observed that the vert
11 min read
Minimum number of edges required to be removed from an Undirected Graph to make it acyclic
Given an undirected graph consisting of N nodes containing values from the range [1, N] and M edges in a matrix Edges[][], the task is to determine the minimum number of edges required to be removed such that the resulting graph does not contain any cycle. Examples: Input: N = 3, M = 3, edges[][] = [[1, 2], [2, 3], [3, 1]] Output: 1Explanation:Remo
8 min read
Check for transitive property in a given Undirected Graph
Given an undirected graph G with vertices numbered in the range [1, N] and an array Edges[][] consisting of M edges, the task is to check if all triplets of the undirected graph satisfies the transitive property or not. If found to be true, then print "YES". Otherwise, print "NO". Transitive property of an undirected graph states that:If vertex X i
13 min read
Maximum GCD of all nodes in a connected component of an Undirected Graph
Given an undirected graph consisting of V vertices and a 2d array E[][2] denoting edges between pairs of nodes. Given another array arr[] representing values assigned to each node, the task is to find the maximum GCD among the GCD of all connected components in the graph. Examples: Input: V = 5, E[][2] = {{1, 3}, {2, 3}, {1, 2}}, arr[] = {23, 43, 1
10 min read
Number of shortest paths in an Undirected Weighted Graph
Given a weighted undirected graph G and an integer S, the task is to print the distances of the shortest paths and the count of the number of the shortest paths for each node from a given vertex, S. Examples: Input: S =1, G = Output: Shortest Paths distances are : 0 1 2 4 5 3 2 1 3 Numbers of the shortest Paths are: 1 1 1 2 3 1 1 1 2 Explanation: T
15 min read
Print all Hamiltonian Cycles in an Undirected Graph
Given an undirected Graph consisting of N nodes in the form of an adjacency matrix graph[][] of size N*N, the task is to print all Hamiltonian cycles possible in the given undirected Graph (taking starting vertex as '0'). A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path such that there is an edge (in the graph) from the last verte
15 min read
Practice Tags :
three90RightbarBannerImg