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, it's good. So know we're going to learn what it means about Sorting in algorithms. Before that let's discuss the definition of SORTING ALGORITHM. are used to arrange the elements of a DS, such as an array, list, or tree, in a particular order, in ascending or descending order. These algorithms are used for organizing data, which enables more efficient searching, merging, and other operations.
What sorted do?🤔 array = [2, 1, 6, 4], look at this a list of array, it's not ordered, what we've to do is ordering this in increasing([1,2,4,6]) or decreasing([6,4,2,1]) order. We know that about BINARY SEARCH, it's sorted, to search for values like using two pointer but not in LINEAR SEARCH. DON'T FORGET WHERE TO USE SORTING👌
we're gonna solve problems & I'll share for u what I gained.🖐
BUBBLE SORT: Now am studying bubble sort. Lemme share for u in easy way what it means. the largest element "bubbles up" to the end in each pass. eg; arr = [3, 2, 5, 4] PASS 1: Compare 3 & 2, then 3 > 2 —> Swap—>[2, 3, 5, 4] Compare 3 & 5, then, 5 > 3 Ok no Swap Compare 5 & 4, then, 5 > 4 —> Swap—>[2, 3, 4, 5] PASS 2: Repeat the process again, check 2 & 3, no Swap. Ok then 3 & 4, no Swap, and 4 & 5, no Swap
Keep In Mind this concept. If so It's easy to apply on the implementations part.👨💻
👍1
As u see in the above image. Given a list of array = [6, 1, 4, 3] then What bubble sort doing here.😁 It looks fun right?😄 At the 1st we look at each list and pair them 2-BY-2. Swap(interchange), No Swap(if it's fixed). 👇Here what I gained the word we use when we talk about Bubble Sort.
,...👉🏽NEXT PROBLEM SOLVING
Swapping, Pass, in addition comparation.
How u can able to learn😊can u pls send ur own thought about Bubble Sort in the comment sections.
,...👉🏽NEXT PROBLEM SOLVING
👍1
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.