Merge Sort:
splits the array into halves, sorts each half, then merges them back in sorted order.
It uses Divide & Conquer.
splits the array into halves, sorts each half, then merges them back in sorted order.
It uses Divide & Conquer.
How to understand Merging Sort🤔
For instance: look at the following.
[5, 2, 4, 1]
Divide
[5, 2] [4, 1]
Divide again
[5] [2] [4] [1]
Merging sort happens here👇
[2, 5] [1, 4]
Final merge
[1, 2, 4, 5]
👍2
def merge(left, right):
result = []
i = 0
j = 0
# Compare elements from both arrays
while i < len(left) and j < len(right):
if left[i] <= right[j]:
result.append(left[i])
i += 1
else:
result.append(right[j])
j += 1
# Add remaining elements
result.extend(left[i:])
result.extend(right[j:])
return result
"""
Merge sort keep in mind
Uses recursion
Sorting happens during merge
Time complexity: O(n log n)
Extra space needed(not in-place)
"""
Am in class learning Discreate Maths.
It's all about Methods Of mathematical proof. Almost this course is related with DSA. It means solving problems. Therefore, student in CS, IT, IS, & SW.Eng they've to focus on it🫡
It's all about Methods Of mathematical proof. Almost this course is related with DSA. It means solving problems. Therefore, student in CS, IT, IS, & SW.Eng they've to focus on it🫡
I'm out of mind. Cause our instructor teaching technique. He makes me to sleep. It's so borring🥱 Therefore what would be my choice🤔
Anonymous Quiz
43%
It's better to leave the class
36%
Have a patience
21%
Try to read some article
https://youtu.be/QUT1VHiLmmI?si=uNqT4gcfUAOKLF-o I'm about to learn numpy so you can start learn this with me. for simplicity watch this video
YouTube
Python NumPy Tutorial for Beginners
Learn the basics of the NumPy library in this tutorial for beginners. It provides background information on how NumPy works and how it compares to Python's Built-in lists. This video goes through how to write code with NumPy. It starts with the basics of…
What is Numpy:
-NumPy is a Python library.
-NumPy is used for working with arrays.
-NumPy is short for "Numerical Python".
👍2
Why Use NumPy?
In Python we have lists that serve the purpose of arrays, but they are slow to process.
The array object in NumPy is called ndarray, it provides a lot of supporting functions that make working with ndarray very easy.
Arrays are very frequently used in data science & also ML, where speed and resources are very important.
Why is NumPy Faster Than Lists?
NumPy arrays are stored at one continuous place in memory unlike lists, so processes can access and manipulate them very efficiently.
This behavior is called locality of reference in computer science.
This is the main reason why NumPy is faster than lists. Also it is optimized to work with latest CPU architectures
What does Numpy stands for?
Anonymous Quiz
0%
Number picker
0%
Numerical platform
100%
Numerical python
Installation of Numpy: If you've already installed python environment & PIP in your system, the next is easy👇
👉🏽else u can able to use. https://www.anaconda.com/download/success
C:\Users\Your Name>pip install numpy
👉🏽else u can able to use. https://www.anaconda.com/download/success
Anaconda
Download Success | Anaconda
Choose Your Download Windows Mac Linux Anaconda Distribution Package and environment management with conda, Anaconda Navigator desktop app, and 600+ packages. Everything you need for data science. Graphical Installer Windows 64-Bit Graphical Installer Graphical…
How to import numpy:👇
don't forget to use array keyword👉🏽 numpy.array
We use NumPy instead of Python lists for numerical and scientific computing primarily because NumPy arrays offer superior performance, memory efficiency,
and a rich set of mathematical functions.
import numpy
arr = numpy.array([1,2,3,4,5])
print(arr)
don't forget to use array keyword👉🏽 numpy.array
We use NumPy instead of Python lists for numerical and scientific computing primarily because NumPy arrays offer superior performance, memory efficiency,
and a rich set of mathematical functions.
#NumPy as np
#NumPy is usually imported under the np alias
#Therefore, Now the NumPy package can be referred to as np instead of numpy. We've to keep in mind it👀
#NumPy is usually imported under the np alias
import numpy as np
arr = np.array([1,2,3,4,5])
print(arr)
#Therefore, Now the NumPy package can be referred to as np instead of numpy. We've to keep in mind it👀
Check number of dimensions:👇
import numpy as np
a = np.array(42)
b = np.array([1, 2, 3, 4, 5])
c = np.array([[1, 2, 3], [4, 5, 6]])
d = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
#how many dimension appear in each line
print(a.ndim) #0
print(b.ndim) #1
print(c.ndim) #2
print(d.ndim) #3
Consider the following array:
arr = np.array([[1, 2, 3], [4, 5, 6]])
How many dimensions does it have?
arr = np.array([[1, 2, 3], [4, 5, 6]])
How many dimensions does it have?
Anonymous Quiz
88%
2
13%
3
0%
1
We've covered NumPy creating Arrays🎉🎉🎉 Now we gonna look at NumPy Array indexing: =>Access Array elements =>Access 2-D =>Access 3-D =>Negative indexing Finally, with a easy questions 🫡 But if you've questions feel free to write in the comment sections
❤1
#Access array element
import numpy as np
num = np.array([2, 4, 5, 7])
print(num[0]) #access the first element:2
print(num[2] + num[3]) #Summation: 12
#Access 2-D array
import numpy as np
num = np.array([[2, 3, 4], [5, 1, 6]])
print(num[1, 2]) #3rd element on 2nd row so 6
#Access 3-D array
import numpy as np
num = np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]])
print(num[0, 0, 1]) #2
#Negative indexing
import numpy as np
num = np.array([[2, 4, 1], [3, 5, 6]])
print(num[1, -1]) #6
I'll give the deep clarifications on the 3-D cause it might be small trick😦
❤2
Guys sorry this night just I've decided to have some rest. & It's hard to study. Cause I got bad cough😒😮💨
🫡1