🪟 Windows ServerSchnellladesäulen: Wenn der Ladestecker zickt - Golem.de(17.09.2026 um 23:29 Uhr)
🕵️ HackingPOL-MK: Betrug beim Online-Kauf - Presseportal(17.09.2026 um 17:57 Uhr)
🔧 ProgrammierungAgentic CLI customizations now in the usage metrics API(17.09.2026 um 23:08 Uhr)
🔧 ProgrammierungCopilot impact dashboard now shows feature engagement(17.09.2026 um 23:47 Uhr)
🪟 Windows ServerSchnellladesäulen: Wenn der Ladestecker zickt - Golem.de(17.09.2026 um 23:29 Uhr)
🕵️ HackingPOL-MK: Betrug beim Online-Kauf - Presseportal(17.09.2026 um 17:57 Uhr)
🔧 ProgrammierungAgentic CLI customizations now in the usage metrics API(17.09.2026 um 23:08 Uhr)
🔧 ProgrammierungCopilot impact dashboard now shows feature engagement(17.09.2026 um 23:47 Uhr)
🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

Selection Sorts

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Straight Sort-



Comparison based Algorithm that swaps minimum element in place to achieve a

T(C) = O(n^2) _ and a _S(C) = O(1) as the swapping occurs in place.






Steps-




  1. Start with the first element as the minimum.

  2. Compare this element to the rest of the elements to find the smallest.

  3. Swap the smallest element with the first element.

  4. Move to the next element and repeat until the list is sorted.






Code-






CODE
#include <iostream>
using namespace std;

void selectionSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
int minIndex = i;
for (int j = i+1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
swap(arr[i], arr[minIndex]);
}
}

int main() {
int arr[] = {64, 25, 12, 22, 11};
int n = sizeof(arr)/sizeof(arr[0]);
selectionSort(arr, n);
cout << "Sorted array: \n";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
return 0;
}










Special Points-




  1. Simplicity

  2. Unstable

  3. Inplace Sorting

  4. Might be beneficial for small number of cases



Image description






Heap Sort



Heap Sort is a comparison-based sorting algorithm that uses a binary heap data structure. It's efficient and consistent.






Steps




  1. Build a Heap

  2. Sorting
    1.Build a max heap from the input data.
    2.The largest element is swapped with the last element of the heap and
    removed from the heap.


    1. Heapify the root of the heap.

    2. Repeat the process until all elements are sorted.











Code-






CODE
#include <iostream>
using namespace std;

void heapify(int arr[], int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;

if (left < n && arr[left] > arr[largest])
largest = left;

if (right < n && arr[right] > arr[largest])
largest = right;

if (largest != i) {
swap(arr[i], arr[largest]);
heapify(arr, n, largest);
}
}

void heapSort(int arr[], int n) {
// Build max heap
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);

// Extract elements from heap one by one
for (int i = n - 1; i >= 0; i--) {
swap(arr[0], arr[i]);
heapify(arr, i, 0);
}
}

int main() {
int arr[] = {12, 11, 13, 5, 6, 7};
int n = sizeof(arr) / sizeof(arr[0]);

heapSort(arr, n);

cout << "Sorted array: \n";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}










Special Points:




  1. Binary Heap is used

  2. Non Stable Algorithm

  3. T(C) - O(nlogn)

  4. Sort in Place S(C) - O(1) {Constant}

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Small AI models let drones autonomously identify and attack battlefield targets
1 Quelle
Here’s What the AI Apocalypse Could Look Like
1 Quelle
The FAA’s plan to fix air traffic? $875 million worth of AI
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Selection Sorts

Thematisch verwandte Begriffe: Selection, Sorts · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...