What Is Asymptotic Analysis? And Why Does It Matter? A Deeper Understanding of Asymptotic Notation.
Key Takeaways
Asymptotic analysis is a crucial concept in algorithms, and understanding it is essential for accurately determining the complexity of an algorithm. The video explains the concept of asymptotic behavior, why it matters, and how it is used to analyze the performance of algorithms.
Full Transcript
okay so what we're gonna discuss today is asymptotic bounding it's very important for algorithms and this is generally something that if you don't have a sound fundamental understanding of you're going to be mistaken in an interview you're going to say a complexity that's completely wrong again if you have not subscribed to the channel subscribe to a channel like this video so when we see a single four loop doesn't that mean linear time when we see two for loops doesn't that mean quadratic time right not always so I think what we have to look at first is a little math and a little calculus I was never amazing at calculus but to really understand asymptotic behavior we need to look at what asymptotic really means so what is asymptotic behavior really mean so I have a graph here so what is this graph so maybe I don't know the equation for this graph but I can tell about where this graph is going so if I took the limit as X approaches infinity if I go towards infinity where does the Y value go and you see that the Y value goes towards zero so this is what this looks like okay so now we see the asymptotic behavior of the graph of 1 over X which is what this graph is this is the graph of 1 over X the asymptotic behavior of it is that as X approaches infinity we get closer and closer to 0 and you notice our points of interest what we're interested in here is tail behavior the idea of asymptotic sand looking at an asymptotic behavior is we want to see how does the graph behave getting into very very large X values into very large values this is the idea of asymptotic complexity ok so now we know what asymptotic means it means tail behavior but wait why don't I just measure the elapsed to real time why don't I just take the wall time why don't I just do that why don't I just do what I see in Li code I mean I run my code on LI code and it tells me this ran in this many milliseconds so I guess I know how strong my algorithm is right so that is not the best way to approach things so in computer science often problems are applied at a grand scale like if you're writing an algorithm for a company like Facebook or a large company it's going to be used across millions and millions of users and large inputs to an algorithm so our best point of interest is to see how does this behave on the tail end how does this behave as input gets very large we only see the true measure of performance of an algorithm when we have very very large input and this is why asymptotic complexity intrigues us in computer science so let's look at an example to really drill this in so we have an algorithm insertion sort that is going to do two times N squared comparisons so this could be any random implementation and for some reason it does two times N squared comparisons so we have a merge sort implementation that does 50 times n log n comparisons so we know that insertion sort is slower and don't worry about the constants here they're just arbitrarily chosen so we have computer a running the slower algorithm insertion sort but computer a runs at ten billion instructions per second and we have computer be running the faster algorithm but computer B is 1,000 times slower than computer a it is 1,000 times slower but it's running a faster algorithm so what is the approximate wall time going to be for both of these computers computer a and computer B okay so can you guess them now now do we have an idea of which is going to be faster okay so we see that the actual running time for the faster computer is going to take 5.5 hours and is running a slower algorithm and we see that computer B is a thousand times slower it is a thousand times slower but it's going to only take 20 minutes to run so why was this algorithm faster and why was this algorithm slower why did the slower algorithm lose on a computer is a thousand times faster so the answer to that question lies in the idea of asymptotic bounding and looking at the asymptotic behavior so I think something to really drill in this concept is looking at linear time looking at the class of poundings that we call linear time so whenever I say linear time I say this in a lot of videos I say we're going to have a linear time bound what does that actually mean so I want us to look at a few different graphs so what we're going to do is I'm going to draw a few graphs and we're going to notice something in common between them and is going to lead us to the most critical word in all of that we're doing so let me start drawing graphs so here is our first graph y equals 1 over 2x okay so we have one graph so let's draw another graph ok so here is another graph we see that this is the graph of y equals x so let's draw two more graphs just to really hammer this point home ok so I just drew the graph y equals 2x and I just drew the graph y equals 3x so what do you notice about these graphs I want you to mentally imagine this if i zoom out when our input is super super super large when i zoom far outwards what are all of these going to do what will they all look like do you see how all of these are lines do you see how all of these are lines all of them have these same tail behavior all of these graphs have the same behavior so the key thing behind asymptotic complexity is the whole point of taking asymptotic measures is so that we know how a graph is behaving when input is very large when input is very large that is when we see a graphs true colors so do you see why we drop constants if I have a Big O of 1/2 of n so why do I drop the 1/2 why does it just become Big O of n why is Big O of N and asymptotic measure so you see this is the exact area because all of these graphs will do the same thing when we get very very large input they will scale in a linear fashion this is a linear scaling when I say log n time when I say linear time when I say quadratic time when I say cubic time when I say factorial time when I say exponential time what am I saying I'm not describing a individual graph I am describing a class of functions I'm describing a class of behaviors and that is what this is all about okay and that is all for this video if you like this video like if this video was clear if this made things a little clearer about why we use Big O notation why we do asymptotic complexities LIKE the video and subscribe to the channel I think every one of these videos is a tiny building block to build a larger picture to make you very competent and able in the interview that is the key to this we're just slowly building that knowledge set until you are in a very strong level along with your Lea code studying to do well in the interview so that's what this is all about so awkward [Music]
Original Description
Free 5-Day Mini-Course: https://backtobackswe.com
Try Our Full Platform: https://backtobackswe.com/pricing
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions
First, we must ask what asymptotic means. Well, you have probably heard of the word "asymptote".
An asymptote is a "line that continually approaches a given curve but does not meet it at any finite distance".
Therefore, asymptotic analysis is the analysis of tail behaviors not reaching any finite point. It is a method of describing limiting behavior.
Wall Time vs. Asymptotic Complexity
Well...why not just measure the seconds our code takes to run? And get the Elapsed real time (wall time)?...like Leetcode.
So why do we care about this...well in computer science we often deal with problems that are at a grand scale with inputs to the order of millions and billions.
And thus, the true measure of the efficiency of an algorithm is best expressed in its tail behavior on very large input. It only then shows its true colors.
An Expression of Asymptotic Behaviour
Insertion Sort: 2 * n^2
Merge Sort: 50 * n * log(n)
We have 2 computers:
Computer A: runs 10 Billion instructions / second
Computer B: runs 10 Million instructions / second
Computer A is 1000x faster than Computer B
Computer A runs insertion sort, Computer B runs merge sort
How long will each computer take to sort 10 million numbers?
Computer A: 5.5 hours
Computer B: 20 minutes
A computer that runs 1000x faster lost horrendously to a computer that runs 1000x slower than it.
But the thing is that insertion sort will be faster for an initial amount, but it will lose as the input gets larger (and that's what we care about and what is a true expression of its efficiency).
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: https://www.youtube.com/channel/UCOf7UPMHBjAavgD0Qw5q5ww
Tuschar Roy: https://www.youtube.com/user/tusharroy2525
GeeksForGeeks: https:/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Back To Back SWE · Back To Back SWE · 43 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
▶
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
4 Tips To Learn Java Programming As Fast As Possible As A Beginner
Back To Back SWE
3 Mistakes Beginners Make When First Learning Java and Android Development
Back To Back SWE
How To Get A Job At Google | The Ultimate Guide To Algorithmic/Coding Interviews
Back To Back SWE
The Ultimate Big O Notation Tutorial (Time & Space Complexity For Algorithms)
Back To Back SWE
Total Occurrences Of K In A Sorted Array (Facebook Software Engineering Interview Question)
Back To Back SWE
The N Queens Problem using Backtracking/Recursion - Explained
Back To Back SWE
Compute All Mnemonics For A Phone Number (Recursion/Backtracking Problem)
Back To Back SWE
How To Reverse A Singly Linked List | The Ultimate Explanation (Iteratively & Recursively)
Back To Back SWE
Depth First & Breadth First Graph Search - DFS & BFS Graph Searching Algorithms
Back To Back SWE
The 0/1 Knapsack Problem (Demystifying Dynamic Programming)
Back To Back SWE
The Dutch National Flag Problem (The Quicksort "Band-Aid")
Back To Back SWE
Test If A Binary Tree Is Symmetric ("Symmetric Tree" on Leetcode)
Back To Back SWE
The IP Address Decomposition Problem - Compute All Valid IP Addresses From Raw IP String
Back To Back SWE
How To Permute A String - Generate All Permutations Of A String
Back To Back SWE
The Balanced Parentheses Problem - Classic Stack Problem ("Valid Parentheses" on Leetcode)
Back To Back SWE
Knuth–Morris–Pratt (KMP) Pattern Matching Substring Search - First Occurrence Of Substring
Back To Back SWE
Implement An LRU Cache - The LRU Cache Eviction Policy ("LRU Cache" on LeetCode)
Back To Back SWE
Find The Longest Increasing Subsequence - Dynamic Programming Fundamentals
Back To Back SWE
Generate All Palindromic Decompositions Of A String ("Palindrome Partitioning" on Leetcode)
Back To Back SWE
Implement A Sudoku Solver - Sudoku Solving Backtracking Algorithm ("Sudoku Solver" on LeetCode)
Back To Back SWE
Merge K Sorted Arrays - Min Heap Algorithm ("Merge K Sorted Lists" on LeetCode)
Back To Back SWE
Partition To K Equal Sum Subsets From An Array of Integers - The Backtracking Approach
Back To Back SWE
Edit Distance Between 2 Strings - The Levenshtein Distance ("Edit Distance" on LeetCode)
Back To Back SWE
Total Ways To Decode A String - Recursive Dynamic Programming Approach ("Decode Ways" on LeetCode)
Back To Back SWE
The Change Making Problem - Fewest Coins To Make Change Dynamic Programming
Back To Back SWE
Compute The Next Permutation of A Numeric Sequence - Case Analysis ("Next Permutation" on Leetcode)
Back To Back SWE
Count Total Unique Binary Search Trees - The nth Catalan Number (Dynamic Programming)
Back To Back SWE
Generate All Strings With n Matched Parentheses - Backtracking ("Generate Parentheses" on LeetCode)
Back To Back SWE
Implement A Max Stack - A Stack With A .max() API (Similar To "Min Stack" on LeetCode)
Back To Back SWE
The Recursive Staircase - Top Down & Bottom Up Dynamic Programming ("Climbing Stairs" on LeetCode)
Back To Back SWE
Search A Maze For Any Path - Depth First Search Fundamentals (Similar To "The Maze" on Leetcode)
Back To Back SWE
Total Unique Ways To Make Change - Dynamic Programming ("Coin Change 2" on LeetCode)
Back To Back SWE
Test If A Binary Tree Is Height Balanced ("Balanced Binary Tree" on LeetCode)
Back To Back SWE
Find The Second Largest Item - Heap & Tracking Approach (Beginner Big N Interview Question)
Back To Back SWE
Increment An Integer Represented As An Array ("Plus One" on LeetCode)
Back To Back SWE
Merge 2 Sorted Lists - A Fundamental Merge Sort Subroutine ("Merge Two Sorted Lists" on LeetCode)
Back To Back SWE
Clone An Undirected Graph - The Utility of Hashtable Mappings ("Clone Graph" on Leetcode)
Back To Back SWE
Clone A Linked List (With Random Pointers) - Linear Space Solution & Tricky Constant Space Solution
Back To Back SWE
Deeply Understanding Logarithms In Time Complexities & Their Role In Computer Science
Back To Back SWE
Implement A Binary Heap - An Efficient Implementation of The Priority Queue ADT (Abstract Data Type)
Back To Back SWE
Max Contiguous Subarray Sum - Cubic Time To Kadane's Algorithm ("Maximum Subarray" on LeetCode)
Back To Back SWE
Binary Tree Bootcamp: Full, Complete, & Perfect Trees. Preorder, Inorder, & Postorder Traversal.
Back To Back SWE
What Is Asymptotic Analysis? And Why Does It Matter? A Deeper Understanding of Asymptotic Notation.
Back To Back SWE
An In-Depth Algorithmic Analysis of Bubble Sort. Best Case, Average Case, & Worst Case.
Back To Back SWE
Maximum Sum Rectangle In A 2D Matrix - Kadane's Algorithm Applications (Dynamic Programming)
Back To Back SWE
A Detailed Algorithmic Analysis of Insertion Sort. Best Case & Worst Case.
Back To Back SWE
Binary Tree Level Order Traversal - Drawing The Parallel Between Trees & Graphs
Back To Back SWE
Implement A Queue Using Stacks - The Queue ADT ("Implement Queue Using Stacks" on LeetCode)
Back To Back SWE
All Nodes Distance K In A Binary Tree - Performing Bidirectional Search On A Tree Using A Hashtable
Back To Back SWE
Longest Common Subsequence (2 Strings) - Dynamic Programming & Competing Subproblems
Back To Back SWE
Egg Dropping Problem: Dynamic Programming Fundamentals & Understanding Subproblem Decomposition
Back To Back SWE
Minimum Window Substring: Utilizing Two Pointers & Tracking Character Mappings With A Hashtable
Back To Back SWE
Reverse Polish Notation: Types of Mathematical Notations & Using A Stack To Solve RPN Expressions
Back To Back SWE
Asymptotic Notations 101: Big O, Big Omega, & Theta (Asymptotic Analysis Bootcamp)
Back To Back SWE
The Backtracking Blueprint: The Legendary 3 Keys To Backtracking Algorithms
Back To Back SWE
Fast Multiplication: From Grade-School Multiplication To Karatsuba's Algorithm
Back To Back SWE
Search A 2D Sorted Matrix - Fundamentals of Search Space Reduction
Back To Back SWE
The Quicksort Sorting Algorithm: Pick A Pivot, Partition, & Recurse
Back To Back SWE
Lowest Common Ancestor Between 2 Binary Tree Nodes (A Recursive Approach)
Back To Back SWE
Sort A K Sorted Array - Investigating Applications of Min/Max Heaps
Back To Back SWE
More on: Algorithm Basics
View skill →Related Reads
📰
📰
📰
📰
Building a Power Grid Inside Minecraft with BFS Algorithms
Dev.to · Carlos Cortez 🇵🇪 [AWS Hero]
The Run-Length Encoding Trick: How Simple Strings Get Compressed
Medium · Programming
75 Days of Leetcode — Day 4: #238 — Product of Array Except Self
Medium · AI
I implemented the algorithm that broke the sorting barrier. Dijkstra still wins.
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI