Graph Theory Basics Quiz

SpellboundTrumpet avatar
SpellboundTrumpet
·
·
Download

Start Quiz

Study Flashcards

21 Questions

What is the key difference between traversing undirected edges and directed edges in a graph?

Undirected edges can be traversed in both directions, while directed edges can only be traversed in the indicated direction.

In a graph, what is the subgraph 𝑆𝑆 referred to as?

A subset of the nodes and edges of graph 𝐺𝐺

What defines a spanning subgraph of a graph?

Formed from all nodes of the graph and some of its edges

Which type of graph allows edges to be traversed in both directions?

Undirected graph

What is an adjacency matrix used for in graphs?

To represent connections between nodes in a graph

For an undirected graph represented by an adjacency matrix, how many cells are modified when adding or removing an edge?

Two cells

In an adjacency matrix of an undirected graph, which cell(s) are affected when adding an edge between nodes?

The cells in both row and column corresponding to the nodes

What happens to the adjacency matrix of an undirected graph when an edge between two nodes is removed?

The corresponding cells are set to 0

How is a directed graph adjacency matrix different from an undirected graph adjacency matrix?

Directed graph adjacency matrix is not symmetric

What does the sum value of a row in an adjacency matrix of an undirected graph indicate?

Number of edges going out of that node

If a node has edges going to all other nodes in an undirected graph, what does its row sum indicate?

Zero edges leaving that node

What is the purpose of the Graph ADT operation 'adjacent'?

To check if two nodes are connected by an edge

In the context of undirected graphs, what does the adjacency matrix represent?

The edges between each pair of nodes in the graph

What is the time complexity of adding a new node using a matrix-based implementation of Graph ADT?

$O(1)$

Which operation in the Graph ADT is used to find and return the neighbors of a given node?

getNeighbors

What does the 'addEdge' function in Graph ADT do?

Creates an edge between two nodes

In a graph with $N$ nodes and $E$ edges, what is the memory complexity of a matrix-based implementation of Graph ADT?

$O(N + E)$

What does the 'removeEdge' function in Graph ADT do?

Removes an edge between two nodes

'adjacent' operation in Graph ADT is used to ___________?

Check if two nodes are connected by an edge

'getNeighbors' function in Graph ADT is responsible for ___________?

Retrieving the neighboring nodes of a given node

'addNode' operation in Graph ADT focuses on ___________?

Adding a new node to the graph

Study Notes

Graph ADT: Adjacency Matrices

  • A graph of 𝑛𝑛 nodes can be represented as a two-dimensional array called adjacency matrix.
  • Let 𝐺𝐺 be the undirected graph corresponding to an adjacency matrix 𝐴𝐴.
  • An edge in 𝐺𝐺 between nodes 𝑖𝑖 and 𝑗𝑗 exists if 𝐴𝐴 𝑖𝑖 𝑗𝑗 = 1 for row 𝑖𝑖 and column 𝑗𝑗.
  • No edge in 𝐺𝐺 between nodes 𝑖𝑖 and 𝑗𝑗 exists if 𝐴𝐴 𝑖𝑖 𝑗𝑗 = 0 for row 𝑖𝑖 and column 𝑗𝑗.
  • Adjacency matrix is symmetric for undirected graphs, meaning 𝐴𝐴 𝑖𝑖 𝑗𝑗 = 𝐴𝐴 𝑗𝑗 𝑖𝑖 for 𝑖𝑖 ∈ {1, … , 𝑛𝑛} and 𝑗𝑗 ∈ {1, … , 𝑛𝑛}.
  • For an undirected graph, two cells are always modified when we add or remove an edge.

Graph ADT

  • The Graph ADT supports adding and removing both nodes and edges, checking if two nodes are adjacent, and getting the neighbors of one node.
  • The Graph ADT methods include:
    • void addNode(Node 𝒏𝒏)
    • void removeNode(Node n)
    • void addEdge(Node n, Node m)
    • void removeEdge(Node n, Node m)
    • boolean adjacent(Node n, Node m)
    • Node[] getNeighbours(Node n)
  • Semantics: Nodes are identified by values (names) so add_edge and rem_edge can find the nodes being referred to.

Graph ADT: List-based Implementation

  • The GraphNode class represents a node in the graph, with a label (id) and a set of edges.
  • The GraphList class represents the graph, with a head node and methods to add and remove nodes and edges.

Graph ADT: Adding and Finding Nodes

  • The addNode method adds a new node to the graph, with a given label.
  • The findNode method finds a node in the graph by its label.

Graph ADT: Adding and Removing Edges

  • The addEdge method adds a new edge between two nodes, by adding the nodes to each other's edges.
  • The removeEdge method removes an edge between two nodes, by removing the nodes from each other's edges.

Graph ADT: Removing a Node

  • The removeNode method removes a node from the graph, by removing all edges to and from the node and then removing the node from the list.

Graph ADT: Get Neighbors and Adjacency

  • The getNeighbors method returns an array of nodes that are neighbors of a given node.
  • The adjacent method checks if two nodes are adjacent.

Graph ADT: Displaying the Graph

  • The print method prints the graph, showing each node and its neighbors.

Graph ADT: Implementation Cost

  • The memory complexity of the list-based implementation is 𝑂𝑂(𝑁𝑁 + 𝐸𝐸) for graphs with 𝑁𝑁 nodes and 𝐸𝐸 edges.
  • The time complexity of the list-based implementation includes:
    • Adding a node: 𝑂𝑂(1)
    • Removing a node: 𝑂𝑂(𝑁𝑁)
    • Finding/accessing a node: 𝑂𝑂(𝑁𝑁)
    • Adding and removing an edge: 𝑂𝑂(𝑁𝑁)
    • Adjacency check: 𝑂𝑂(𝑁𝑁)

Graphs

  • A graph can be directed or undirected.
  • Undirected edges can be traversed in both directions, while directed edges can only be traversed in the indicated direction.
  • A subgraph 𝑆𝑆 of a graph 𝐺𝐺 is a subset of the nodes and edges of 𝐺𝐺.
  • A subgraph 𝑆𝑆 is a spanning subgraph of 𝐺𝐺 if it is formed from all nodes of 𝐺𝐺 and some of the edges of 𝐺𝐺.

Test your knowledge on the basics of graph theory including nodes, edges, directed and undirected graphs, subgraphs, and graph traversal.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser