Sorting - Part 1 | Selection Sort, Bubble Sort, Insertion Sort | Strivers A2Z DSA Course

take U forward
29 Jan 202343:43

Summary

TLDRThis video lecture from the Strivers A to Z DSA course covers essential sorting techniques for data structures and algorithms, focusing on selection sort, bubble sort, and insertion sort. The presenter explains each algorithm step-by-step, provides pseudocode, and discusses their time complexities, emphasizing the importance of these skills for placement interviews.

Takeaways

  • 📚 The video is a lecture from the 'Strivers A to Z DSA' course, which claims to be India's most in-depth course on Data Structures and Algorithms (DSA) with 456 modules.
  • 🔍 The course is comprehensive and is recommended for those preparing for placements, as it covers a wide range of topics including sorting techniques which are often asked in interviews.
  • 🔑 The lecture specifically covers three sorting algorithms: selection sort, bubble sort, and insertion sort, starting with selection sort as the first step.
  • 💡 Selection sort is explained through a step-by-step process where the minimum element is selected and swapped to the beginning of the array, and this process is repeated until the array is sorted.
  • 📝 Pseudo code is provided to help understand how to implement the selection sort algorithm in different programming languages like C++, Java, and Python.
  • 🔄 The time complexity of selection sort is analyzed to be O(n^2) for the worst and average cases, but it can be optimized in the best case scenario where the array is already sorted.
  • 🎯 The bubble sort algorithm is explained, which involves repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order.
  • 🛠️ The video provides an optimized version of the bubble sort algorithm that includes a 'did swap' flag to potentially break early if the array is already sorted, leading to a best-case time complexity of O(n).
  • 📈 The insertion sort algorithm is also discussed, which builds the final sorted array one item at a time, with each new element being placed in its correct position from the sorted portion of the array.
  • 🔍 The time complexity of insertion sort is explained as O(n^2) in the worst and average cases, but it can be O(n) in the best case when the array is already sorted.
  • 🌐 The video also promotes a learning platform called 'Learn by' that offers data science and full stack development programs, with benefits like live classes, Capstone projects certified by IBM, and job assistance.

Q & A

  • What is the claim made by the speaker about the Strivers A to Z DSA course in India?

    -The speaker claims that the Strivers A to Z DSA course is the most in-depth course on Data Structures and Algorithms (DSA) in India, with 456 modules, which is more comprehensive than any other paid or free courses available in the market.

  • What are the sorting techniques covered in the 'Step 2' of the DSA course?

    -In 'Step 2' of the DSA course, the speaker covers important sorting techniques including selection sort, bubble sort, and insertion sort.

  • What is the primary purpose of the 'Learn by' platform mentioned in the script?

    -The 'Learn by' platform is an edtech platform that offers data science and full stack development programs, dedicated to professionals, providing live online classes, one-on-one mentorship, doubt sessions, and opportunities to work on industry-based Capstone projects certified by IBM.

  • How does the selection sort algorithm work according to the script?

    -The selection sort algorithm works by repeatedly finding the minimum element from the unsorted part of the array and swapping it with the element at the beginning of the unsorted part.

  • What is the time complexity of the selection sort algorithm?

    -The time complexity of the selection sort algorithm is O(n^2), which is the worst, average, and best-case scenario due to the nested loops that iterate through the array.

  • What is the key difference between the selection sort and bubble sort algorithms?

    -The key difference is that selection sort selects the minimum element and places it at the beginning, while bubble sort pushes the maximum element to the end through adjacent swaps.

  • How can the bubble sort algorithm be optimized to improve its time complexity?

    -The bubble sort algorithm can be optimized by introducing a flag that checks if any swaps have occurred in a pass. If no swaps occur, the algorithm can terminate early as the array is already sorted, leading to a best-case time complexity of O(n).

  • What is the basic concept of the insertion sort algorithm?

    -The basic concept of the insertion sort algorithm is to take each element and place it in its correct position within the array by comparing and shifting elements as necessary.

  • How does the speaker describe the process of shifting elements in the insertion sort algorithm?

    -The speaker describes the process as taking an element and comparing it with the elements on its left, shifting the larger elements to the right until the correct position is found for the element being inserted.

  • What is the time complexity of the insertion sort algorithm in the best case?

    -The best-case time complexity of the insertion sort algorithm is O(n), which occurs when the input array is already sorted, and no shifts are needed.

Outlines

00:00

📚 Introduction to DSA Course and Sorting Techniques

The speaker introduces an in-depth Data Structures and Algorithms (DSA) course, emphasizing its comprehensive nature with 456 modules. The course is positioned as a must-have for placement preparation. The focus then shifts to sorting techniques, which are crucial for placements. The first sorting algorithm discussed is selection sort, followed by others like bubble sort and insertion sort. The speaker also promotes an educational platform called 'Learn by', which offers data science and full stack development programs, live classes, and opportunities to work on industry-based projects certified by IBM.

05:01

🔍 Detailed Explanation of Selection Sort Algorithm

The paragraph delves into the selection sort algorithm, explaining its process of selecting the minimum element from an unsorted array and swapping it with the first element. The speaker illustrates the steps of the algorithm with an example, showing how each element is compared and swapped to its correct position. The explanation includes a pseudocode representation and a discussion on the algorithm's implementation in different programming languages. The paragraph concludes with a step-by-step breakdown of how the array is sorted using selection sort.

10:03

💡 Observations and Pseudocode for Selection Sort

This section continues the discussion on selection sort, focusing on the observation of the algorithm's process. The speaker outlines the steps involved in finding the minimum element and swapping it with the first element of the unsorted portion of the array. The explanation includes a detailed pseudocode that demonstrates how to implement selection sort, emphasizing the importance of observing the array and swapping elements to achieve a sorted sequence.

15:04

📈 Time Complexity Analysis of Selection Sort

The speaker analyzes the time complexity of the selection sort algorithm, explaining that it has a time complexity of O(n^2) in the worst and average cases. The analysis is based on the summation of the first n natural numbers, which approximates to n(n+1)/2. The speaker also mentions that the best-case scenario, although not typically considered for selection sort, would be O(n) if the array is already sorted.

20:07

🔄 Understanding Bubble Sort Algorithm

The paragraph introduces the bubble sort algorithm, explaining its process of pushing the maximum element to the end through adjacent swaps. The speaker uses an example to illustrate how the algorithm works, showing how elements are compared and swapped to move the largest element to its correct position at the end of the array. The explanation includes a step-by-step breakdown of the algorithm's process and a discussion on its implementation.

25:07

🔄 Optimizing Bubble Sort with Early Termination

This section discusses an optimization for the bubble sort algorithm. The speaker introduces a method to break out of the sorting loop early if no swaps are made during a pass, indicating that the array is already sorted. This optimization can reduce the time complexity to O(n) in the best case, although the average and worst-case complexities remain O(n^2). The speaker emphasizes the importance of understanding the algorithm's behavior in different scenarios.

30:08

🚀 Introduction to Insertion Sort Algorithm

The speaker introduces the insertion sort algorithm, explaining its process of taking each element and placing it in its correct position in the sorted portion of the array. The explanation includes a detailed example of how the algorithm works, showing how elements are compared and shifted to their correct positions. The speaker also discusses the algorithm's implementation and provides a step-by-step guide on how to perform insertion sort.

35:12

🔍 Detailed Walkthrough of Insertion Sort

This paragraph provides a detailed walkthrough of the insertion sort algorithm, focusing on how each element is compared with the elements to its left and shifted accordingly. The speaker illustrates the process with examples, showing how elements are moved left until they are in the correct order. The explanation includes a discussion on the algorithm's implementation and the conditions under which elements are swapped.

40:13

📉 Time Complexity Analysis of Insertion Sort

The speaker analyzes the time complexity of the insertion sort algorithm, explaining that it has a worst-case and average-case time complexity of O(n^2) due to the number of comparisons and shifts required. However, in the best case, when the array is already sorted, the time complexity is O(n) as no swaps are needed. The speaker emphasizes the importance of understanding the algorithm's performance in different scenarios.

👋 Conclusion and Call to Action

The speaker concludes the video by summarizing the key points discussed about the sorting algorithms and encourages viewers to like, comment, and subscribe for more content. The speaker also invites viewers to follow them on Instagram, Twitter, and LinkedIn, with links provided in the video description. The call to action includes a prompt for viewers to share their learnings using a specific hashtag.

Mindmap

Keywords

💡DSA Course

The 'DSA Course' refers to a Data Structures and Algorithms course, which is a fundamental educational program for anyone looking to strengthen their understanding of programming constructs and problem-solving techniques. In the video's context, it is described as India's most in-depth course, boasting 456 modules, suggesting a comprehensive curriculum that covers a wide range of topics within the subject.

💡Sorting Techniques

Sorting techniques are algorithms used to rearrange a list of items into a certain order, typically ascending or descending. The script discusses several sorting methods, emphasizing their importance in the context of data structures and algorithms, and mentions that they are often a subject of interest in placement interviews for software development roles.

💡Selection Sort

Selection sort is a specific sorting algorithm that works by repeatedly finding the minimum element from the unsorted part of the list and putting it at the beginning. The video script provides a detailed explanation of how selection sort operates, including the process of finding minimum elements and swapping them into the correct positions.

💡Insertion Sort

Insertion sort is another sorting algorithm that builds the final sorted array one item at a time. It is mentioned in the script as one of the algorithms that interviewees might be asked to explain or code during placement interviews. The script explains the process of insertion sort, where each new element is placed in its correct position in a sorted section of the array.

💡Bubble Sort

Bubble sort is depicted in the video as a simple sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. The script describes the process of bubble sort, highlighting how it pushes the maximum element to the end of the array with each pass through the list.

💡Algorithm Implementation

The term 'algorithm implementation' refers to the process of writing code that performs a specific algorithm's task. The video script includes discussions on how to translate the conceptual understanding of sorting algorithms into actual code, using pseudocode and programming language examples.

💡Time Complexity

Time complexity is a measure of how long an algorithm takes in terms of the amount of input. The script analyzes the time complexity of the selection sort, bubble sort, and insertion sort algorithms, explaining that these algorithms have a time complexity of O(n^2) in their worst and average cases, but can be optimized for better performance.

💡Optimization

In the context of the video, optimization refers to the process of improving an algorithm to make it more efficient. The script suggests that bubble sort can be optimized by introducing a flag to detect if any swaps have occurred during a pass; if not, the algorithm can terminate early, as the array is already sorted.

💡Pseudocode

Pseudocode is an informal high-level description of an algorithm, which is used for planning out code before actual implementation. The script provides pseudocode for the sorting algorithms discussed, serving as a bridge between the conceptual understanding of the algorithms and their actual coding.

💡Runtime Error

A runtime error is an error that occurs during the execution of a program. The script cautions about the potential for runtime errors when implementing algorithms, specifically mentioning that attempting to access an array index that does not exist can cause such an error.

💡Career Counseling

Career counseling is a service that helps individuals to identify their skills, interests, and goals to make informed career decisions. The video script mentions a free one-on-one career counseling session as part of the offerings from a learning platform, suggesting that it can be beneficial for viewers to understand their career paths better.

Highlights

Introduction to the comprehensive Strivers A to Z DSA course, which is India's most in-depth course on Data Structures and Algorithms with 456 modules.

Emphasis on the importance of learning sorting techniques for placements, with potential interview questions on algorithms like insertion sort.

Promotion of LearnBase, an attic platform offering data science and full stack development programs with live online classes and industry-based Capstone projects certified by IBM.

Discussion on the benefits of LearnBase's one-on-one mentorship, doubt sessions, and project innovation labs across India.

Explanation of the selection sort algorithm, including its steps and the concept of selecting minimum elements and swapping them to the beginning of an array.

Illustration of the selection sort process with a step-by-step example using an array of numbers.

Introduction to the concept of pseudo code as a tool for understanding and implementing algorithms like selection sort.

Observation of the selection sort algorithm's time complexity, which is O(n^2) for the worst and average cases.

Introduction to the bubble sort algorithm, highlighting its method of pushing the maximum element to the end through adjacent swaps.

Description of the bubble sort process, including how it compares and potentially swaps adjacent elements to sort the array.

Analysis of bubble sort's time complexity, which is also O(n^2) in the worst and average cases, but can be optimized for best-case scenarios.

Optimization technique for bubble sort, which includes breaking out of the loop if no swaps are made, indicating the array is already sorted.

Introduction to the insertion sort algorithm, which builds the final sorted array one item at a time by comparing and inserting elements in their correct position.

Explanation of the insertion sort process, demonstrating how elements are shifted to their correct positions within the sorted portion of the array.

Writing of pseudo code for the insertion sort algorithm, outlining the steps for shifting elements and swapping them into place.

Analysis of insertion sort's time complexity, which is O(n^2) in the worst case but can be O(n) in the best case for an already sorted array.

Encouragement for viewers to engage with the content by liking, commenting, and subscribing for more learning opportunities.

Transcripts

play00:03

hey everyone welcome back to the channel

play00:04

I hope you guys are doing extremely well

play00:06

so this will be another lecture from the

play00:08

Strivers A to Z DSA course just in case

play00:11

yeah for the first time here this course

play00:13

is India's most yes most in-depth course

play00:16

on DS algo why do I see that the course

play00:19

has 456 modules

play00:22

you can go to the market buy any of the

play00:24

paid courses check out any of the free

play00:26

courses none of those courses on DS algo

play00:29

will have poor 56 problems or modules

play00:33

solved so this is definitely by far one

play00:37

of the most comprehensive course on DS

play00:40

algo and this is the only thing that you

play00:41

will be requiring if you are preparing

play00:43

for placements so in the previous videos

play00:46

we have covered the step one and now we

play00:48

will be going to step two the step two

play00:50

states you have to learn important

play00:52

sorting techniques in order to start

play00:54

your journey with Ds algo sorting is

play00:57

something which you have to know even if

play00:59

you're going for placements they might

play01:01

ask you sorting algorithms and the

play01:04

Sorting one which is Step 2.1 we have

play01:06

three algorithms selection sort bubble

play01:09

shot insertion sort so if you are

play01:12

appearing for placements they might ask

play01:13

you hey can you please tell me the code

play01:15

for insertion sort and you have to tell

play01:17

them right and sorting two will be based

play01:21

on recursion so we'll be covering that

play01:22

in the next lecture so without waiting

play01:24

let's start with selections on so before

play01:28

moving at in the video let me tell you

play01:29

about learn base so learn by is an attic

play01:30

platform that offers you data science

play01:32

and full stack development programs

play01:34

dedicated to professionals only so at

play01:36

lonely you will be getting 100 live

play01:37

online classes where you can interact

play01:39

with the faculties directly and get your

play01:41

doubt Result One Is to one one thing I

play01:44

didn't like about learn by is you'll be

play01:46

getting an opportunity to work on

play01:47

industry-based Capstone projects which

play01:50

will be certified by IBM so you're going

play01:52

to get a global accreditation which will

play01:54

be beneficial whenever you present that

play01:56

project anywhere that's gonna be very

play01:58

very helpful you also get in one is to

play02:01

one personal mentorship and you also get

play02:03

a one is to one daily doubt session

play02:05

where you can actually get all your

play02:07

doubts resolved also they have project

play02:08

innovation Labs across the country in

play02:10

Kolkata Pune Bangalore Hyderabad and a

play02:12

lot of other places so you can go over

play02:14

there and create your projects in the

play02:15

offline mode as well so once you enroll

play02:17

for any of the courses your three years

play02:19

of subscription so you can have all the

play02:21

learning modules and all the videos for

play02:22

three years in this program you'll also

play02:24

be getting 100 job assistance by their

play02:27

dedicated placement cell and in the past

play02:29

people have got hikes up to 250 percent

play02:31

and they are partnered with more than

play02:32

250 companies like ey Intel sap and a

play02:36

lot others land-based Albanese have also

play02:37

got placed in top companies like Amazon

play02:39

T Cell Cap Gemini Etc so what are you

play02:41

waiting for there's a link in the

play02:42

description click it and get your free

play02:44

one is to one career counseling session

play02:46

the question what is selection sort does

play02:50

the name recommends

play02:52

selection

play02:53

what do you select we select minimums

play02:58

levels as the name recommends what do

play03:01

you select we select minimums so as the

play03:04

name recommends select minimums so what

play03:07

you will do is you look at the entire

play03:09

array and you will say who is the

play03:11

minimum and it states 9 is the minimum

play03:15

so you'll take that 9 and you'll place

play03:17

it here

play03:18

perfect

play03:19

I place the 9 here and if this line is

play03:24

the minimum and you're placing it at the

play03:26

first place

play03:27

where will 13 go 13 says okay no issues

play03:31

I will go to your place because 9 has to

play03:33

come at first and now I'll write the

play03:35

remaining guys over here

play03:38

that's how you do it so that is the step

play03:40

one of the algorithm step one States get

play03:43

the minimum from the entire

play03:46

and you've got the minimum they place it

play03:49

at the first whoever is at the first

play03:51

goes to that minimum

play03:55

select minimums and swap is what the

play03:59

algorithm is all about so this is step

play04:01

one remember this this is step one what

play04:04

is step two let's see so the step two

play04:06

states okay I know the first I know the

play04:10

extreme smallest guy

play04:12

is at the first

play04:13

Nash we should select the next minimum

play04:17

we know one thing if the minimum is over

play04:19

here

play04:20

this array is sorted which portion of

play04:24

the array is not sorted that is this

play04:26

let's find the minimum can I say in this

play04:29

13 is the minimum so if 13 is the

play04:32

minimum I know 9 will stay where nine is

play04:35

13 is the minimum 13 will come at the

play04:38

first place it will and if 13 comes here

play04:42

where will 46 go 46 will go to 13. the

play04:46

46 goes here and the rest remains as it

play04:48

is

play04:50

perfect tip to done let's do step three

play04:53

so can I say

play04:55

after two steps I got the first two

play04:58

minimums and

play05:00

this portion of the array sorted I can

play05:02

now we are left with this portion

play05:06

what to do get the next minimum what's

play05:08

the next minimum 20

play05:11

as usual 9 30 stays 20 comes in if 20 is

play05:16

coming in here where will 24 Go 24 will

play05:19

go to 20. so take it to there and 50 to

play05:22

46 days

play05:24

step three is completed let's do step

play05:27

four

play05:28

at step four can you say that

play05:30

this portion of the array is sorted you

play05:32

can which portion is not this one so in

play05:37

this which is this minimum 24 place it 9

play05:41

13 20 24 52 goes at its place 46 let's

play05:46

do the step five

play05:48

so can I say at step four this is sorted

play05:51

and this is unsorted who is the minimum

play05:54

46

play05:55

so 9 13 20 24

play05:59

sorry 46 will come here

play06:03

and 52 will go here now

play06:05

at step five if this is done

play06:08

do you need to look like do you need to

play06:11

sort one element one element will always

play06:14

be solved so apparently can I say the

play06:16

entire array is sorted at step five one

play06:20

two three four five six six elements but

play06:23

actually took five steps to sort the

play06:26

entire array what I did was get the

play06:29

minimum and swap it and swap it then

play06:33

what I did was get the minimum and swap

play06:36

it then what I did was get the minimum

play06:38

and swap it so get the minimum and swap

play06:42

is the algorithm now the question comes

play06:46

okay we've understood the algorithm but

play06:48

how do I implement this in code I'll be

