ArticleslgStudy

computer science

Graph (abstract data type)

Graph (abstract data type) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Graph (abstract data type) rather than just read about it. In short: In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from the field of graph theory within mathematics. A graph data structure consists of a finite (and possibly mutable) set of vertices (also called nodes or points), together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed gr…

Graph (abstract data type) — main illustration
Graph (abstract data type) — illustration

Key takeaways

  • Graph (abstract data type) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Graph (abstract data type) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Graph (abstract data type) from memory before moving on to harder problems.

Reference excerpt

In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from the field of graph theory within mathematics. A graph data structure consists of a finite (and possibly mutable) set of vertices (also called nodes or points), together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph. These pairs are known as edges (also called links or lines), and for a directed graph are also known as edges but also sometimes arrows or arcs. The vertices may be part of the graph structure, or may be external entities represented by integer indices or references. A graph data structure may also associate to each edge some edge value, such as a symbolic label or a numeric attribute (cost, capacity, length, etc.).

Operations

The basic operations provided by a graph data structure G usually include:

adjacent(G, x, y): tests whether there is an edge from the vertex x to the vertex y; neighbors(G, x): lists all vertices y such that there is an edge from the vertex x to the vertex y; add_vertex(G, x): adds the vertex x, if it is not there; remove_vertex(G, x): removes the vertex x, if it is there; add_edge(G, x, y, z): adds the edge z from the vertex x to the vertex y, if it is not there; remove_edge(G, x, y): removes the edge from the vertex x to the vertex y, if it is there; get_vertex_value(G, x): returns the value associated with the vertex x; set_vertex_value(G, x, v): sets the value associated with the vertex x to v. Structures that associate values to the edges usually also provide:

get_edge_value(G, x, y): returns the value associated with the edge (x, y); set_edge_value(G, x, y, v): sets the value associated with the edge (x, y) to v.

Common data structures for graph representation Adjacency list Vertices are stored as records or objects, and every vertex stores a list of adjacent vertices. This data structure allows the storage of additional data on the vertices. Additional data can be stored if edges are also stored as objects, in which case each vertex stores its incident edges and each edge stores its incident vertices. Adjacency matrix A two-dimensional matrix, in which the rows represent source vertices and columns represent destination vertices. Data on edges and vertices must be stored externally. Only the cost for one edge can be stored between each pair of vertices. Incidence matrix A two-dimensional matrix, in which the rows represent the vertices and columns represent the edges. The entries indicate the incidence relation between the vertex at a row and edge at a column. The following table gives the time complexity cost of performing various operations on graphs, for each of these representations, with |V| the number of vertices and |E| the number of edges. In the matrix representations, the entries encode the cost of following an edge. The cost of edges that are not present are assumed to be ∞.

Adjacency lists are generally preferred for the representation of sparse graphs, while an adjacency matrix is preferred if the graph is dense; that is, the number of edges | E | {\displaystyle |E|} is close to the number of vertices squared, | V | 2 {\displaystyle |V|^{2}} , or if one must be able to quickly look up if there is an edge connecting two vertices.

More efficient representation of adjacency sets The time complexity of operations in the adjacency list representation can be improved by storing the sets of adjacent vertices in more efficient data structures, such as hash tables or balanced binary search trees (the latter representation requires that vertices are identified by elements of a linearly ordered set, such as integers or character strings). A representation of adjacent vertices via hash tables leads to an amortized average time complexity of O ( 1 ) {\displaystyle O(1)} to test adjacency of two given vertices and to remove an edge and an amortized average time complexity of O ( deg ⁡ ( x ) ) {\displaystyle O(\deg(x))} to remove a given vertex x of degree deg ⁡ ( x ) {\displaystyle \deg(x)} . The time complexity of the other operations and the asymptotic space requirement do not change.

Parallel representations The parallelization of graph problems faces significant challenges: Data-driven computations, unstructured problems, poor locality and high data access to computation ratio. The graph representation used for parallel architectures plays a significant role in facing those challenges. Poorly chosen representations may unnecessarily drive up the communication cost of the algorithm, which will decrease its scalability. In the following, shared and distributed memory architectures are considered.

Shared memory In the case of a shared memory model, the graph representations used for parallel processing are the same as in the sequential case, since parallel read-only access to the graph representation (e.g. an adjacency list) is efficient in shared memory.

… excerpt ends here. Continue reading the full article.

Illustrations

Graph (abstract data type): A directed graph with three vertices (blue circles) and three edges (black arrows).
A directed graph with three vertices (blue circles) and three edges (black arrows).
Graph (abstract data type): UML class diagram of a Graph (abstract data type)
UML class diagram of a Graph (abstract data type)

Worked examples

Example 1 — a first encounter with Graph (abstract data type)

Start with the simplest possible case. Write down what Graph (abstract data type) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Graph (abstract data type) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Graph (abstract data type) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Graph (abstract data type)

In research
Graph (abstract data type) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Graph (abstract data type) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Graph (abstract data type) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Abstract data types, Graph data structures, Graph theory, so understanding it makes those chapters shorter.
In everyday life
Look for Graph (abstract data type) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Graph (abstract data type)” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Graph (abstract data type) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Graph (abstract data type) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Graph (abstract data type) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Graph (abstract data type) in simple terms?

In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from the field of graph theory within mathematics. A graph data structure consists of a finite (and possibly mutable) set of vertices (also called nodes or points), toge…

Why does Graph (abstract data type) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Graph (abstract data type)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Graph (abstract data type).

Tags

  • Abstract data types
  • Graph data structures
  • Graph theory
  • Graphs
  • Hypergraphs

Keep exploring