Ch 9. Graphs
Ch 9. Programming Exercises
Exercise 1: Complete Graph Generator
The objective of this exercise is to practice constructing complete graphs.
Write a program (using pseudocode or a programming language of your choice) that takes an integer [latex]n[/latex] as input and generates the edge list of a complete graph with [latex]n[/latex] vertices. Display the total number of edges and all vertex pairs.
Exercise 2: Connectivity Checker
The objective of this exercise is to determine whether a graph is connected.
Create a function (using pseudocode or a programming language of your choice) that accepts an adjacency list or matrix and checks whether the graph is connected. Use depth-first search (DFS) or breadth-first search (BFS) to traverse the graph and report whether all vertices are reachable.
Exercise 3: Directed Graph Analyzer
The objective of this exercise is to analyze incoming and outgoing degree in directed graphs.
Write a program (using pseudocode or a programming language of your choice) that takes a directed graph as input (in adjacency list format) and calculates the incoming and outgoing degree of each vertex. Display the results in a formatted table.
Exercise 4: Euler Path and Circuit Detector
The objective of this exercise is to apply graph theory to path analysis.
Write a program (using pseudocode or a programming language of your choice) that determines whether a given undirected graph contains an Euler path or Euler circuit. Accept the graph as an edge list and apply the necessary conditions based on vertex degrees.
Exercise 5: Topological Sort for Directed Graphs
The objective of this exercise is to implement topological sorting.
Create a program (using pseudocode or a programming language of your choice) that performs a topological sort on a DAG. Accept the graph as an adjacency list and output a valid ordering of vertices. Include cycle detection to ensure the graph is a DAG.