play06:52

writing the pseudo code so that you can

play06:53

write it in C plus plus as well as in

play06:55

Java as well as in Python so in order to

play06:58

implement algorithms you have to have

play07:01

something like observing power let's

play07:03

start observing for the first

play07:05

observation

play07:07

in the entire array very very important

play07:10

in the entire array we figured out the

play07:13

minimum can I say we figured out the

play07:14

minimum and whichever index the minimum

play07:17

appeared whichever index the minimum

play07:19

appeared I swapped it with the first guy

play07:22

zero then

play07:24

that's what I did that's why 13 is here

play07:28

and 9 is here

play07:30

so 0 to 5 is what I find next

play07:34

I took this which is from index 1 to

play07:37

index 5.

play07:38

and I got the minimum which is 13. and I

play07:42

swapped it with 46 thereby I got

play07:45

I went from 1 to 5 and the swapping

play07:48

happened

play07:49

with one

play07:51

and the minimum minimum minutes

play07:54

next

play07:55

in this

play07:57

I got the minimum and the swapping

play07:59

happened

play08:00

from two so can I say

play08:02

first time

play08:04

trap happened

play08:05

at index 0

play08:09

and minimum index

play08:11

next time swap happened at index one

play08:16

and minimum index

play08:19

and this minimum index is from the array

play08:22

0 to n minus 1. this minimum index is

play08:25

from the array 1 to n minus 1. next time

play08:28

can I say swapping happened at index 2

play08:31

because

play08:32

till that 0 and 1 are sorted and minimum

play08:36

Index this time is from 2 to n minus 1.

play08:39

so can I generalize this and can I see

play08:42

this will go like 0 1 2

play08:45

till what

play08:46

are you doing for the last guy are you

play08:49

trapping the last head is just still

play08:51

here you got 46 and you swapped can I

play08:54

see you go till n minus 2 at index y n

play08:58

minus 2 at index why because the last

play09:00

index is n minus 1 in arrays so can I

play09:04

say okay stopping is happening 0 1 2 and

play09:08

I'll go till n minus 2. so thereby can I

play09:12

write this as like this a pseudo code

play09:14

okay

play09:16

zero first time it will go 0 next time

play09:19

one next time two next time three and it

play09:21

goes on till n minus 2 and I plus plus

play09:25

can I see this the first

play09:27

and whenever I is 0

play09:30

I find the minimum from 0 to n minus 1.

play09:35

whenever is I is 1 I find it from 1 to n

play09:39

minus 1 whenever I is 2

play09:41

I find it from 2 to n minus 1 so can I

play09:44

say I need to find the minimum guy

play09:47

minimum so we know one thing I will be 0

play09:50

1 2 and there has to be an internal Loop

play09:53

why because you have to find the minimum

play09:55

in this range minimum in this range

play09:58

minimum in this range so the internal

play10:00

Loop Can You observe something from 2 to

play10:03

n minus 1 to write the internal Loop

play10:05

what are you waiting for write the

play10:06

internal Loop so can I say the internal

play10:08

Loop will be from J equal to I

play10:11

till J lesser than n

play10:14

minus 1 because that is the last index

play10:16

and Del J plus plus

play10:18

and you need to find the minimum I know

play10:21

the internal loop as well I know the

play10:23

internal loop as well

play10:24

now what is the next thing you have to

play10:26

do

play10:27

in this range

play10:29

in this range you have to find the

play10:31

minimum how do you do it very simple can

play10:35

I say initially I will keep the mini

play10:38

just imagine just imagine since your

play10:41

array is from 0 to n minus 1 I will say

play10:43

okay while we start let's consider this

play10:47

guy to be these small

play10:49

while we start for this let's consider

play10:51

this guy to be meaningful while we start

play10:54

for this let's consider this guy to be

play10:56

minimum I will say hey my minimum

play10:58

appears at index I itself at index I

play11:02

whoever is the first guy let's assume is

play11:04

the minimum I'm like okay

play11:06

then I'm saying if array of J

play11:10

is smaller than array of whatever

play11:13

minimum index you are considering

play11:16

what does this mean

play11:17

when am I treating when am I treating

play11:19

element by element I'm saying hey limit

play11:22

are you smaller than what I considered

play11:26

if you are can I say minimum okay you

play11:30

are smaller so my minimum appears at the

play11:32

jth index not at this guy I updated so

play11:37

can I say once you have I treated can I

play11:40

say once if I treated in the entire

play11:42

thing you will get the minimum index

play11:44

stored at the mini variable you will you

play11:48

will write so

play11:49

once this is completed what did we do

play11:52

let's go back to the algo what did we do

play11:55

so if you are iterating over here what

play11:58

will happen let's see minimum initially

play12:00

is

play12:01

zeroth Index right the minimum is zero

play12:03

what happened let's see in iteration

play12:06

we are taking 13. it's like 13 lesser

play12:09

than

play12:09

30 because minimum is 0 what happens

play12:12

array of 0 lesser than array of mini

play12:16

because mini is zero it's not there so

play12:20

it doesn't work next it goes here array

play12:23

of 1 lesser than array of meaning

play12:26

it's like 46 lesser than 13 no next time

play12:30

24 less than 30 next time 52 less than

play12:34

30 no next time 20 less than 30 no next

play12:37

time 9 less than 13 so the mini gets

play12:41

updated to five so you know at the fifth

play12:44

index the mini is what did you do

play12:47

you took the mini index and you took

play12:49

those ith index and you swap and you

play12:52

swap so you can just do a swap

play12:56

you can just do a strap

play12:58

wrap up whoever wherever is the mini

play13:01

whatever is the value

play13:03

with

play13:04

the first guy because if you have to

play13:07

take that mini and place it at the first

play13:09

first we'll go to that mini index so

play13:12

this app is also done

play13:13

simple as that so by the way how do you

play13:16

swap two numbers it's very simple

play13:18

imagine uh I have array of I and I have

play13:22

array of mini okay

play13:25

these are the two numbers that I have to

play13:27

swap imagine this is 15 and this is 12.

play13:30

so what I'll do is I will take a

play13:32

temporary variable that's another third

play13:35

variable that I will take and I'll say

play13:36

array of mini to go there so what will

play13:40

array of mini uh what will temporary

play13:42

have as of now 12 because area of mini

play13:46

is 12 and that was put in to the

play13:48

temporary now what I will do is I'll say

play13:51

array of mini

play13:52

can you replace yourself to array of I

play13:56

so what will be the value of array of

play13:59

mini reload B12 this value will go here

play14:02

and this will become 15 right now I will

play14:05

say array of I a array of I can you take

play14:09

the value of array of mini but it is

play14:12

replaced to 15. this is where since you

play14:14

stored in the temporary that works and

play14:16

it's a temporary can you get it the

play14:18

temporary will get it and this will

play14:20

become 12. tap lead cost so this is the

play14:24

strap that you have to write

play14:26

is the pseudocode of track function so

play14:29

if I had to code it up imagine I have

play14:31

given the N I take it as the input then

play14:33

I take this array of N and then I go

play14:36

across and I say this

play14:38

so this is basically nothing but the

play14:39

array input that I'm taking now I have

play14:42

to write the selection sort so maybe I

play14:45

can say selection I'll just pass it into

play14:48

the function I'll pass it let's write

play14:50

the selections on so void selection and

play14:54

this will be sort and I'll say let's

play14:56

take the array let's say the N so I'm

play15:00

passing this

play15:01

and I'm assuming this will do it and

play15:03

post this what I'll do is for I and I

play15:06

equal to 0 I lesser than n i plus plus

play15:08

can I print the array values to C if

play15:11

they are sorted or not okay let's see if

play15:14

they are sorted or not

play15:17

and what we can do is we can take the

play15:19

same example that we took it has six

play15:21

numbers 13 46 24

play15:26

52 20 and 9. so took the same example

play15:29

over here let's quickly write the code

play15:33

so whatever pseudo code I did right that

play15:36

I've converted into code now over here

play15:38

and if I go across and run this

play15:41

particular task you will see that this

play15:42

particular array is sorted over here in

play15:45

the output.txt

play15:46

so you have understood the selection

play15:48

sort algorithm in depth it's time to

play15:50

analyze the time complexity of this

play15:51

particular algorithm let's see can I see

play15:54

for the first time when the loop gets

play15:56

inside

play15:57

this particular Loop runs for n times

play16:01

exactly yes

play16:03

next time when it gets in then this

play16:06

actually runs so one lesson it's it runs

play16:09

from one to n minus one so can I say it

play16:11

runs for n minus 1. next time when it

play16:14

gets in it runs for one lesson so it's

play16:17

like n minus 2. next time when it gets

play16:20

in transfer one lesson

play16:22

n minus 3 so so on it kind of runs for

play16:25

till last last that we run for this is

play16:29

still here that's for two types so this

play16:31

is kind of kind of if I just try to take

play16:35

it to some near

play16:36

formula stuff can I say it's something

play16:39

like one

play16:40

plus two plus three plus dot dot till n

play16:43

which is nothing but the summation of

play16:45

the first n natural numbers which is n

play16:48

into n plus 1 by 2 can I say this I can

play16:53

so if I can say this what is this

play16:56

n Square

play16:57

plus n by

play17:00

2

play17:02

can I say this is how it looks like and

play17:05

if you remember the time complexity

play17:06

Remember the Time complexity lecture we

play17:09

did we ignore

play17:10

smaller things because n by 2 in

play17:14

comparison to n square is very small and

play17:16

we ignore constant thereby I can say

play17:20

that the time complexity is near about

play17:23

bigo of N squared and this is the best

play17:27

this is the worst and this is the

play17:30

average time complexity for this

play17:33

particular algorithm so we can see that

play17:36

we have completed selection sort

play17:38

successfully now it's time to understand

play17:40

bubble shot

play17:42

bubble chart so when we talk about

play17:44

Bubble shot you have to remember it

play17:46

pushes the maximum to the left and

play17:48

opposite to the selections because

play17:50

selection chart was taking the minimum

play17:52

at the front if you remember

play17:53

pushes the maximum to the last or does

play17:56

it do it by adjacent traffic addition

play17:59

swapping is the key over here

play18:02

how does the algorithm work let's

play18:03

understand

play18:04

first two elements Compares are they in

play18:07

the sorted order

play18:09

13 and 46 they are because 13 is smaller

play18:12

than 46. do not do anything go to the

play18:15

next two are they the sorted order 46

play18:18

before 24 no

play18:21

trap it

play18:22

okay

play18:25

24

play18:28

46 perfect let's go to the next

play18:31

46 52 are they in the sorted order yeah

play18:34

they are

play18:36

why will you do anything

play18:37

next 50 to 20 are they in the sorted

play18:41

order no 20 should be before take 20

play18:45

yeah take 50 to here

play18:48

so 20 52

play18:51

let's go to the next 50 to 19.

play18:54

are they in the sorted no so take care

play18:56

take care

play18:58

so let's do nine and then 52. so can I

play19:01

say

play19:02

after

play19:04

adjacent swaps

play19:06

like this like this like this like this

play19:10

like this one complete round of adjacent

play19:13

swap checkings Do You observe something

play19:16

the max 52 is at the last the max 52 is

play19:21

at the last done so the max 52 is at the

play19:24

last

play19:25

what should be your next step

play19:28

this portion of the array is kind of

play19:31

sorted so I need to work on this perform

play19:34

the same algorithm again let's do it 13

play19:37

24 is it okay it is

play19:40

246 is it okay yes 46 20

play19:45

no no no no no trap 46 here take 20 here

play19:50

let's swap it

play19:51

20

play19:53

46 let's go to the next

play19:55

46 9 are they no no take

play19:59

46 here

play20:02

9 46 do you compare the last two there's

play20:06

no point

play20:07

because 52 is already in the socket

play20:10

version

play20:11

there's no need do you only do it till

play20:13

here can I say no

play20:16

in this particular array 46 was the

play20:18

maximum and it's at the last so thereby

play20:21

after two steps the last two are in the

play20:26

correct orders so Step One is done step

play20:29

two is done let's do the step three so

play20:31

this is done this is done let's do the

play20:33

step three step three means this portion

play20:36

should be making sure that the maximum

play20:39

is over here h2n 1324 are they they are

play20:44

24 20. no no no stop it

play20:50

20 24 next 24 9 no no stop it

play20:56

done

play20:57

in this 24 was the maximum it's at the

play21:01

last

play21:02

step three done

play21:04

step four can I say step three means

play21:07

last three elements done

play21:09

this is left 1320 correct

play21:12

29 no pops up

play21:16

9 20. can I say for this 20 was the

play21:20

largest and it said the last so thereby

play21:23

post step four

play21:26

this is done next step five

play21:30

or step five

play21:32

this

play21:34

let's do a combination no

play21:36

pap

play21:37

913 for this portion 13 was the maximum

play21:41

and it's at the last so for this portion

play21:44

13 was the maximum and it's at the last

play21:47

so thereby

play21:50

this portion is sorted post step five

play21:54

