Team 8

Graph Theory App

Build an app that lets users create simple graphs by entering edges, generates the adjacency matrix, computes vertex degrees, and checks basic graph properties like connectivity and regularity.

๐ŸŽฏ Learning Goals

  • โ–น Understand Vertices, Edges, and Degrees
  • โ–น Build and interpret an Adjacency Matrix
  • โ–น Apply Handshaking Theorem in practical code
  • โ–น Implement adjacency lists using nested application lists

๐ŸŒŽ Why This Matters

Graph theory is how Google Maps finds the shortest route, how LinkedIn suggests 'connections', and how the internet itself is built. When you study graphs, you are studying the science of connectivity.

๐Ÿ“–Understanding Graph Theory Basics

Theory Masterclass
"

A graph is a collection of points (called vertices or nodes) connected by lines (called edges). Think of it like a social network: people are vertices, and friendships are edges. Key Terms: โ€ข Vertex (Node): A point in the graph. Example: cities on a map. โ€ข Edge: A connection between two vertices. Example: roads between cities. โ€ข Degree: The number of edges connected to a vertex. If vertex A connects to B, C, D โ€” degree(A) = 3. Adjacency Matrix: A grid where entry [i][j] = 1 if vertex i connects to vertex j, else 0. For undirected graphs, the matrix is symmetric (same above and below diagonal). Example: 3 vertices, edges: 1-2, 2-3 Adjacency Matrix: 1 2 3 1 [0 1 0] 2 [1 0 1] 3 [0 1 0] Sum of all degrees = 2 ร— number of edges (Handshaking Theorem) Regular Graph: All vertices have the same degree. Complete Graph: Every vertex connects to every other vertex.

Mathematical Foundation

fxDegree(v) = sum of row v in adjacency matrix
fxSum of all degrees = 2 ร— |E| (Handshaking Theorem)
fxComplete graph Kn has n(n-1)/2 edges
fxRegular: all degrees are equal

๐ŸŽจPart A โ€” Designer View (UI Design)

Open MIT App Inventor โ†’ Switch to Designer view. Follow each step below to build the interface.

1

Set up the screen

Title: "Graph Theory Explorer". Dark theme.

2

Create vertex count input

Label: "Number of vertices" TextBox named VertexCount (NumbersOnly, Hint: "4") Button: "Initialize Graph"

3

Create edge input area

Label: "Add edges (enter vertex pairs)" HorizontalArrangement: TextBox V1, Label "โ€”", TextBox V2 Button: "Add Edge" ListView named EdgeList to show all added edges.

4

Add action buttons

Row 1: "Show Adjacency Matrix", "Show Degrees" Row 2: "Check Regular", "Check Complete" Row 3: "Total Edges", "Reset Graph"

5

Create matrix display

A large Label named MatrixLabel with monospace font to display the adjacency matrix in grid format. Another Label for degree information.

๐ŸงฉPart B โ€” Blocks View (Logic & Calculation)

Switch to Blocks view. Now add the logic that makes your app actually work.

1

Initialize the graph data structure

When InitializeButton.Click: 1. Read n = number(VertexCount.Text) 2. Create a list of nร—n zeros (use nested loops to fill a list) 3. Store as global variable "adjMatrix" 4. Create a list "edges" to track all edges 5. Clear the ListView

2

Add Edge logic

When AddEdgeButton.Click: 1. Read v1 and v2 from TextBoxes 2. Validate: both must be between 1 and n 3. Set adjMatrix at position [(v1-1)*n + v2] = 1 4. Set adjMatrix at position [(v2-1)*n + v1] = 1 (undirected) 5. Add "v1 โ€” v2" to the edges ListView

3

Display Adjacency Matrix

When ShowMatrixButton.Click: 1. Build a string row by row 2. For each row i (1 to n): For each column j (1 to n): Append adjMatrix[(i-1)*n + j] + " " Append newline 3. Display the formatted string in MatrixLabel

4

Calculate vertex degrees

When ShowDegreesButton.Click: For each vertex i (1 to n): degree = 0 Sum all values in row i of adjacency matrix Display: "Vertex i: degree = " + degree Also show total: "Sum of degrees = " + totalDegrees And: "Number of edges = " + totalDegrees/2

5

Check if graph is Regular

When CheckRegularButton.Click: 1. Calculate degree of each vertex 2. If all degrees are equal โ†’ "Graph is Regular (degree k)" 3. Else โ†’ "Graph is NOT regular"

6

Check if graph is Complete

When CheckCompleteButton.Click: 1. Calculate degree of each vertex 2. If every degree = n-1 โ†’ "Graph is Complete (Kn)" 3. Else โ†’ "Graph is NOT complete" Also verify: edges = n(n-1)/2

7

Reset logic

When ResetButton.Click: Clear all lists, TextBoxes, and Labels. Reset the graph to empty state.

๐ŸงชTesting Your App

  • โœ“3 vertices, edges 1-2, 2-3, 1-3 โ†’ Complete graph K3, all degrees = 2
  • โœ“4 vertices, edges 1-2, 3-4 โ†’ Not regular, not complete
  • โœ“Verify handshaking: sum of degrees should always be 2 ร— edges
  • โœ“Try adding a self-loop (1-1) and see what happens
  • โœ“Test adjacency matrix symmetry: entry [i][j] should equal [j][i]

๐Ÿš€Bonus Challenges

Extra credit โ€” impress your instructor

  • โ˜…Draw the graph visually on a Canvas with circles and lines
  • โ˜…Add directed graph support (asymmetric adjacency matrix)
  • โ˜…Implement simple BFS to check if graph is connected
  • โ˜…Add 'Find Path' between two vertices