SlideServe
Menu
Préférences
© SlideServe · v2026

Internal Sorting

gareth avatar
7 diapositives · 240 Views · Jul 24, 2014

This guide covers various sorting algorithms including Bubble Sort, Selection Sort, Quick Sort, and Insertion Sort, providing insights into their efficiencies and applications. Bubble Sort, while easy to implement, is inefficient at O(N²). Selection Sort is slightly better with less swapping, but still retains O(N²) complexity. Quick Sort is the fastest at O(N log N), albeit more complex to code. Additionally, we discuss sorting linked lists, highlighting their advantages when list sizes are unknown and comparing methods for both arrays and linked lists.

Internal Sorting - slide 1
01 / 7Internal Sorting
1 / 17

Télécharger la présentation

Internal Sorting
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Internal Sorting File Sorting Part 2

  2. Bubble Sort of an array Inefficient --- O ( N2 ) easy to code, hence unlikely to contain errors Algorithm for outerloop = 1 to N for innerloop = 0 to N-2 if ( item[innerloop] > item[innerloop+1] ) swap item[i] and item[i+1]

  3. Selection Sort of an array • Easy to code, less swapping than bubble, but still O ( N2 ) • Splits the array into 2 lists: • one sorted (which slowly grows) • one unsorted (which slowly shrinks) • Algorithm • find the smallest item in unsorted list • swap smallest with start of unsorted list • sorted_size ++; and unsorted_size --;

  4. Quick Sort of an array • Very Fast --- O ( N log2 N ) • A pain to program • Algorithm • recursively partition the array into sub-lists • sort infileoutfile …… it's magic !!! animations and comparisons at http://www.sorting-algorithms.com/

  5. Sorting a Linked List • Linked Lists are necessary when we don't know the size of the list • Sorting Operations for both arrays and linked lists • comparisons • arrays - need multiple indexes • LL - need multiple pointers • swaps • with big records, LL is easier: • just move a few pointers

  6. Insertion Sort of Linked List Oversimplified Algorithm: While not eof newptr = new record with data from file temp = head while (temp != NULL) if (newptr->key < temp->key) insert newptr before temp else temp = temp->next

  7. Ordered Binary Tree 40 20 60 10 30 70 Alternative to building Singly Linked List Inserting new node is much easier Traversal to find insertion is log2N So, inserting N items takes N * log2 N compares