Dutch National Flag Algorithm. Explained with playing cards.

  Рет қаралды 8,822

CodeSmart

CodeSmart

Күн бұрын

Dutch National Flag AKA DNF is a well-known algorithmic problem for coding interviews. It was first proposed by
Edgar Djaikstra, one of the brightest minds in the history of computer science who happens to be Dutch by nationality. The flag of the Netherlands consists of three colors: white, red, and blue. Our objective is to group the colors together and maintain the correct order. In other words, this is a sorting problem of 3 unique values. For example, sorting an array consisting only 0, 1, and 2’s. Or it could be 3 unique ranges of values. For example - values less than pivot equals to pivot and greater than the pivot. ( We need this type of sorting in quicksort). The idea of this algorithm is to push low values to the left, high values to the right, and don’t care about the mid values, it will be in the middle eventually.
We will use three pointers - low, mid, high and will keep 4 invariants.
- Everything at the left of low is low values.
- From the low pointer to the left of the mid pointer are mid values.
- From mid pointer to the high pointer are unknown values.
- Everything at the right of the high pointer has high values.

Пікірлер: 75
Dutch National Flag problem leetcode
15:01
Engineerhoon
Рет қаралды 9 М.
Русалка
01:00
История одного вокалиста
Рет қаралды 5 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 53 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 4,3 МЛН
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 50 МЛН
The Dutch National Flag Problem (The Quicksort "Band-Aid")
10:54
Back To Back SWE
Рет қаралды 30 М.
Every Sorting Algorithm Explained in 120 minutes (full series)
1:57:33
Kuvina Saydaki
Рет қаралды 50 М.
LeetCode Sort Colors Solution Explained - Java
7:40
Nick White
Рет қаралды 31 М.
Selection sort explained | Visualized with playing cards
8:01
Tower of Hanoi | Recursion
24:01
Aditya Verma
Рет қаралды 163 М.
Where Does Bad Code Come From?
42:21
Molly Rocket
Рет қаралды 185 М.
Confessions from a Big Tech Hiring Manager: Tips for Software Engineering Interviews
20:16
Зачем ЭТО электрику? #секрет #прибор #энерголикбез
0:56
Александр Мальков
Рет қаралды 91 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН