Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Selection Sort Algorithm

Selection Sort is a simple and intuitive sorting algorithm. It divides the input list into two parts: a sorted sublist of items which is built up from left to right at the front (left) of the list and a sublist of the remaining unsorted…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Selection Sort is a simple and intuitive sorting algorithm. It divides the input list into two parts: a sorted sublist of items which is built up from left to right at the front (left) of the list and a sublist of the remaining unsorted items. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, swapping it with the leftmost unsorted element (putting it in sorted order) and moving the sublist boundaries one element to the right.






Implementation of Selection Sort






// Time Complexity: O(n*n) (where n = size of the array)
// for the best, worst and average cases.
// Space Complexity: O(1)
void selectionSort(int arr[], int n)
{
for (int i = 0; i <= n - 2; i++)
{
int min = i;

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






Logic:



1. Outer Loop: Iterate from the start of the array to the second last element.



2. Initialize Minimum: Assume the current element is the smallest (min = i).



3. Inner Loop: Find the smallest element in the unsorted portion of the array.




  • Iterate through the remaining elements (j = i to n - 1).


  • If a smaller element is found (arr[j] < arr[min]), update the index of the smallest element (min = j).




4. Swap: Swap the found minimum element with the first unsorted element.



Time Complexity: O(n²)





  • Explanation: The outer loop runs n - 2 i.e. n - 1 times and the inner loop runs up to n - 1 times, resulting in O(n²) for all (best, worst and average) cases.



Space Complexity: O(1)





  • Explanation: The algorithm sorts in place and uses a constant amount of extra space.






Example



Input: arr = [7, 5, 9, 2, 8], n = 5



Output: arr = [2, 5, 7, 8, 9]



Explanation: In each iteration, the smallest element from the unsorted portion of the array is selected and swapped with the first element of the unsorted portion. This process continues, reducing the unsorted portion of the array by one element each time, until the entire array is sorted.









Step-by-Step Explanation



Let's break down the steps for the example input arr = [7, 5, 9, 2, 8]:



1. Initial Array: [7, 5, 9, 2, 8]



2. Pass 1:




  • Array at the start of Pass 1:[7, 5, 9, 2, 8]


  • Find the minimum from index 0 to 4: 2


  • Swap 2 with the first element 7


  • Array after pass 1:[2, 5, 9, 7, 8]




3. Pass 2:




  • Array at the start of Pass 2:[2, 5, 9, 7, 8]


  • Find the minimum from index 1 to 4: 5


  • Swap 5 with itself (no change).


  • Array after pass 2:[2, 5, 9, 7, 8]




4. Pass 3:




  • Array at the start of Pass 3:[2, 5, 9, 7, 8]


  • Find the minimum from index 2 to 4: 7


  • Swap 7 with 9


  • Array after pass 3:[2, 5, 7, 9, 8]




5. Pass 4:




  • Array at the start of Pass 4:[2, 5, 7, 9, 8]


  • Find the minimum from index 3 to 4: 8


  • Swap 8 with 9


  • Array after pass 4:[2, 5, 7, 8, 9]




6. Final Sorted Array:[2, 5, 7, 8, 9]






Visualization



Selection Sort Algorithm Animation









Edge Cases




  • Already Sorted Array: The algorithm still performs O(n²) comparisons, making it inefficient for sorted inputs.


  • Array with Identical Elements: Handles duplicates correctly but doesn't provide any advantage over its time complexity.


  • Single Element Array: No swaps needed, the array remains unchanged.







Additional Notes




  • Inefficiency: Due to its O(n²) time complexity, Selection Sort is inefficient for large datasets compared to more advanced algorithms like Quick Sort or Merge Sort.


  • Stability: Selection Sort is not stable, meaning it may change the relative order of elements with equal keys.


  • Use Case: Useful for small datasets or when memory space is limited since it sorts in place with O(1) additional space.







Conclusion



Selection Sort is a fundamental sorting algorithm that provides a clear introduction to the concept of sorting. Although not suitable for large datasets due to its quadratic time complexity, it is easy to understand and implement, making it an excellent teaching tool for learning about algorithmic concepts. Its simplicity and in-place sorting capability are its main advantages.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - Selection Sort Algorithm
id: 73f66f72-14ee-4b6e-a760-86fc2799d4b2
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-26
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-26"
        description = "YARA Signature for "
    strings:
        $str = "Selection Sort Algorithm" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Selection Sort Algorithm")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Selection Sort Algorithm*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Selection Sort Algorithm"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Selection Sort Algorithm.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Selection Sort Algorithm

Thematisch verwandte Begriffe: Selection, Sort, Algorithm · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-88003 | InvoicePlane is a self-hosted open source application for managing invoi…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag