Share Your Experience: Take the 2024 Developer Survey

# Questions tagged [graph-theory]

For challenges regarding graphs, mathematical structures used to model relations between objects.

202 questions
Filter by
Sorted by
Tagged with
214 views

### Pareto-optimal shortest paths

Given a directed graph on the nodes 0, 1, ..n, where each edge has two non-negative integer costs, return the set of all possible Pareto Optimal path costs between ...
• 3,829
2k views

### Calculating Transitive Closure

First attempt at a question. Calculating Transitive Closure According to Wikipedia, "the transitive closure $R^*$ of a homogeneous binary relation $R$ on a set $X$ is the smallest ...
• 481
836 views

### Compute the chromatic number of special graphs

This challenge is about computing the chromatic number of special types of graphs. Input The input will consist of two integers. A positive integer $n > 1$. A distance $d < n$. Task The ...
• 2,926
3k views

### Is it a valid chemical?

Non-metals typically* have a fixed number of covalent bonds in every chemical they are part of. Given the number of bonds every element requires, output whether it's possible to construct a single ...
• 12.6k
226 views

### Triangularly embed a graph on a surface

This challenge arises from a claim made in a MathOverflow answer and a paper linked in that answer which seems to back up the claim: Searching for triangular embeddings is much quicker than ...
• 3,737
353 views

### Minimum Cut finder

Write a program that takes an undirected graph and finds the minimum cut, i.e., the set of edges that, if removed, would disconnect the graph into two or more connected components. The program should ...
1k views

### Simplify a Cycle

Alternatively: That one challenge I forgot I had in the sandbox and is about stuff from Discrete Mathematics I learned like 5-6 months ago and kinda don't remember Given a path of vertices that form a ...
• 33.5k
951 views

### Detect round trips on a dodecahedron

An ant starts on an edge of a dodecahedron, facing parallel to it. At each step, it walks forward to the next vertex and turns either left or right to continue onto one of the other two edges that ...
• 621
1k views

### The smallest number of steps for a chess piece to reach a position

I have previously posted a challenge, smallest number of steps for a knight in chess. Now I would like to go a step further by adding the possibility to choose your piece. If you place a piece on any ...
• 435
3k views

### Is this graph a tree?

Given an undirected graph, find out if it is a tree. A tree is an undirected graph in which there is exactly one path between any two vertices. In other word, the graph is both acyclic and connected. ...
• 48.2k
3k views

### smallest number of steps for a knight in chess

If you place a knight on any square of a chessboard, what is the smallest amount of steps to reach every position? Rules It is an 8 by 8 board. The knight starts at an arbitrary position, taken as ...
• 435
564 views

### Train Route Planning

We can model a rail network as a directed graph, where each node is a train station and each edge is a train connecting two train stations. We'll assume that each train travels between its ...
• 3,829
205 views

### Is this a strange pond?

In this challenge we considered a frog hopping around a lily pond. To recap the lily pond was represented as a finite list of positive integers. The frog can only jump forward or backwards by a ...
• 98.8k
5k views

### Can the 🐸 visit all the 🪷?

In this challenge you will be simulating a frog jumping from lily-pad to lily-pad in a pond. A frog's jump distance is uniquely determined by the size of the lily pad it jumps from. So for example ...
• 98.8k
710 views

### Increasing permutation trees

For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left ...
• 98.8k
979 views

### Convert between graph representations

What? Let's say I have this graph: 1 \ \ 2 3 \ / \ / 4 I can represent it in 2 ways: A list of connected vertices. ...
• 1,655
726 views

### Can you draw this in one stroke?

Related | Related Given an ASCII art with |, _, and , check if you can draw the art in one ...
• 9,328
889 views

### Chromatic polynomial of a graph

Given a undirected graph $G$ and a integer $k$, how many $k$-coloring does the graph have? Here by a $k$-coloring, we mean assigning one of the $k$ colors to each vertex of the graph, such ...
• 48.2k
1k views

### Generate a regular graph

Inspired by this Mathematica.SE post Given two positive integers $n, k$ with $n > k \ge 1$, output a binary $n\times n$ matrix such that every row and column contains exactly $k$ 1s, and ...
• 49.9k
253 views

### Your trees need to be rerooted

In graph theory a tree is just any graph with no cycles. But in computer science we often use rooted trees. Rooted trees are like trees except they have one specific node as the "root", ...
• 98.8k
5k views

### Who Is Kevin Bacon?

