100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Class notes

Sorting Algorithms

Rating
-
Sold
-
Pages
3
Uploaded on
14-01-2021
Written in
2020/2021

Lecture notes of 3 pages for the course Data Structures at Comsats Institute Of Information And Technology (Sorting Algorithms)

Institution
Course

Content preview

`1) Stage J (Journey)

Introduction
Bubble Sort

Bubble sort is a simple and well-known sorting algorithm. It is used in practice once in a blue
moon and its main application is to make an introduction to the sorting algorithms. Bubble
sort belongs to O(n2) sorting algorithms, which makes it quite inefficient for sorting large
data volumes. Bubble sort is stable and adaptive.

Algorithm

1. Compare each pair of adjacent elements from the beginning of an array and, if they
are in reversed order, swap them.
2. If at least one swap has been done, repeat step 1.

Insertion Sort

Insertion sort belongs to the O(n2) sorting algorithms. Unlike many sorting algorithms with
quadratic complexity, it is actually applied in practice for sorting small arrays of data. For
instance, it is used to improve quicksort routine. Some sources notice, that people use same
algorithm ordering items, for example, hand of cards.

Algorithm

Insertion sort algorithm somewhat resembles selection sort. Array is imaginary divided into
two parts - sorted one and unsorted one. At the beginning, sorted part contains first element
of the array and unsorted one contains the rest. At every step, algorithm takes first element in
the unsorted part and inserts it to the right place of the sorted one. When unsorted part
becomes empty, algorithm stops.

Selection Sort

Selection sort is one of the O(n2) sorting algorithms, which makes it quite inefficient for
sorting large data volumes. Selection sort is notable for its programming simplicity and it can
over perform other sorts in certain situations (see complexity analysis for more details).

Algorithm

The idea of algorithm is quite simple. Array is imaginary divided into two parts - sorted one
and unsorted one. At the beginning, sorted part is empty, while unsorted one contains whole
array. At every step, algorithm finds minimal element in the unsorted part and adds it to the
end of the sorted one. When unsorted part becomes empty, algorithm stops.

When algorithm sorts an array, it swaps first element of unsorted part with minimal element
and then it is included to the sorted part. This implementation of selection sort in not stable.


50

Written for

Institution
Course

Document information

Uploaded on
January 14, 2021
Number of pages
3
Written in
2020/2021
Type
Class notes
Professor(s)
Rashid mehmood
Contains
All classes

Subjects

$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
youtubecanvas

Get to know the seller

Seller avatar
youtubecanvas COMSATS Institute Of Information Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
5 year
Number of followers
0
Documents
18
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions