Graph Concepts & Terminologies
Introduction to Graphs DSA practice problem on Onlearn.
Difficulty: easy.
Topics: What is a graph data structure and how is it used in programming and real-world applications?, Graph, Data Structures, Node, Edge, Directed Graph, Undirected Graph, Hash Map, Time Complexity, Space Complexity, Algorithm, Loops, graph traversal, data structures, graph properties, Data Structures, Graph Terminology, Graph Types, Cycle Detection in Undirected Graphs.
Graph Properties Query A graph is a non linear data structure consisting of nodes (vertices) and connections between them (edges). Each edge is directed, from a source vertex u to a destination vertex v. The indegree of a vertex is the number of incoming edges. The outdegree of a vertex is the number of outgoing edges. You are given a list of directed edges. Your task is to count the total number of unique vertices and edges. For each unique vertex, calculate and report its indegree and outdegree. Input Specification The first line contains an integer M, representing the number of directed edges. The next M lines each contain two integers u and v, representing a directed edge from vertex u to vertex v. Vertex IDs can be any non negative integer. Output Specification First, print "Number of Vertices: [count]". Then, print "Number of Edges: [count]". For each unique vertex, print its properties on a new line: "Vertex [ID]: Indegree = [indegree], Outdegree = [outdegree]". Vertices should be listed in ascending order of their IDs. Constraints 1 <= M <= 1000 0 <= u, v <= 10000 (Vertex IDs) Sample Test Case Input Output