You may know the game The Six Degrees of Kevin Bacon, based on the conjecture that every actor in Hollywood can be connected to Kevin Bacon by no more than 6 "co-star" relations, so Kevin ...
• 23.7k
401 views

### AoCG2021 Day 19: To Hire or To Fire

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2018 Day 7, Part 2. Why I'm pxeger, not Bubbler As soon as you and a few Elves successfully ...
• 23.7k
1k views

### AoCG2021 Day 13: Defrag in action!

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2017 Day 14. To recap: The disk is a rectangular grid with $r$ rows and $c$ columns. Each ...
• 76.7k
574 views

### Is this an interval graph?

Background An interval graph (Wikipedia, MathWorld, GraphClasses) is an undirected graph derived from a set of intervals on a line. Each vertex represents an interval, and an edge is present between ...
• 76.7k
201 views

### Hamiltonian levencycle of 1-dup permutations

The word "levencycle" is inspired by cyclic levenquine challenge. Definitions A 1-dup permutation of order $n$ is some permutation of $1, \cdots, n$ plus one duplicate number in the ...
• 76.7k
313 views

### Classify a graph

Challenge Given a graph (a structure consisting of nodes and vertices), classify it according to a few categories. Specifically, you will be given an unweighted directed graph, which is a set of nodes ...
• 42.4k
230 views

### NP-complete reduction: (grid-)Hamiltonian circuit

Background Hamiltonian circuit problem is a decision problem which asks whether a given graph has a Hamiltonian circuit, i.e. a cycle that visits every vertex exactly once. This problem is one of the ...
• 76.7k
434 views

### Taking the long route

Challenge Your goal is to find the furthest point on a graph (from a provided start node). Your code doesn't need to handle cycles in the graph properly, but it might pose a fun challenge. For this ...
• 341
388 views

### Radio station hopping

Introduction You are listening to a car radio. You are pressing seek up/down, moving you to the next frequency some radio station broadcasts on, to avoid all this pointless music and listen to all the ...
• 255
295 views

### Find the Best Set of Adapters

I'm trying to plug this really old phone into my computer but the phone seems to use a very obscure plug. Luckily I have some adapters. Unfortunately, I can't figure out which of them to use to ...
• 1,161
435 views

### Is this Game of Go configuration fully alive?

Background This challenge is about the Game of Go. Here are some rules and terminology relevant to this challenge: Game of Go is a two-player game, played over a square board of size 19x19. One of ...
• 76.7k
1k views

### Count all binary relations

A binary relation on a set $X$ is simply a subset $S \subseteq X \times X$; in other words, a relation is a collection of pairs $(x,y)$ such that both $x$ and $y$ are in $X$. The number of ...
• 8,689
443 views

### A graph and its seven closures

Background A little while ago, someone posted an interesting puzzle on Math.SE: What is the smallest digraph (directed graph) G where the following eight graphs are all distinct: G, the original ...
• 76.7k
2k views

### Are these states connected?

With the US election going on right now, I noticed that there is one (completely meaningless, but still) thing which Trump can still achieve and which is out of reach for Biden: Having the won states ...
• 451
693 views

### Count Euler's Tours

Leonhard Euler wants to visit a few friends who live in houses 2, 3, ..., N (he lives in house 1). However, because of how his city is laid out, none of the paths between any houses form a loop (so, ...
• 42.4k
1k views

### Solve the Trolley Problem with Multitrack Drifting [closed]

Introduction Programmers have already solved the trolley problem (a classical problem in philosophy). In the usual trolley problem, we have a directed graph and each edge is weighted by the number of ...
• 29
615 views

### Find the maximum flow

Given a directed network, with a single source and a single sink, it is possible to find the maximum flow through this network, from source to sink. For example, take the below network, $G$: Here, ...
• 49.9k
836 views

### Counting King's Hamiltonian Paths through 3-by-N grid

Background A Hamiltonian path is a path on a graph that steps through its vertices exactly once. On a grid, this means stepping through every cell exactly once. On a square grid, a Chess King can move ...
• 76.7k
812 views

### Scoring Quantum Tic-Tac-Toe

In the description of this challenge, the following board will be used as a reference for positions: ABC DEF GHI For instance, in a game of ordinary tic-tac-toe, <...
• 2,059
2k views

### Get to the Zone!

You are playing a famous game called $1\text{D Array BattleGround}$. In the game, the player can be stationed in any position from $0$ to $10^5$. You are a Paratrooper in the game and have the ...
2k views

• 615