do you need to do for a single element

play21:55

you do not thereby the entire array is

play21:58

sorted if you see so EV uh so you have

play22:01

understood the algorithm but now the key

play22:03

factor comes in which is implementing

play22:06

this to code

play22:08

because that is where the key lies

play22:10

let's try to do that

play22:12

what are we doing observation is the key

play22:15

0 1 2 3 4 5. we're going till

play22:19

the first step we went everywhere and we

play22:22

did

play22:24

add disen company

play22:26

the for the first time we kind of went

play22:30

till 0 till n minus 1 and we did

play22:34

adjacent facts if if it was not in the

play22:37

order next time

play22:39

we went like zero to

play22:40

n minus 2 because the last was shot next

play22:45

time we went from 0 to

play22:49

n minus 3. next time we went to 0 to

play22:54

n minus 4 and I said this is what we are

play22:57

doing and the next time zero to n minus

play23:00

5 and so on can I say I will just do

play23:03

till 0 to 1 not L 0 to 0 because one

play23:07

element will not matter

play23:08

if you carefully observe

play23:10

first Loop should run from here too next

play23:14

Loop should run from here to here so

play23:16

kinda

play23:17

can I say I can probably keep the value

play23:19

of I from n minus 1 till I can I keep I

play23:24

can if I do it I equal to n minus 1 I

play23:29

greater than 1 and I minus 1 this is

play23:31

what I have

play23:33

and internally I can always run the loop

play23:36

from J equal to 0 till J lesser than I

play23:39

and J plus plus

play23:41

is it similar is it similar observe

play23:45

0 to n minus 1

play23:46

0 to n minus 1 for the first time next

play23:49

time I is n minus 2 so 0 to 1 minus 2

play23:52

next time I is n minus 3 so 0 to n minus

play23:54

3 so

play23:56

I have made sure the looping is done

play23:58

what is the next thing that you are

play23:59

doing the next thing is pretty simple

play24:01

you take up two elements and you compare

play24:03

you take up two elements you compare so

play24:06

when you're looping from zero to n minus

play24:07

1

play24:08

it's kind of

play24:11

this is J so you're comparing J with G

play24:13

plus one and if they're not then you are

play24:15

swapped right so you're kind of

play24:18

comparing what are you comparing

play24:20

if a of J is kind of greater than J plus

play24:24

1 it's not in the correct order then

play24:26

you're saying swap then you're saying

play24:27

swap both of them

play24:29

a key thing to notice over a very key

play24:32

important thing

play24:35

if you are going from here to here

play24:37

that is wrong because for 52 it will

play24:40

have no one to compare

play24:42

do you actually go from here to here

play24:47

because of 46

play24:49

gets compared with J plus 1 which is

play24:51

this

play24:52

you actually Loop till here so what you

play24:54

can do is

play24:56

you can go over here and say instead of

play24:59

going till

play25:00

I exactly I will go till I minus 1

play25:04

because if I go till here

play25:07

if I go this will compare this will

play25:09

compare this will compare this will

play25:10

compare and 4652 will be compared

play25:13

because I'm doing J Plus 1. I'm taking

play25:15

the next index I don't need to go to

play25:17

so you can just go till one lesson

play25:20

and if you do not do that what will

play25:21

happen for 52 it will look for the next

play25:25

index which is not present and if you

play25:27

are accessing an index which is not

play25:29

present it will throw a runtime error

play25:32

remember this if you are accessing an

play25:35

index which is not present it will say

play25:38

runtime I did not

play25:40

children name

play25:42

that's why it's very important to run

play25:43

your Loops perfectly that's when you

play25:46

strap and once you have done this

play25:48

all steps at the end of the day the

play25:51

array will be sorted so what we will do

play25:54

is now we will write void bubble sort I

play25:58

will do the same thing array

play26:00

and n and instead of calling the

play26:03

selection sort we will say okay so I

play26:06

will just quickly go and write the same

play26:08

pseudo code

play26:10

if you remember this was kind of array

play26:12

of G

play26:15

if greater than array of J plus 1

play26:20

when you swap

play26:22

and in order to swap I've already taught

play26:23

you how to

play26:25

do that shopping you do this

play26:27

and then you say okay

play26:30

array of G plus 1 can use to array of J

play26:33

and in Array of J can you take the value

play26:35

of the rfj which is J plus 1 which is

play26:38

stored in temporary once you have done

play26:41

this entire thing the array will be

play26:43

sorted I'll just go and erase this

play26:45

output.txt and now go across and say to

play26:48

run it and see if the bubble shot is

play26:51

actually producing it it is it is

play26:54

producing so if I have to analyze the

play26:57

time complexity can you analyze the time

play27:00

complexity for me for this particular

play27:02

case it's quite similar to The Selection

play27:05

sort first time the algorithm kind of

play27:07

runs for n then for n minus 1 then for n

play27:11

minus 2 then for n minus 3 so kind of

play27:13

it's similar to selection sort where I

play27:16

say it's n plus n minus 1 plus n minus 2

play27:19

plus so on the last is 2.

play27:22

it's something if you just add a 1 to it

play27:25

it's similar to some of n natural

play27:27

numbers again n into n plus 1 by 2 which

play27:31

is n Square by 2 plus n by 2 smaller

play27:35

constants

play27:37

dissolved so the complexity is bigo of N

play27:41

squared can it be optimized that's right

play27:45

yes it can be it can be optimized this

play27:48

is the worst complexity

play27:52

this is the worst complexity and you can

play27:54

also call it as the average complexity

play27:56

in most of the cases this will become

play27:58

most of it

play28:00

but imagine if I give you an array which

play28:03

is something like 2 3 5 15 and 20. if I

play28:07

give you an array link it'll be like

play28:09

Trevor this is sorted yeah it is sorted

play28:12

so do you run the loop for n Square do

play28:15

you go across every time every time

play28:17

so

play28:20

what is the algorithm

play28:22

correct order no subs

play28:25

correct order no sweats correct order no

play28:29

swaps correct order no scrap array dude

play28:33

if everything is in the correct order

play28:35

and you're not performing a swap if

play28:37

everything is in the correct order what

play28:39

does it signify the array is in the

play28:42

ascending order if everything is in the

play28:44

correct order

play28:45

added is in the ascending order so the

play28:48

first

play28:49

check

play28:51

you did not find

play28:53

a swap to be done because everything was

play28:56

in the correct order so can I say if I

play28:58

do not do any swaps but do not do any

play29:01

swaps

play29:02

that's when I stop I do not perform

play29:04

so

play29:06

it's kind of if no subs done

play29:09

I don't need to go

