Difference Between Recursion and Iteration

If you are learning algorithms or data structures, you might have come across the terms recursion and iteration. Knowing the difference between the two can be confusing, so I will explain both terms using a real-world example.

Eating My Morning Bowl of Oatmeal


Everyday before I go to work, I take a shower, get dressed, and then head over to the kitchen to fix myself a big bowl of oatmeal. Breakfast is my favorite meal of the day and the most important. Many days I feel like skipping breakfast so that I can go on with my day. However, on those rare occasions when I decide to skip breakfast, I have usually regretted it. I spend the morning hungry and cannot fully concentrate on the tasks at hand.

The problem of eating my morning bowl of oatmeal can be implemented both iteratively and recursively. Iteration is the act of repeating a process. So, in the case of oatmeal, an iterative way to solve the problem of eating my bowl of oatmeal would be to do the following:

  1. Take one bite of the oatmeal
  2. Repeat Step 1 until the bowl is empty.

Recursion, on the other hand, is when a method calls itself. It involves breaking a problem into smaller versions of the same problem until you reach a trivial stopping case.

Let’s consider the problem of eating a bowl of oatmeal. I can solve the problem of eating the entire bowl of oatmeal recursively by breaking it into two subproblems as follows:

  • Take one bite of oatmeal
  • Eat the rest of the bowl of oatmeal

Each step of this recursive procedure gets smaller and smaller until all I am left with is one more spoonful of oatmeal. Once I finish that last spoonful, I am done, and I can go on about my day.

Here is how I would implement the iterative and recursive procedures for eating a bowl of oatmeal in Java pseudocode:

Iterative Implementation

public static main void main(String[] args) {

    while (!bowl.empty()) {
        // Keep taking bites over and over 
        // again until the bowl of oatmeal 
        // is empty

Recursive Implementation

public static void eatOatmeal(Bowl bowl) {

    if (bowl.empty()) {  
    // This is our stopping case. 
    // We stop taking bites once 
    // the bowl is empty

    else {
        eatOatmeal(bowl); // Recursive call

What Is a Maximum Spanning Tree?

In this post, I will explain the concept of a maximum spanning tree.

What is a Spanning Tree?

Let’s say we have a graph G with three nodes, A, B, and C. Each node represents an attribute. For example, for a classification problem for breast cancer, A = clump size, B = blood pressure, C = body weight.

Graph G:


A spanning tree is a subset of the graph G that includes all of the attributes with the minimum number of edges (that would have to be 2 because a tree with just one edge would only connect at most 2 attributes). In the graph above, there are three spanning trees. All spanning trees in this graph G must have the same number of attributes (3 in total) and edges (2 in total).

Spanning Tree 1:

Spanning Tree 2:

Spanning Tree 3:

What is a Maximum Spanning Graph?

OK, so we have our spanning trees. Now, imagine that each edge has a weight. This weight would be some number. Weighted graphs look like this:

The graph above could has three spanning trees, subsets of the graph G that include all of the attributes with the minimum number of edges.

Which one of those spanning graphs is the “maximum spanning graph?”…the one that, when you add up the weights of each edge of the spanning graph, delivers the greatest result. The answer to that is our maximum spanning tree.

Here is the maximum spanning tree:

Since the Attribute Designated as the Root Is Arbitrary, Is It Safe to Assume That This Choice Does Not Affect the Model Effectiveness?

Yes, it is safe to assume that. The graph doesn’t change, and Kruskal’s algorithm, the algorithm for finding the maximum spanning tree in a graph doesn’t care what the root is…it just wants to find the largest edge at each step that doesn’t produce a cycle.

The number of maximum spanning trees in a graph G remains constant. Whether you start at C, B, and E, doesn’t matter. The graph is what it is…unless of course you decide to add a new attribute…but then it would be a different graph with a whole other set of spanning trees.

How to Set Up Visual Studio Community 2019 for Windows 10

In this post, I’ll show you how to set up Visual Studio Community 2019 for Windows 10. This IDE will help us build C++ and Python programs. Our goal is to create a simple “Hello World” program in C++ and in Python.


Here are the requirements:

  • Set up Visual Studio Community 2019 for Windows 10.
  • Create a simple “Hello World” program in C++ and in Python


Installation of Visual Studio Community 2019

Open a web browser.

Type “download visual studio community” into your favorite search engine.


Click on the first result.


Click to download Visual Studio Community.

Click the up arrow (^) and then click “Show in folder.”


Right click on the file and click “Run as administrator.”

Click Yes.

Acknowledge the terms and conditions by clicking “Continue”.


Wait for the Visual Studio Installer to do its thing.


Select “Desktop Development with C++”. This is all you need to build C++ programs.

Select “Python development”. This is all you need to build Python programs.


I also plan to develop for Raspberry Pi and do some data science, so I installed some extra workloads. This is optional if all you want to do is develop programs in C++ and Python:

  • Linux development with C++
  • Data science and analytical applications

Choose the individual components that you want to install. It is OK to keep the default. Here is what else I selected:

  • Git for Windows
  • GitHub extension for Visual Studio
  • Class Designer (under Code Tools)

You don’t need any of the .Net stuff.

Click “Install”. Go get a bite to eat or take a break. This will take a while.


Once the install is complete, reboot your computer.


Search for the program “Visual Studio 2019” on your computer, and then create a Desktop shortcut for it so that it is easier to find the next time around.

On the sign-in screen, sign in using your Microsoft account (or create one).


Select “General”.

Creating the “Hello World!” Program in C++

Click “Create a new project”.


Click “Empty Project” to start a new project.


Configure your new project.

Right click on the project under the Solution Explorer. Go to Add -> New Item.


Select C++ File (.cpp), and give the source code a name. Then click “Add”.


Type in the code for your “Hello World!” program:

// This is a basic C++ program to display "Hello World!" 

// Header file for input output functions 

using namespace std;

// main function: where the execution of program begins 
int main()
	// prints Hello World! to the console
	cout << "Hello World!";

	return 0;

Click the green button (Local Windows Debugger) to compile and run.


You can also go to Build -> Build Solution. Then go to Debug -> Start Without Debugging.

That’s it! You should see the Hello World! message pop up.


Running a Program in a Command Window

Solution Explorer (Right click the project name) -> Open Folder in File Explorer

Open the Debug folder.


Select the hello_world.exe application.


Hold down the Shift Key and right click to open a menu

Choose “Copy as path”.

Press Windows + R to open a command prompt window.

Type cmd.exe in the box.


Click OK.

Right click to paste in the path.


Press Enter to run.


Creating the “Hello World!” Program in Python

Click “Create a new project”.


Under “Language” select Python.

Select “Python Application”.


Configure your new project. This time I checked “Place solution and project in the same directory”.

Click “Create”.


Type in the code for your “Hello World!” program:

print("Hello World!")

Click the green button (“Attach”) to run.

That’s it! You should see the message pop up.


To run via command line, go to the project folder and find the python file (hello_world.py in this case).


Hold down the Shift Key and right click to open a menu.

Choose “Copy as path”.

Press Windows + R to open a command prompt window.

Right click to paste in the path.


Press Enter to run. You might have to select the Python application you want to use to execute the file. You’ll only have to do this once.

The message should print to the terminal window. Congratulations! You are now ready to build C++ and Python programs!