0% found this document useful (0 votes)
39 views6 pages

Bubble Sort (Best: O (N), Worst:O (N 2) ) : Sorting Techniques

The document describes 5 sorting techniques: Bubble Sort, Selection Sort, Insertion Sort, Quicksort, and Mergesort. Bubble Sort and Selection Sort have worst-case performance of O(N^2). Insertion Sort has best-case performance of O(N) but worst-case of O(N^2). Quicksort and Mergesort generally have better performance than the other techniques, with Quicksort having average performance of O(N lg N) and Mergesort having average and worst-case performance of O(n*log2n).

Uploaded by

Abdullah Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views6 pages

Bubble Sort (Best: O (N), Worst:O (N 2) ) : Sorting Techniques

The document describes 5 sorting techniques: Bubble Sort, Selection Sort, Insertion Sort, Quicksort, and Mergesort. Bubble Sort and Selection Sort have worst-case performance of O(N^2). Insertion Sort has best-case performance of O(N) but worst-case of O(N^2). Quicksort and Mergesort generally have better performance than the other techniques, with Quicksort having average performance of O(N lg N) and Mergesort having average and worst-case performance of O(n*log2n).

Uploaded by

Abdullah Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Sorting Techniques:

Bubble Sort [Best: O(n), Worst:O(N^2)]


The list is divided into two sublists: sorted and unsorted.

The smallest element is bubbled from the unsorted list and moved to the
sorted sublist.

After that, the wall moves one element ahead, increasing the number of
sorted elements and decreasing the number of unsorted ones.

Each time an element moves from the unsorted part to the sorted part one
sort pass is completed.

Given a list of n elements, bubble sort requires up to n-1 passes to sort the
data.
Selection Sort [Best/Worst: O(N^2)]

The list is divided into two sublists, sorted and unsorted,


which are divided by an imaginary wall.

We find the smallest element from the unsorted sublist and


swap it with the element at the beginning of the unsorted
data.

After each selection and swapping, the imaginary wall


between the two sublists move one element ahead,
increasing the number of sorted elements and decreasing
the number of unsorted ones.

Each time we move one element from the unsorted sublist to


the sorted sublist, we say that we have completed a sort
pass.

A list of n elements requires n-1 passes to completely


rearrange the data.

selection sort algorithm is appropriate only for small n.


Insertion Sort [Best: O(N), Worst:O(N^2)]

Insertion sort is a simple sorting algorithm that is


appropriate for small inputs.
Most common sorting technique used by card
players.
The list is divided into two parts: sorted and
unsorted.
In each pass, the first element of the unsorted part is
picked up, transferred to the sorted sublist, and
inserted at the appropriate place.
A list of n elements will take at most n-1 passes to
sort the data.
Quicksort [Best: O(N lg N), Avg: O(N lg N), Worst:O(N^2)]

It works as follows:
1. First, it partitions an array into two parts,
2. Then, it sorts the parts independently,
3. Finally, it combines the sorted subsequences by

a simple concatenation.

Mergesort [Best: O(N), Avg / Worst: O (n * log2n )]


It is a recursive algorithm.
Divides the list into halves,
Sort each halve separately, and
Then merge the sorted halves into one sorted
array.

You might also like