0% found this document useful (0 votes)
29 views10 pages

Presentatioin 1

Sorting algorithms like bubble sort, insertion sort, quicksort, and mergesort can be used to sort data into ascending or descending order. Internal sorting sorts data within the program's memory, while external sorting handles large datasets that exceed available memory. Bubble sort compares adjacent elements and swaps them if out of order, but is inefficient with a runtime of O(n^2). Quicksort and mergesort are generally faster algorithms with better runtimes. Mergesort splits the list into halves recursively until single elements remain, then merges the sorted halves back together.

Uploaded by

Saurabh Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Presentatioin 1

Sorting algorithms like bubble sort, insertion sort, quicksort, and mergesort can be used to sort data into ascending or descending order. Internal sorting sorts data within the program's memory, while external sorting handles large datasets that exceed available memory. Bubble sort compares adjacent elements and swaps them if out of order, but is inefficient with a runtime of O(n^2). Quicksort and mergesort are generally faster algorithms with better runtimes. Mergesort splits the list into halves recursively until single elements remain, then merges the sorted halves back together.

Uploaded by

Saurabh Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Data Structures Sorting

Sorting – Bubble, Insertion,


Quicksort, Mergesort,Selection
sorting.
Sorting
 Sorting is a process by which we can
maintain the data list in some order
 We can sort this list either ascending or descending.

 Type of Sorting : 1. Internal Sorting.


2. External Sorting.
Sorting
 Bubble sort: In that sorting compression is
between the two elements.
 These techniques are usually slow (O(n2))

 But, they are easier to understand.

 You will have to understand the more


complex schemes eventually. There is no
escape.
Insertion Sort
 There are two kinds of insertion sort:
 Insert in-order into a new list
 Reposition into our existing array
Insertion Sort
Bubble Sort
 Has a good name.
 Easy to understand.
 Slow and crusty.
 What is its efficiency?
Sorts
 Ok, now that I’ve filled your head with the
basics. Do you want to know the ultimate,
mega-powered, best sort ever?

 Me too. I like quicksort though.

 Too many variables apply:


 List contents
 Pre-sortedness
 Etc.
Mergesort
 Mergesort takes two
(or more) inputs and
sorts them!
 But how?
 By insertion!
 Uh oh… everyone
has to get up now.
Quicksort
 The “Bad Boy” of sorts.
 This is recursive too.
 Again, everyone needs to get up.
 Hey…. These slides are pretty empty. But,
you get to code this stuff!
Sort Analysis
 Well, first we need to explain more structurally
how these work:
 Mergesort:
 Split up a list into smaller parts (half size) until the list
is of size 1.
 Put lists back together by “merging”: insertion sort
 Quicksort:
 Select a value and ensure that all values to the left
are smaller – all values to the right are equal or larger
 Repeat with left/right side until they are of size 1 or 2
(and sorted).

You might also like