Keep in mind:
many of us know that we can use timers to test the speed of our code. But this raises a couple problems. The other main problem being that this still does not give us an objective way to talk about the difference between two blocks of code. This is exactly where Big O Notation comes into play. It provides a way for us to communicate the efficiency of our code in a way that is consistent and clear. So then what do we use if not time?👇 The simple answer is counting operations.
SamiTech Code pinned «Guys HRU all just sorry for my late, since we've just started DSA this course is needed! you need to know the basic concept of DSA You can learn it from youtube tutorial, but since we're focused on Python programming watch this video there is about 20 videos…»
I've defined function name called calcNumber(), then n parameter passed here so there is 3 operations these're *,/, & + then there're 3 operations here no matter if n increases just it's equal. cuz for all of them there is 3 operations. eg; n =100, & n=2. We don't care about n value but count the operations they are going to do one result. Look at this code:
In summary, an algorithm with an O(1) is the most preferable, and will always be more efficient than an algorithm of O(n). WHY? I'll give you the answer when we see O(n) & you can also try to guess it! cuz we're about to developing our understand in Algorithm,😁 with the next I'll share for you the graph of O(1)👇
def calcNumber(n):
return n * 3/2 + 4
print(calcNumber(6)) #What you've to understand here to say it's Big O notation there is no loop here there is only constant eg; O(1) == O(6) so we say that it's O(1) -> Constant.
In summary, an algorithm with an O(1) is the most preferable, and will always be more efficient than an algorithm of O(n). WHY? I'll give you the answer when we see O(n) & you can also try to guess it! cuz we're about to developing our understand in Algorithm,😁 with the next I'll share for you the graph of O(1)👇
The next point is O(n): If an operation has an O(n) (pronounced ‘O of N’), what this means is that, as ’n’ increases, so does the amount of operations needed to complete the problem. This is simple to understand, cuz it’s an entirely linear relationship. Here O(n) code looks like
To say it's linear Big O notation: Look at there is only one for loop it's not nested. when our n = 5 the time to complete this operation is also increase, and if n = 100 the time to complete this operation is also further increases,👉🏾that's why O(1) is preferably than O(n). and then the graph of O(n) is👇
def findNum(n):
for i in range(n):
print(i)
findNum(5)
To say it's linear Big O notation: Look at there is only one for loop it's not nested. when our n = 5 the time to complete this operation is also increase, and if n = 100 the time to complete this operation is also further increases,
Good Evening Guys🌃
I wish u're doing well and we'll keep learning without any stress💪Thanks for being with me🙏
I wish u're doing well and we'll keep learning without any stress💪Thanks for being with me🙏
What we've to understand is: An O(n) operation inside of an O(n) operation is an O(n * n) operation. In other words, O(n ²). This is the slowest and least efficient, and therefore the least desirable Big O Expression when considering time complexity. Here eg; of O(n ²)
Since it's nested loop it's O(n ²) algorithm,
def calc(n, m):
for i in range(n):
for j in range(m):
print(i, j)
calc(4, 5)
Since it's nested loop it's O(n ²) algorithm,
List: List is a built-in dynamic array which can store elements of different data types. It is an ordered collection of item, that is elements are stored in the same order as they were inserted into the list. List stores references to the objects (elements) rather than storing the actual data itself.
b = [2, 4, "word", True]
print(b)
a = list((1, 4, 3.2, 'banana', 5))
print(a)
b = list('STC')
print(b)
# Creating list with repeated elements
# we can use * for repeated items
a = [3] * 3
print(a)
# Accessing list elements
# elements in a list are accessed using indexing.
# Python indexes start at 0
a = [12,13,15,18]
print(a[0])
print(a[1])
print(a[2])
print(a[1:-1])
❤1🔥1
Key concept we've to know👇
Don't worry this course might be confusion, however what we learn in this course is very interesting and important! you've to use different resourses, we're on our way to understand, analysis, solve problem, but we must've to consistence 💪
#Adding elements into list
"""we can add elements to a list using the following methods:
append(): add at the end of the list
extend(): adds multiple elements to the end of the list
insert(): adds at a specific position
clear(): removes all items"""
x = []
x.append(15)
x.append(2)
x.append(3)
print("After append:", x)
x.insert(0, 1)
print("After insert", x)
x.extend([4, "list", True])
print("After extend", x)
x.clear()
print("After clear:", x)
Don't worry this course might be confusion, however what we learn in this course is very interesting and important! you've to use different resourses, we're on our way to understand, analysis, solve problem, but we must've to consistence 💪
❤1
here I've prepared the topics we'll going to focus one by one
May be this course takes time don't worry we'll learn from each others, ask questions, and share info. Let's go together and become mastered in DSA💪
DATA STRUCTURE:
Array DS, String in DS, Set, Dictionary, Recursion, Linked List DS, Stack DS, Queue DS, hash in DS, Tree DS, Heap in DS, Graph DS, Trie DS
ALGORITHMS: Searching Algorithms, Sorting Algorithms, Tree Traversal, Graph Algorithms,
PROBLEM SOLVING TECHNIQUES: Two Pointers, Sliding Window, Recursion, Dynamic Programming(DP), Greedy
May be this course takes time don't worry we'll learn from each others, ask questions, and share info. Let's go together and become mastered in DSA💪