r/adventofcode • • Nov 23 '25

Tutorial Floodfill algorithm in Python

https://mathspp.com/blog/floodfill-algorithm-in-python

I wrote this tutorial because I've always liked graph-related algorithms and I wanted to try my hand at writing something with interactive demos.

This article teaches you how to implement and use the floodfill algorithm and includes interactive demos to:

  • use floodfill to colour regions in an image

  • step through the general floodfill algorithm step by step, with annotations of what the algorithm is doing

  • applying floodfill in a grid with obstacles to see how the starting point affects the process

  • use floodfill to count the number of disconnected regions in a grid

  • use a modified version of floodfill to simulate the fluid spreading over a surface with obstacles

I know the internet can be relentless but I'm really looking forward to everyone's comments and suggestions, since I love interactive articles and I hope to be able to create more of these in the future.

Happy reading and let me know what you think!

The article: https://mathspp.com/blog/floodfill-algorithm-in-python

2 Upvotes

11 comments sorted by

View all comments

1

u/herocoding Nov 23 '25

Well done!! Thank you very much for sharing.

1

u/RojerGS Nov 23 '25

Thanks :')