Introduction to
Recursive &
Big O Notation
Wilianto, S.T., S.Pd, M.M., M.T.I.
Universitas IBBI
Profile
September 2022
Wilianto, ST, SPd, MM, MTI
Pemodelan & Simulasi
Wilianto, S.T., S.Pd, M.M., M.T.I.
1. Fak.Teknik Elektro USU Medan
Jurusan Sistem Kendali & Komputer
2. Jurusan Matematika STKIP Teladan Medan
3. Magister Manajemen STM IMNI Jakarta
4. Magister Teknik Informatika Universitas BINUS Jakarta
- Cisco CCNA IT Network & Infrastructure (DTS) Certified
- Cisco CCNA Cybersecurity Operations (DTS) Certified
- Aptikom Introduction to AI Certified
- NDG Linux Unhatched English 1120 cga Cisco Certified
- Intel AI for Workforce Training (SL-2 Singapore)
- Aptikom Data Science and AI/ML Training (kemendikbud)
- HTML, CSS, Javascripts Training (OpenClassroom) Certified
- Intro to Python, R, SQL Data for Data Science(Data Camp)
Certified
- SAP ABAP with Net Weaver 7.52 Certified
- UI/UX Design DTS Kominfo
- IoT DTS Kominfo & Indobot
• Dosen Tetap Teknologi Informasi Universitas IBBI
• Dosen Tidak Tetap Universitas Pelita Harapan (UPH)
• Pemilik Toko Sepatu New Colombia di Shopee, Tokopedia & Lazada
• Head Trainer di PT.Nusa Aksara Teknologi (Sustainable Living Labs-2) (SL2)
• Trainer Data Science di Narasio Data Surabaya
• Mentor di Bangkit Academy
Email: wiliantogan@gmail.com
Github: https://github.com/wiliantogan
Linkedln:
https://www.linkedin.com/in/wiliantogan
Telegram: https://t.me/Wilianto_Gan
Wilianto Gan
Latest Work Experiences:
● Tutor for mathematics, physics, chemistry, IT, and English in EL’S
Education Center
1991 – present
● Lecturer in Faculty of Science and Technology, IBBI University
2013 – present
● Online Shop Manager, Toko Sepatu New Colombia Shopee, Lazada and
Tokopedia
2020 – present
● Lead Facilitator Intel AI for Workforce, PT.Nusa Aksara Teknologi(SL2)
2021 – present
Education:
● North Sumatra University
1991 - 2000
Electrical Engineer
● Bina Nusantara University
2013 - 2015
Master of Information Technology
Your Image
About Me
Observe the following rules to ensure a supportive, inclusive, and engaging
classes
Give full attention
in class
Mute yourself
when the lecturer is talking
Keep your
eyes on the
lecturer
Raise hand
to ask questions
Make this classroom a safe
place to learn and share
Turn off or mute your
Handphone during the
class
Ground Rules
Introduction to Recursion
01.
02. Cracking Recursion Interview Questions
03. Introduction to Big O Notation
Learning Objectives
04. Top 10 Big O Interview Questions (Amazon,
Facebook, Apple and Microsoft)
❏ Introduction to Recursion
❏ Cracking Recursion Interview Questions
❏ Introduction to Big O Notation
❏ Top 10 Big O Interview Questions (Amazon,
Facebook, Apple and Microsoft)
Today’s Agenda
Introduction to
Recursion
What is Recursion?
What is Recursion?
What is Recursion?
Why do we need
Recursion?
How Recursion Works?
How Recursion Works?
How Recursion Works?
Recursive vs Iterative
Solutions?
When to Use/Avoid
Recursion?
How to Write Recursion in 3
Steps?
How to Write Recursion in 3
Steps?
How to Write Recursion in 3
Steps?
Fibonacci Numbers - Recursion
Fibonacci Numbers - Recursion
Cracking Recursion
Interview Questions
Interview Question -
1
Interview Question -
2
Interview Question -
3
Interview Question -
4
Introduction
to Big O
Notation
Big O Notation
Big O Notation
Big O Notation
Big O Notation
Big O Notation
Algorithm Run Time
Notations
Algorithm Run Time
Notations
Big O, Big Theta, and Big Omega
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Algorithm Run Time
Complexities
Space
Complexity
Space Complexity - Example
Space Complexity - Example
Space Complexity - Example
Drop Constant and Non Dominant
Terms
Why do we drop Constant and Non Dominant
Terms
Add vs
Multiply
How to Measure The Codes Using Big
O?
How to Measure Recursive
Algorithm?
How to Measure Recursive
Algorithm?
How to Measure Recursive Algorithm That Make Multiple
Calls?
How to Measure Recursive Algorithm That Make Multiple
Calls?
Top 10 Big O
Notation Interview
Questions
Top 10 Big O Notation Interview Questions
Interview Question -
1
Interview Question -
2
Interview Question -
3
Interview Question -
4
Interview Question -
5
Interview Question -
6
Interview Question -
7
Interview Question -
8
Interview Question -
9
Interview Question -
10
Brain Teaser!
Show and Tell
Discussions
Quiz
Pop-Up Quiz!
Duration: 10 minutes
Let’s check your understanding of this lesson!
Please access the provided quiz link to answer 10 questions related to the
material you’ve just learned.
The link will be shared in the chat box.
Conclusion
You have learned Recursion and
Big O Notation, and The
Interview Questions.
These knowledges will be
helpful for your work as a
developer in the future. Now,
you can understand why they
are important for your future
interview job as a developer!
Thank You

3 - Introduction to Recursive & Big O Notation.pptx

Editor's Notes

  • #3 if you like, please tell about yourself in more detail
  • #4 Turn off your audio throughout the session unless the Instructor asks you to do so. This is to minimize disruption during the sessions. Turn on your video at all times throughout the session to promote an offline-like class environment. If you are experiencing connection difficulties, please make it known to the Class Instructor using the Chat feature. Feel free to ask questions by using the Chat feature. In between the session, the Instructor will take a look at your questions and answer them. As such, please reserve the Chat Box as a space to ask questions or participate in class discussions and refrain from using it for idle chat and unrelated conversations. This is a place to learn and share our experience. Let's open our mind to other people's stories and understand each others' perspective. No idle browsing or chatting during class. Hands off phones or other devices that may distract you from giving your full attention.
  • #5 If possible, do a simple poll to know about students’ current skill level vs required skill level. Because the students need to see the importance to fill the “gaps”.
  • #6 Today’s Agenda (Outline Session)
  • #8 In computer science it’s a method of solving a problem where the solution depends on the solution to the similar instance of the same problem. Such problems can generally be solved by iteration as well. The real life example for recursion can be a Russian nesting doll. At first, you just see one figure usually painted wood that looks like this. If you remove the top half of this doll, you see another slightly smaller Russian doll inside it, do it repeatedly till the final doll which is a piece you can’t open it. As you see a Russian doll is a sequence of similar dolls inside each other that can be opened. But every time the size gets smaller and smaller, each time you open a doll, a smaller version of doll will be inside and you repeat the process until you reach the final doll that cannot be opened. You can see that the problem gets the small instance of the same problem until we solve it. So this technique making the problem smaller and smaller is called recursion.
  • #11 Recursion are asked in the interviews of companies like Apple, Google, Facebook and Microsoft.
  • #13 The stack memory is maintained by the system for the method invocation. You may already know that stack memory works on LIFO method, which means that the last entered will be removed first. Here push method is used to insert into a stack and a pop method, is used for removal. If you don’t know what the stack is, we will discuss it in the stack section in detail. As soon as we call the first method, the first statement that we see within the first method is to call second method. So the control goes to the second method. After completing the second method, it needs to come back to the first method to execute the print statement after the second method call. So the system needs to store the first method somewhere to come back for executing the rest of code, which is within the first method, once the second method execution is done, so the system will push the first method to the stack memory. So in this way, the system remembers that it needs to comeback to the first method. If you look at the second method, we see that this method also calls another method, which is third method. So the system once again needs to store the second method to come back to execute print statement after third method. So the second method will be pushed to stack as well, and this is applicable for third method because it also call another method within before executing the rest of the code. So it will be pushed to stack as well. The last method is here fourth method, which is executing one line of code without calling any function, which means that the system does not need to store it somewhere for calling back, so it will not be inserted in stack memory. So after finishing execution of the fourth method, how does the system know it needs to go back and execute third method not the second method. So this will come from stack memory. As we said, it works based on Last In First Out strategy. So the last method that is added to stack is the third method. So this method will be called by the system as a next step to execute the rest of code, which is printing, I am the third method. So after this statement, we know that the third method is done, so it will be popped out from the stack memory. And here again, the next thing will be from stack memory as well, which is second method. So the second method will be called and the print statement inside second method will be executed. And with this, we know that the execution of second method is complete, which means that it will be popped out from the stack memory. Now the system one more time to the stack memory and calls first method and execute the print statement inside the first method. And with this, the execution of first method is complete. So the first method will be popped out of the stack memory. So with this, all the execution is complete.
  • #14 This is a recursive function that calls itself. First, it checks if the entered parameter n is less than 1, it prints out that “n is less than one”, else it calls itself with parameter n-1. So to make things clear, let’s run this function for parameter of 4 and let’s see how this will be managed in the stack memory. When you run this function with parameter of four, first the system checks that whether is four is less than 1, we see that 4 is greater than 1. So this means that else statement will be executed, which is called the recursive function with parameter 3. So recursive method with parameter four will be stored in stack memory to come back for executing the print statement after this. So when running the function with parameter 3, the system once again checks that whether the 3 is less than 1, we see that 3 is greater than 1. so this means that else statement will be executed, which is calling the recursive method with parameter 2. So the recursive method with parameter 3 will be stored in stack to come back for executing the print statement after this. So once again when running the recursive function with the parameter 2, the system checks first if 2 is less than 1, we see that 2 is greater than 1, which means that else statement will be executed, which is calling recursive method with parameter 1. So the recursive method with parameter 2 will be stored in stack memory. So once again, when you are running the function with parameter 1 the system checks that this condition and we see that one equals to 1. So which means that else conditions will be executed, which is calling recursive method with parameter 0. So the recursive method with parameter 1 will be stored in stack memory. So when we call recursive method with parameter 0, we see that 0 is than 1. So the print statement executed and no need for storing method in stack memory. So to continue the execution, system refers to the stack memory again. So the last method is pushed that will be the first executed, which is recursive method with parameter 1 in our case. So the output from recursive method with parameter 1 will be 1, after calling this method from the stack, it will be popped out from the stack memory. So the system will go to the next method, which is located in stack memory. In our case, it’s a recursive method with parameter 2, and this will again print 2, and so on till 4 is printed. We understood that stacked memory is used by the system for managing recursive calls. So every time recursive method calls itself, the system stores it in the stack for coming back because there are execution statements left after calling itself, this means that the system somehow should remember the point where it stops to call recursive method with different parameter. Based on the condition to coming back.
  • #15 As we said, all recursive algorithms can be implemented iteratively, although sometimes it’s much more complex to do it. Both methods calculated Nth power of 2. As a parameter, both methods, take N, which is an integer number. In the recursive function over here, we have if condition here, which is a base condition to stop infinite loop. And if the condition is not satisfied, the function calls itself recursively and return power of 2. In the iterative solution, we start by creating two variables, which is I and power. So while i less than N, it multiplies power with 2 and in each iteration i is increased by 1. So if you look at this piece, of code carefully, we can see that the recursion code is easy to write. But there are many situations that converting a recursive function to an iterative function is extremely difficult. The second point here is a conditional statement decides the termination of recursion, while a control variable value decides the termination of iteration statements. In recursive function, infinite recursion can lead to system crash, whereas in iterative function, infinite iteration consumes CPU cycles. Each of these calls has its own advantages. We use recursion in the cases that we know that a problem can be divided in similar subproblems. And when we deal with that in structures like trees and graphs, the usage of recursion is more efficient.
  • #72 Link: https://www.youtube.com/watch?v=nSbvlktToSY
  • #73 Brain Teaser! You can use this 4:12 minutes riddle video as an ice break as well as a brain teaser. How to play: Students can use the chat box to discuss before answering the question. Use the jam board for students to write the answers. Ask another question if the riddle is solved before 5 minutes. The answer is included in the video (minute 2:10) Questions: Your expedition finally stands at the heart of the ancient temple. But as you study the inscriptions in the darkness, two wisps of green smoke burst forth. The walls begin to shake. The giant sandglass begins flowing with less than an hour before it empties, and a rumbling tells you that you don’t want to be around when that happens. Can you use math to escape the temple? Answers: Split them with 2 persons in one group, and 3 persons in two group The possessed students might lie, but you can just ignore the pairs If both arguing in 3 persons group, you know that both possessed are in the same groups. The other two groups if have each possessed, so you can choose the majority. You just need three of four groups. But if you are one find the exit, everything is useless.
  • #74 Demo Recursion: Demo Big O Notation:
  • #76 Quiz Link: https://forms.gle/b93dav1r46X5CAhq5
  • #79 Ask students to conclude before you, as a speaker, generalizes the topic as a whole.