Skip to Content

Discrete Math: Graphs and Trees Basics

Given a binary tree, calculate its pre-order traversal.

Find the in-order traversal of a given binary tree.

Determine the post-order traversal of a given binary tree.

Is it possible for 5 people to each be friends with exactly 2 other people?

Is it possible for 5 people to each be friends with exactly 3 other people?

Create an adjacency matrix for the given graph G. Identify rows and columns using vertex labels A, B, C, and D. Populate the matrix following these rules: the entry in the i-th row and j-th column is 1 if the vertices represented are adjacent in graph G, otherwise it is 0.

Draw a directed graph that has the following adjacency matrix: [0102201000111111]\begin{bmatrix} 0 & 1 & 0 & 2 \\ 2 & 0 & 1 & 0 \\ 0 & 0 & 1 & 1 \\ 1 & 1 & 1 & 1 \end{bmatrix}

Determine if each graph has an Euler Circuit, and if it does, find the Euler Circuit.

We're given a graph of nn nodes and an array of edges belonging to this graph. Every edge is undirected and connects two nodes aa and bb. We need to return the number of connected components in the graph.

Explain how to represent a graph using an adjacency list, adjacency matrix, and incidence matrix in JavaScript.

Represent a graph using an adjacency matrix given a graph with 5 vertices.

Represent a graph using an adjacency list for a given graph with 5 vertices.

A fairly standard problem that you're likely to encounter all the time revolves around connectivity.

Given a set of colors, can we assign a color to each vertex such that no two neighbors are assigned the same color (vertex coloring problem)?

Explain the difference and use cases for undirected and directed graphs with examples such as social networks and street maps.

Describe how adjacency matrices and adjacency lists are used to represent graphs and compare their time and space complexities.