Soorten grafieken in gegevensstructuur met voorbeelden

โšก Slimme samenvatting

Graphs in data structure are non-linear collections of vertices and edges classified into families such as directed, undirected, weighted, cyclic, acyclic, complete, connected, bipartite, Euler, and Hamilton graphs based on structure.

  • ๐Ÿ“ Definitie: A graph G = (V, E) is a non-linear structure where V is the vertex set and E is the edge set connecting pairs of vertices.
  • โžก๏ธ Richting: Directed graphs use arrowed edges with a fixed source and target, while undirected graphs allow bidirectional travel across each edge.
  • โ€‹ Gewicht: Weighted graphs attach a numeric cost to every edge, whereas unweighted graphs treat all edges as equal-cost connections.
  • ๐Ÿ” Cycles: Cyclic graphs contain one or more cycles; a Directed Acyclic Graph (DAG) forbids cycles and enables scheduling and topological sorting.
  • ๐Ÿ”— Volledigheid: Complete graphs connect every pair of vertices, connected graphs allow a path between any two vertices, and null graphs have zero edges.
  • ๐Ÿงฉ Speciale typen: Bipartite, Euler, Hamilton, Multi, Cycle, and Trivial graphs each impose a specific rule on how vertices and edges are arranged.

Soorten grafieken in de gegevensstructuur

A graph is a non-linear data structure that consists of vertices and edges. The vertices contain the information or data, and the edges work as a link between a pair of vertices.

Graphs can be of multiple types, depending on the position of the nodes and edges. Here are some important types of Graphs:

Gerichte grafiek

The edges of the Directed Graph contain arrows that mean the direction. The arrow determines where the edge is pointed to or ends. Here is an example of the Directed Graph.

Gerichte grafiek

Gerichte grafiek

  • We kunnen van knooppunt A naar D gaan.
  • However, we cannot go from node D to node A, as the edge points from A to D.
  • Omdat de grafiek geen gewichten heeft, kost het reizen van hoekpunt A naar D hetzelfde als reizen van D naar F.

Ongerichte grafiek

An Undirected Graph contains edges without pointers. It means we can travel vice versa between two vertices. Here is a simple example of the undirected Graph.

Ongerichte grafiek

Ongerichte grafiek

In de bovenstaande grafiek,

  • We can move from A to B.
  • We can also move from B to A.
  • Randen bevatten geen richtingen.

It is an example of an undirected graph having a finite number of vertices and edges with no weights.

Gewogen grafiek

A Graph that contains weights or costs on the edges is called a weighted Graph. The numerical value generally represents the moving cost from one vertex to another vertex. Both Directed and Undirected Graphs can have weights on their edges. Here is an example of a weighted graph (Directed).

Gerichte grafiek met gewicht

Gerichte grafiek met gewicht

  • A to B, there is an edge, and the weight is 5, which means moving from A to B will cost us 5.
  • A points to B, but in this Graph, B has no direct edge over A. So, we cannot travel from B to A.
  • However, if we want to move from A to F, there are multiple paths. The paths are ADF and ABF. ADF will cost (10+11) or 21.
  • Here, the path ABF will cost (5+15) or 20. Here we are adding the weight of each edge in the path.

Here is an example of an Undirected Graph with weights:

Ongerichte grafiek met gewicht

Ongerichte grafiek met gewicht

Hier heeft de rand gewicht maar geen richting. Het betekent dus dat reizen van hoekpunt A naar D 10 euro kost en omgekeerd.

Bidirectionele grafiek

Bi-directional and undirected graphs have a common property. That is:

  • Generally, the undirected Graph can have one edge between two vertices.

Bijvoorbeeld:

Bidirectionele grafiek

  • Hier kost het verplaatsen van A naar D of D naar A 10.
  • In een bidirectionele grafiek kunnen we twee randen tussen twee hoekpunten hebben.

Hier is een voorbeeld:

Bidirectionele grafiek

Bidirectionele grafiek

Traveling from A to D will cost us 17, but traveling from D to A will cost us 12. So, we cannot assign two different weights if it is an undirected graph.

Oneindige grafiek

The Graph will contain an infinite number of edges and nodes. If a graph is Infinite and it is also a connected graph, then it will contain an infinite number of edges as well. Here, the extended edges mean that more edges might be connected to these nodes via edges. Here is an example of the infinite Graph:

Oneindige grafiek

Oneindige grafiek

Nulgrafiek

A Null Graph contains only nodes or vertices but with no edges. If given a Graph G = (V, E), where V is vertices and E is edges, it will be null if the number of edges E is zero. Here is an example of a Null Graph:

Nulgrafiek

Nulgrafiek

Triviale grafiek

A graph data structure is considered trivial if only one vertex or node is present with no edges. Here is an example of a Trivial Graph:

Triviale grafiek

Multigrafiek

A graph is called a multigraph when multiple edges are present between two vertices, or the vertex has a loop. The term โ€œLoopโ€ in Graph Data Structure means an edge pointing to the same node or vertex. A multigraph can be directed or undirected. Here is an example of a Multi Graph:

