I've been taking discrete math classes for a few months now and I was recently tasked to with a challenging exercise. I have to write a program that finds every induced subgraph that is a tree. The induced graph must have $m$ number of vertices ($m < n$, where $n$ is the number of vertices in the given graph).
So I've been digging around the internet for the last two days and the best things that I've found are an algorithm to check whether the graph is a tree: https://www.geeksforgeeks.org/check-given-graph-tree/ and these mathematical proofs: https://reader.elsevier.com/reader/sd/pii/S0166218X09000663?token=63213A4B2D548D315FF37E74896FD371A61C08FBDEC7C79C89D1C3E919C631ABBF6C048E5DB1600A3622E12758D51E49. It's quite frustrating as we were only given basic theory about trees and no programming knowledge at all so any help would really be appreciated!
I am assuming the graph is the data structure consisting of two "lists," a vertex list $V$ and an edge list $E$. Furthermore, I am assuming you know what while-loops and for-loops are. Good luck with your class!
First, you must know the following algorithm that checks for a cycle in a connected graph:
second I assume that you are familiar with Kruskal's algorithm which finds a spanning forest
and third I also assume that you know how to perform the following
here I am assuming familiarity with depthfirst search.
We are finally ready to write the final algorithm
here I am assuming you know how to produce all of the $\binom{V}{m}$, the simplest problem in algorithmic combinatorics/discrete math.