play29:10

if on the first check no swap is done I

play29:13

don't need to go for this for this for

play29:15

this for this let me stop so the loop at

play29:18

the best case will run for bego of n if

play29:21

we do some optimizations let's go and do

play29:25

some optimization can I say

play29:28

if I say indeed did swap

play29:30

equal to 0 and over here if I just can

play29:34

say did swap equal to 1 which means if

play29:37

any

play29:38

if at any moment a swap happens

play29:40

then it's okay but if did swap at any

play29:45

time is

play29:47

there was no strap then I break out I

play29:51

will not go if the array is sorted it

play29:54

will just check for the first time and

play29:56

it will break

play29:57

post it

play29:59

right this also runs

play30:02

I'll prove you uh this one

play30:05

I'll prove you this one so I'll give you

play30:06

an example see

play30:08

six five four three two one now what

play30:11

I'll do is I will just go ahead and

play30:14

print this how many times the array runs

play30:16

okay and plus

play30:20

and I'll just give it

play30:22

and you can see how many times it runs

play30:23

now terminal and I'll go to run task

play30:26

this is a descending order and it runs

play30:28

for five tips because the size is six it

play30:31

runs so five but if I just change it to

play30:34

something like one two three four five

play30:36

six and I'll see how many times the

play30:38

first for Loop will you see

play30:43

uh delete one

play30:44

just a minute

play30:47

okay let's run it

play30:51

run it

play30:53

did you see something it never came to

play30:56

this because it it did break over here

play30:58

so it just ran for the first did not

play31:00

Swap and broke so can I see

play31:04

can I say the best time complexity will

play31:08

be nothing but Big O of n so the time

play31:11

complexity for the best of bubble shot

play31:14

is we go often this might be asked in an

play31:18

interview you have to critically tell

play31:20

them the use case you have to explain

play31:22

them in the dryer and tell them the

play31:24

worst and the average might be n square

play31:26

but if the array is sorted I will break

play31:28

up and I will end up getting a linear

play31:30

time complexity because the array is

play31:32

already solved the bubble shot is done

play31:35

now let's move on to the next one that

play31:37

is the insertion sort algorithm so

play31:40

talking about insertion sort you need to

play31:43

remember one thing it always takes an

play31:46

element

play31:46

and places it in its correct position

play31:50

takes an element

play31:52

and places it in its correction let's

play31:55

start yeah

play31:56

the algorithm starts with looking at the

play31:59

first element as an array and you will

play32:02

say that if this much is the array the

play32:05

element 14

play32:06

in a size 1 array is at the correct

play32:10

if I look at this much

play32:13

and I ask you is 9 at the correct

play32:16

position it'll be like no nine

play32:18

apparently should have been here and 14

play32:20

should have been here so this is what

play32:22

you do

play32:23

you go to the next element and you ask

play32:26

on the left side where nine should

play32:28

happen

play32:29

and that is where you take

play32:31

so you basically do it like this 9 40.

play32:35

perfect

play32:37

so

play32:37

then you go ahead to this one and you

play32:40

ask is 15 at the correct position or a

play32:43

size 3 and you say

play32:45

then you go ahead and say is 12 at the

play32:48

correct position for a size four I say

play32:51

no apparently 12 should have been here

play32:54

14 should have been here 15 should have

play32:57

been

play32:58

so do you see a pattern it's like 14

play33:02

will come here and 15 will come

play33:05

everyone right shifts by one and 12 kind

play33:09

of goes in its correct bottle

play33:11

so what you can do is

play33:13

you can take 12 and you can say Okay 12

play33:16

15. 15 will come here 12 will go here

play33:18

then you can say 12 14 so you can 12

play33:22

year and you can pass 14 year you can go

play33:24

to the left and slap tap till it can be

play33:27

swapped till it can be served so if you

play33:30

do like this 12 goes here it's like 12

play33:34

and 15. then 12 14. so 12 goes here and

play33:38

14 comes so go to the left till it can

play33:40

be can 12 be swapped with 9 no because

play33:43

that will distort the order but just go

play33:45

still here simple

play33:47

so what will happen

play33:49

it'll be like 12 14

play33:52

15 perfect next is six if you look at 6

play33:57

where ideally should be 6 in this array

play34:00

it should be here 9 should be here 12

play34:03

should be here 14 should be here 15

play34:06

should be here so can I do this can I

play34:09

take this six here but I have to I have

play34:12

to write shift every one by one how do

play34:14

you do it you take six you take 15. and

play34:17

you say Okay trap yourself what happens

play34:20

is six goes here 15 goes here next you

play34:23

take six fourteen fourteen comes here

play34:27

and 6 goes here next you dig six twelve

play34:29

twelve comes here 6 goes here next you

play34:32

take six and nine six goes here nine

play34:35

comes here

play34:37

if I have to do it it's like 6 15 not in

play34:41

the correct order let's wrap it 15 comes

play34:44

here and 6 goes here fourteen six no six

play34:49

comes here 14 goes 6 12 no 12 comes here

play34:53

6 goes six nine no nine comes here 6

play34:58

goes

play34:59

perfect it's like 6 9 12 14 15. so if I

play35:02

have to write it by raising it's like 6

play35:06

9 12 14 15. perfect I just went on to

play35:11

the left till it could have been drop

play35:14

shot trap right next

play35:16

eight in this particular array where

play35:20

does it will go where will it go in this

play35:23

particular array where will it go ask

play35:24

yourself

play35:25

the answer to that is 8 will go here

play35:28

so if 8 has to go here 9 has to go here

play35:31

12 has to go here 14 has to go here 15

play35:34

has to go here so again what do you do 8

play35:37

15 they say okay

play35:40

it goes yeah 15 so left

play35:42

can 814 can eight go till 14 yes 14

play35:46

comes here 8 goes here can it go more

play35:48

left yes it can eight goes here 12 goes

play35:50

here can it go more left yes 9 goes yeah

play35:53

it goes here is it in the correct order

play35:54

yes how do you know it because when you

play35:57

compared it with six it was not compared

play35:59

and understood six eight nine twelve

play36:02

fourteen fifteen

play36:03

6 8 9 12 14 15 remember this

play36:06

six eight nine twelve fourteen fifty

play36:11

next

play36:12

13 is the next guy that you are

play36:14

comparing can I say 13. ideally over

play36:17

here should have been here so do it

play36:20

again

play36:21

13 goes here 15 comes here 13 goes here

play36:24

14 comes here can I do a 13 12 no

play36:29

stop can I say post the last the array

play36:32

is sorted why because you picked up

play36:35

every element and you did put it into

play36:37

its character

play36:38

so how did it work I picked up one

play36:42

first time I picked up the first guy

play36:44

next time I picked up the second next

play36:45

time the third next time the four next

play36:47

and the fifth next time the sixth next

play36:48

time the seven picked up every guy I'm

play36:51

running from index 0 to n minus one

play36:53

that's for sure

play36:55

that's something for sure I'm running

play36:57

from 0 to n minus 1.

play37:01

and what am I doing

play37:03

what am I doing

play37:05

every guy I'm looking at the left are

play37:08

you greater are you greater Swap and

play37:11

till I can do it like for 13 I could do

play37:15

till here till it is possible on the

play37:17

left

play37:18

so I'll be like okay

play37:20

maybe JSI and I can keep while J greater

play37:25

than 0 and I can say and and okay left J

play37:29

minus 1. because the last that you can

play37:32

compare is still here

play37:34

is still here that's the last you can

play37:36

compare so imagine this was not 13 I'll

play37:39

give you an example

play37:41

if this was like 14

play37:43

15 and this is 7. so the seven would

play37:46

have last gone here

play37:48

or imagine this was five for an example

play37:51

it's just five what would have happened

play37:55

five would have gone

play37:56

like

play37:57

till here

play37:58

and then five would have got compared

play38:00

with six by standing here by standing

play38:04

here would have compared it on the left

play38:05

that's why you don't go till zero

play38:07

because right before zero you do the

play38:09

last comparison that's why and that's

play38:11

why J minus one the last comparison if

play38:14

it is greater than a of j e if it is

play38:17

greater

play38:19

that means can you please swap

play38:21

so I'm not writing the swap you know how

play38:24

to write you say a of J minus 1 and a of

play38:27

G that's what you say

play38:28

right and that's when it ends and you

play38:32

can just do a j minus minus

play38:34

oh yeah because what am I doing is I'm

play38:37

taking the element and I'm saying left

play38:39

left small left small okay and go left

play38:43

again come back left small trap again

play38:45

goal F small go the moment it's not

play38:48

small stop and go to the next guy

play38:52

White

play38:53

now time to write insertion soft right

play38:56

so avoid insertion sort int array

play39:01

and int n so as usual we can just do

play39:05

this as insertion Source okay and I'll

play39:09

quickly write this book

play39:11

[Music]

play39:13

until here you know the pseudo code y g

play39:15

greater than 0 y not greater than equal

play39:17

to imagine if J goes equal to Z

play39:21

is J minus 1 like when J is 0 J minus 1

play39:24

will be minus

play39:25

runtime that's all right so over here

play39:29

you can go ahead and swap it and the

play39:31

temporary equal to

play39:33

array of a minus 1 and an array of J

play39:37

minus 1 is array of J and then you can

play39:41

go ahead and say array of J is equal to

play39:43

Temporary and once you've swapped let's

play39:45

go move left so J minus minus let's go

play39:48

ahead and quickly run this and see if

play39:51

this is sorting this particular thing

play39:53

yeah it is sorting done simple if we

play39:56

analyze the time complexity

play39:59

what will be the time complexity imagine

play40:02

for a

play40:04

reversed array like something like five

play40:09

four three two one what's up

play40:12

for the first time five no swaps

play40:16

next time it comes to four

play40:19

and does this one it's like four five

play40:22

next time it comes to three that's a

play40:25

complete like three goes here then three

play40:27

goes here next Summit so it's like three

play40:30

four five two one next time it comes to

play40:33

two two goes here two goes here two goes

play40:36

here the two kind of goes here it's like

play40:38

two three four five one next time it

play40:40

comes to one one goes here one goes here

play40:42

one goes here one goes here so it's like

play40:44

one two three four five

play40:45

it's kind of going

play40:47

extreme left to the to the extreme left

play40:49

this Loop for the first time

play40:54

run for zero times when it was at five

play40:57

when it was at point when it went to

play41:00

four it stopped one place

play41:03

next one it was a tree it swapped two

play41:05

places next when it was at two it

play41:08

trapped three pieces next it was when it

play41:11

was at one it went left four places it's

play41:14

kind of a game going into the similar

play41:16

direction of summation of natural

play41:18

numbers which is n cross at n plus one

play41:21

by two makes it near above the time

play41:23

complexity of n square if you remember

play41:25

the time complexity class so I can say

play41:28

the kind of worst case is n Square the

play41:34

average case is also n square but what

play41:37

about the best case imagine I give you

play41:40

something like one two three four five

play41:43

one two three four five and I go back to

play41:45

the code and I go back to the code

play41:49

so imagine I give you a completely

play41:51

sorted

play41:52

and I go back to the code and let's see

play41:54

how many times this Loop runs

play41:57

go to the terminal and try to print it

play41:59

this Loop will not run a single day

play42:02

because for one there's no one on the

play42:04

left or two there's no one on the left

play42:06

three is already in its correct position

play42:07

4 is already in its correct position

play42:09

five is already in its correct position

play42:10

six is already so this

play42:14

putting them into the correct position

play42:15

never happens so apparently only this

play42:18

Loop runs or check

play42:20

it's a big off that's a big go offend

play42:22

the best case for this is nothing but B

play42:27

go of n complexity because

play42:31

there is no straps that happen everyone

play42:33

is at its correct order just go to

play42:36

everyone that is what the time is taken

play42:38

for in case of insertion sort so so with

play42:42

this I can tick mark insertion sort and

play42:45

it is completed uh the time is 5 29 yes

play42:50

because I do take a lot of retakes while

play42:52

recording because I want it to be

play42:55

perfect like a lot of times I teach two

play42:57

or three times so please uh please for

play43:00

this effort if you understood everything

play43:02

do consider hitting that like button and

play43:05

to follow our ritual please do comment

play43:08

understood if you understood everything

play43:09

and if you have doubts you can

play43:11

definitely put that into the comment

play43:12

section I'll be replying to them and if

play43:15

you're new to our Channel what are you

play43:17

waiting for hit that subscribe button

play43:19

and follow Strivers A to Z DSA course

play43:22

share your learnings with the hashtag

play43:24

and yes if you haven't followed me on

play43:26

Instagram Twitter LinkedIn all the links

play43:29

will be in the description make sure you

play43:30

follow me with this I'll be wrapping up

play43:32

this video let's read in some other

play43:33

video till then

play43:35

[Music]

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
Data StructuresAlgorithmsSorting TechniquesPlacement PrepDSA CourseCareer CounselingLearn by DoingTechnical LearningJob AssistanceIndustry Partnership
¿Necesitas un resumen en inglés?