Тёмный

Insertion Sort Pseudocode 

Computer Science
Подписаться 215 тыс.
Просмотров 21 тыс.
50% 1

This is the second of two videos about the insertion sort. It builds on the previous video, which illustrated the algorithm for an insertion sort, by describing the pseudocode for an insertion sort. This video illustrates how a pointer variable separates the sorted and unsorted sections of a list. It shows how the pointer advances from left to right, making each item in the unsorted section the current item, as the insertion sort progresses. A defining characteristic of the insertion sort is that that sorted section of the list is scanned from RIGHT TO LEFT. You can therefore recognise the code for an insertion sort because you’ll see a variable being DECREMENTED within a nested loop. The insertion sort is like sorting a hand of playing cards. The insertion sort is particularly good for lists that are nearly sorted already, or when you just want to insert a single item into a list that is already in order. For example, the high score board of a game would be a good candidate for an insertion sort. The insertion sort is a little faster than a bubble sort but, like the bubble sort, the insertion sort does not scale well. It is not the best choice for a very large list.

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 18   
@de_pool8768
@de_pool8768 4 года назад
Your channel is saving me from failing my Computer Science study lol
@MrIzzo006
@MrIzzo006 5 лет назад
It's been a while 🤓 love your tutorials, thank you.
@opst1704
@opst1704 5 лет назад
I have a question: Why do we use for loop and then while loop? Is it because in first loop we know how many iterations we will have and that's why we are using for loop, and in the second loop we don't know how many iterations will happen so we use while loop. I heard that is a general rule about for and while loops. So, is that the reason why we have for and then while loop? Yes, I am aware that it is possible to use only for loop or while loop, or combined... for example in Kotlin language there's no traditional for loop so we would have to use two while loops... Anyway, I understand this is a pseudocode, just wanted to be sure about the reason why we used for and then while loop. Brilliant explanation and visualization, as usual!!!
@ComputerScienceLessons
@ComputerScienceLessons 5 лет назад
Hi Voja Radovic You are quite correct. The outer loop is a For loop because it's count controlled and the inner loop is a While loop because it's condition controlled. This approach leads to neat and tidy pseudocode. However, you could have an outer loop like this: pointer = 1 While pointer < myArray.Length ... ... pointer = pointer +1 End While But in this case you need to explicitly initialise the pointer to 1 before the loop begins and explicitly increment it within the loop. You could even write the inner loop as a For loop, starting with something like this: For position = position To 0 Step -1 Next But an inner For loop is going to get really messy. You would need an If statement inside the loop to test for the other exit condition, that is If myArray(position - 1) > current Then... I guess there is no one way to write the pseudocode for an insertion sort, and therefore, no one way to implement it. You've given me a good idea for an exercise that I can use with my own students. I'm going to ask them to implement an insertion sort with a while loop in the outside and a for loop on the inside. Tnx.
@opst1704
@opst1704 5 лет назад
@@ComputerScienceLessons Thank you for sorting this out!
@mk9834
@mk9834 5 лет назад
Yeah just love your tutorials you rock
@ComputerScienceLessons
@ComputerScienceLessons 5 лет назад
You're very welcome. I will be uploading a video about how to implement an insertion sort in VB.NET soon.
@greedsin555
@greedsin555 6 часов назад
Thanks mate
@Magius06
@Magius06 10 месяцев назад
Love it, life saver
@ComputerScienceLessons
@ComputerScienceLessons 10 месяцев назад
You're welcome :)KD
@mtmohammed369
@mtmohammed369 Месяц назад
I don't know if I am wrong but I felt like your voice is like Jason Statham's voice ❤😂
@namelessunnamed6544
@namelessunnamed6544 8 месяцев назад
Real!
@moviofootgame
@moviofootgame 2 года назад
👍
@ComputerScienceLessons
@ComputerScienceLessons 2 года назад
:) KD
@faisalzamanhayder8357
@faisalzamanhayder8357 5 лет назад
again 1st comment
@ComputerScienceLessons
@ComputerScienceLessons 5 лет назад
:)
@MrIzzo006
@MrIzzo006 5 лет назад
Somebody give him a cookie 🥳
@thechaoslp2047
@thechaoslp2047 5 лет назад
Hey dude youre awesome
Далее
Insertion Sort VB.NET Implementation
10:31
Просмотров 9 тыс.
Insertion Sort Algorithm
8:28
Просмотров 18 тыс.
Watermelon magic box! #shorts by Leisi Crazy
00:20
Learn Quick Sort in 13 minutes ⚡
13:49
Просмотров 343 тыс.
Insertion sort algorithm
14:15
Просмотров 1,5 млн
Learn Merge Sort in 13 minutes 🔪
13:45
Просмотров 303 тыс.
How Do I Write Pseudocode?
27:58
Просмотров 657 тыс.
Sorting Algorithms Explained Visually
9:01
Просмотров 538 тыс.
Insertion Sort Code | DSA
12:25
Просмотров 28 тыс.
Sliding Window Technique - Algorithmic Mental Models
36:45
Hash Tables and Hash Functions
13:56
Просмотров 1,6 млн
Watermelon magic box! #shorts by Leisi Crazy
00:20