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💪
SamiTech Code pinned «here I've prepared the topics we'll going to focus one by one DATA STRUCTURE: Array DS, …»
Array Search: Given an array, arr[] of n integers, and an integer element x, find whether element x is present in the array. Return the index of the first occurrence of x in the array, or -1 if it doesn't exist
This's Linear Search O(n)👆🏻 Try to think this problem before jumping into code🤔
input: arr[] = [1,2,3,4], x = 3 output: 2 Explanation: For array [1, 2, 3, 4], the element to be searched is 3. Since 3 is present at index 2, the output is 2. Input: arr[] = [10, 8, 30], x = 6
Output: -1
Explanation: The element to be searched is 6 and it is not present, so we return -1.
This's Linear Search O(n)👆🏻 Try to think this problem before jumping into code🤔
SamiTech Code
Array Search: Given an array, arr[] of n integers, and an integer element x, find whether element x is present in the array. Return the index of the first occurrence…
Code Implementation👆🏻
I wish you understand the logic! in the next I'll share for you some applications of Linear Search(Sequential Search)👌
class Solution:
def search(self, arr, x):
# Code with the logical error fixed
for n in range(len(arr)):
if arr[n] == x:
return n # Return the index if found
# Only return -1 after the entire loop has completed,
# meaning the element was not found in the entire list.
return -1
arr = [1, 2, 3, 4]
x = 3
# Create an instance of the class to call the instance method
sol_instance = Solution()
print(sol_instance.search(arr, x))
I wish you understand the logic! in the next I'll share for you some applications of Linear Search(Sequential Search)👌
👏3
Applications of Linear Search Algorithm:
👉🏽In The next step we'll learn about Binary Search this's very important while learning DSA😁
Unsorted Lists:
When we have an unsorted array or list, linear search is most commonly used to find any element in the collection.
Small Data Sets: Linear Search is preferred over binary search when we have small data sets with
Searching Linked Lists: In linked list implementations, linear search is commonly used to find elements within the list. Each node is checked sequentially until the desired element is found.
Simple Implementation: Linear Search is much easier to understand and implement as compared to Binary Search or Ternary Search.
👉🏽In The next step we'll learn about Binary Search this's very important while learning DSA😁
https://youtu.be/GnZ9ppr_zaI?si=No9RHS19jrAzzQzp 👉🏽Take a look this video carefully you'll get important point about Binary Search and it's usefulness.
YouTube
Binary Search - Data Structures & Algorithms Tutorial Python #13
Binary search is a popular search algorithm that can find an element using log(n) time complexity. In this video we will go over theory behind binary search, compare it with linear search and then implement binary search in python.
Code: https://githu…
Code: https://githu…
👍2
👉🏽For more info this pdf is important you can study it it's organized, clarifications, and also problem-solving. It contains Linear Search and Binary Search https://projector-video-pdf-converter.datacamp.com/29490/chapter3.pdf
As long as we learn DSA we must solve daily proble😎 👉🏽so here I've tried to solve binary search leetcode problem. https://leetcode.com/problems/binary-search/submissions/1925757948/
LeetCode
Binary Search - LeetCode
Can you solve this real interview question? Binary Search - Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.…