Posts

Nested Loops: Behind the Scenes!

Image
👋 Welcome! Hi! Welcome to this tutorial on  Nested Loops  where we will cover the basic principles with examples,  let’s begin!  👍 👀 First Example This is the basic structure of nested for loops. We have a for loop within another for loop. Let’s see an example in action! 📣 Note:  Please note that you should use different variables for each loop, since you might need to use these values in your code and if you use the same variable, the value can change and result in unexpected behaviors. 🔍 Step by Step! Now we have a real example of nested for loops. We have some code on the outer loop, then the inner loop and more code on the outer loop. Let’s walk through this code step by step. You can check the code and table below for a visual reference of the process. The outer loop  for i in range(3)  will start with an initial value of  0  for  i . The  print  statement will be executed. NOW.. You will...

'Break' Statement: Behind the Scenes!

Image
👋   Welcome! You will use  break  during the course and in your future projects. It's very important that you understand how it works and when to use it. 💻 Let’s begin!  👍 As you can see by the  (very subtle hahaha 😁)  graphics below, the  break  statement is the code equivalent of a  “STOP”  signal. 🔧  Use With the  break  keyword you can stop the execution of  while  loops and  for  loops. If you have nested loops, you will stop the nearest enclosing loop. (You will see examples in this tutorial ✨). ✅  Break Statement and While Loops! Let’s see a  break  statement inside a  while  loop and analyze the code in the  image below : Using  while True  means that you will enter an infinite loop if there is nothing stopping the loop because the condition will always evaluate to  True . Then, we check the if statement con...

Higher-Order Programming: Behind the Scenes!

Image
Welcome to Higher-Order Programming! Hi, Welcome! In this section we are going to dive into Higher-Order Programming. You will learn how to pass functions as parameters to other functions and how to return functions from functions. Let’s get started! In the diagram below you can first see two of the functions we will be working with. These are regular functions  f  and  g  that perform a simple operation on their parameter. In the purple rectangle you can find an example of  passing functions as arguments  to other functions. In this case we pass the functions  f  and  g  to the function  h . In the blue rectangle you can find an example of  returning functions  from functions. Let’s look at each one in more detail! : ) Passing Functions as Arguments The function  applyFunctions  takes three parameters ( f ,  g  and  p ).  f  and  g  are functi...

Closures: Behind the Scenes!

Image
Welcome! Hi, Welcome! We will discuss a very interesting concept related to functions,  “Closures” , what they are and how to use them. Let’s get started! First of all, what is a Closure? The concept might be a little bit abstract at first, so let’s jump to a concrete example: What does a Closure look like? Here you can see the general structure of a Closure: We have an enclosing function ( returnMultiplyFunction ) with a nested function ( multiplyBy ). The nested function uses a variable that is part of the enclosing function’s scope (in this case,  multiplyBy  uses x, the parameter passed to the outer function) The inner function is returned by the enclosing function. NOTE:  A Nested function is a function defined inside another function. You may ask, what happens when we call  multiplyBy ? We have two variables but we only pass in one argument,  y . What value will  x  have? Let’s find out! : ) Ready...

Complexity Classes and their Graphs: BEHIND THE SCENES!

Image
Welcome Hi! Welcome to this section on  Complexity Classes and their Graphs . First of all,  congratulations on these weeks of hard work!!  : ) You’ve done a fantastic job and we’re so glad you’ve come this far. You learned in lecture that algorithms have different running times and how the orders of growth tell you how efficient an algorithm is, given very large inputs. The order of growth is an approximation, an upper bound on how much an algorithm could take to run, the worst-case scenario. We will first have a quick introduction to 2-D graphs and then we’ll discuss and illustrate the logic behind each complexity you’ve learned (constant, logarithmic, linear, loglinear, polynomial and exponential). The Graph The complexity classes are represented with  a graph . Graphs have two axes: The  X-axis , a horizontal line (represented below with an orange line). The  Y-axis , a vertical line (represented below with a green line). E...