SamiTech Code pinned «Morning guys🫡: In this morning am gonna focus on Sorting Algorithms and related problems. Therefore have u heard about sorting before? what it means? IF you know…»
https://youtu.be/gcRUIO-8r3U?si=Rhu_wwzMYHKtuNrL In this's video you get interesting understanding😊 hopefully is all about SORTING ALGORITHMS Therefore go and check it. Before that👉🏽Have a nice Lunch🥗
YouTube
Sorting: Bubble, Insertion, Selection, Merge, Quick, Counting Sort - DSA Course in Python Lecture 10
Timeline --
0:00 Bubble Sort
4:26 Insertion Sort
8:33 Selection Sort
11:54 Merge Sort
23:30 Quick Sort
30:38 Counting Sort
38:59 Sorting in Practice
Code solutions in Python, Java, C++ and JS can be found at my GitHub repository here: https://github.com/gahogg/Data…
0:00 Bubble Sort
4:26 Insertion Sort
8:33 Selection Sort
11:54 Merge Sort
23:30 Quick Sort
30:38 Counting Sort
38:59 Sorting in Practice
Code solutions in Python, Java, C++ and JS can be found at my GitHub repository here: https://github.com/gahogg/Data…
👍1
here bubble sort: Time: O(n^2)◽️
Space: O(1)⬛️
This's in place sort w/c means👇 Shifting array elements.
Space: O(1)⬛️
This's in place sort w/c means👇 Shifting array elements.
👍1
Hey guys. Now am discussing with my friends just I give for them small challenge.
What is one thing in your morning routine?🛖
Then they share their ideas. So what about u?
What is one thing in your morning routine?🛖
Then they share their ideas. So what about u?
INSERTION SORT:
is one of the best algorithms to truly understand sorting logic, cause it works exactly like how humans sort cards in their hand. Human way to understand: Imagine you're holding cards: 👉🏽You pick one card at a time 👉🏽You insert it into the correct position among the already sorted cards Left side = sorted, Right side = unsorted Think of it like this: I take the next element and slide it left until it reaches its correct position. No swapping neighbors again & again like bubble sort instead, we shift elements.
How Insertion Sort is doing?
Step 1: i = 1 Sorted part: [3] key = 2 Compare: 3 > 2—Shift 3 right [2, 3, 4, 1] Step 2: i = 2 Sorted part: [2, 3] key = 4 4 is already in correct place - no change Step 3: i = 3 Sorted part: [2, 3, 4] Key: 1 Shift all larger element > [1,2,3,4]
SELECTION SORT: The definitions👇
Not end yet😁
Here in my own word I understand in this way; You are given an integer list of array then, you scan all numbers in your minds. At the first this question have to come to your mind. You look at the elements, then you pick out the smallest numbers then compare with the first position(index). Then you swap them together. this process is repeatedly goes through the logic until order(sorting) satisfied.
Not end yet😁
given a list for array numbers: [3, 2, 4, 1] what we've to do is by using selection sort and sort the numbers.
Btw am using the code editor on w3school
SamiTech Code pinned «https://youtu.be/gcRUIO-8r3U?si=Rhu_wwzMYHKtuNrL In this's video you get interesting understanding😊 …»
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)
"""