Today I Learned (May 10, 2024)

How to show a dependency graph for installed Brew packages

Brew will helpfully refuse to uninstall packages that are required by other installed packages, so you could also go the trial and error path. But, if you want to find out which packages are not required by others—and may, therefore, be uninstalled—, run

brew deps --installed --dot --graph | grep -- '-> "<the-package-name>"'

E.g.

$ brew deps --installed --dot --graph | grep -- '-> "libidn2"'
"gnutls" -> "libidn2"
"wget" -> "libidn2"
# ...

lists libidn2 as a dependency for packages gnutls and wget meaning that it cannot not be uninstalled without likely breaking gnutls and wget (and brew uninstall has to be run with the --force flag if either of these packages actually has to be removed).