Multigrafiek

There are two edges from B to A. Moreover, vertex E has a self-loop. The above Graph is a directed graph with no weights on edges.

Volledige grafiek

A graph is complete if each vertex has directed or undirected edges with all other vertices. Suppose there is a total of V number of vertices and each vertex has exactly V-1 edges. Then, this Graph will be called a Complete Graph. In this type of Graph, each vertex is connected to all other vertices via edges. Here is an example of a Complete Graph with five vertices:

Volledige grafiek

You can see in the image that the total number of nodes is five, and all the nodes have exactly four edges.

Verbonden grafiek

A Graph is called a Connected graph if we start from a node or vertex and can travel to all the nodes from the starting node. For this, there should be at least one edge between each pair of nodes or vertices. Here is an example of a Connected Graph:

Verbonden grafiek

Here is some explanation of the above Connected Graph:

  • Assuming there is no edge between C and F, we cannot travel from A to G. However, the edge C to F enables us to travel to any node from a given node.
  • Een volledige grafiek is een verbonden grafiek omdat we van een knooppunt naar elk ander knooppunt in de gegeven grafiek kunnen gaan.

Cyclische grafiek

A graph is said to be cyclic if there are one or more cycles present in the Graph. Here is an example of a Cyclic Graph:

Cyclische grafiek

Here, vertices A, B, and C form a cycle. A graph can have multiple cycles inside it.

Gerichte Acyclische Grafiek (DAG)

A Graph is called a Directed Acyclic Graph or DAG if there are no cycles inside a graph. DAG is important while doing the Topologische sortering or finding the execution order. DAG is also important for creating scheduling systems or scanning dependency of resources, etc. However, the Graph above does not contain any cycle inside. Here is a simple example of a Directed Acyclic Graph (DAG):

Gerichte Acyclische Grafiek (DAG)

Cyclusgrafiek

A Cycle Graph is not the same as the cyclic Graph. In a Cycle Graph, each node will have exactly two edges connected, meaning each node will have exactly two degrees. Here is an example of a Cycle Graph:

Cyclusgrafiek

Bipartiete grafiek

Dit soort Grafieken are special kinds of Graph where vertices are assigned to two sets. A Bipartite Graph must follow the rule:

  • The two sets of vertices should be distinct, which means all the vertices must be divided into two groups or sets.
  • Same-set vertices should not form any edges.

Bipartiete grafiek

Euler-grafiek

A Graph data structure is considered an Euler Graph if all the vertices have an even-numbered degree. The term degree of vertices means the number of edges pointing to or pointing out from a particular vertex. Here is an example of a Euler graph:

Euler-grafiek

All the vertices have even degrees. Vertices A, D, E, and H have two degrees. Here, node C has four degrees, which is even.

Hamilton-grafiek

A Hamilton Graph is a Connected Graph, where you can visit all the vertices from a given vertex without revisiting the same node or using the same edge. This kind of Connected Graph is known as the โ€œHamilton Graphโ€. The path you visit to verify if the given Graph is a Hamilton Graph or not is known as the Hamiltonian Path. Here is a simple graph example of a Hamilton:

Hamilton-grafiek

In deze afbeelding kunnen we alle hoekpunten van elk knooppunt in de bovenstaande grafiek bezoeken. Een van de paden kan zijn ADCHBE. It is also possible to find a Hamilton Cycle. A Hamilton Cycle starts and ends at the same vertex. So, the Hamilton Cycle will be A-D-C-H-B-E-A.

Veelgestelde vragen

A graph is a non-linear data structure made of vertices (nodes) and edges (links). Vertices store data and edges connect pairs of vertices, forming networks used to model roads, social ties, dependencies, and more.

Directed graphs use edges with arrows pointing from a source to a target, restricting travel to that direction. Undirected graphs use edges without arrows, allowing travel between the connected vertices in either direction.

A Directed Acyclic Graph, or DAG, is a directed graph that contains no cycles. DAGs are widely used for task scheduling, build systems, package dependency resolution, and any workflow that requires a valid topological order.

A weighted graph attaches a numeric weight to every edge, representing distance, time, or cost. Shortest-path algorithms such as Dijkstra and network routing protocols use weighted graphs to find the most efficient path.

A complete graph has an edge between every pair of vertices. A connected graph only needs a path between every pair. Every complete graph is connected, but not every connected graph is complete.

Bipartite graphs split vertices into two disjoint sets with edges only between the two sets. They model matching problems such as assigning workers to jobs, students to courses, or ride-hailing drivers to riders.

Graph Neural Networks apply machine learning to graph-structured data for tasks like fraud detection, drug discovery, and recommendation. Knowledge graphs power AI question-answering, and computation graphs describe every forward and backward pass in deep learning.

Yes. AI Copilot tools such as GitHub Copilot and ChatGPT generate boilerplate for BFS, DFS, Dijkstra, and topological sort in most languages. Developers still need to verify edge cases, cycle handling, and complexity for production code.

Vat dit bericht samen met: