0% found this document useful (0 votes)
7 views12 pages

Dictionary and Sorting

hi

Uploaded by

dipanshuporas4
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)
7 views12 pages

Dictionary and Sorting

hi

Uploaded by

dipanshuporas4
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/ 12

INTRODUCTION

TO SORTING
• Generally, sorting means to
categorize the objects as per their
groups.
• A Computer system needs to work
with different tyes of elements and
sorting means to arrange these
elements in an order.
• Order of sorting can be ascending or
descending.
• In this chapter we will study sorting
in details and will see two sorting
techniques-
1. Bubble Sort
2. Insertion Sort
What is Sorting
• “In computer, sorting means to arrange elements in
an order, order can be ascending or descending”.
• Consider the following sequence -
Seq = [6,8,9,1,3,4]
Its new sequence arranged in ascending order will
be- Seq = [1,3,4,6,8,9 ]
And its new sequence arranged in descending order
will be- Seq = [9,8,6,4,3,1]
• There are various techniques of sorting like-
Selection Sort, Bubble Sort, Insertion Sort, Heap Sort,
Quick Sort etc.
• Only two sorting techniques are in our syllabus-
• Bubble sort
• Insertion sort
Bubble Sort
• In Bubble Sort, we compare two adjacent elements and if the
elements are not in correct order then these elements got
exchanged. After every pass the biggest element secures its
correct position.

OUTPUT:

OUTPUT:
Insertion Sort
• In insertion Sort, firstly two first values gets in order.
• We call it as sub-sequence which will be sorted.
• From rest of the unsorted sequence, values will be taken one by
one and will be inserted at right position in sorted sub-sequence.
• This process will be continued until we get the ordered sequence. |

OUTPUT:
Usage of Bubble Sort and Insertion
Sort

• Bubble sort is considered as a very simple and easy


sorting
algorithm but it is not considered as a very efficient
algorithm.
• For a small database, insertion sort is better than
bubble sort.
• For the sorting of a file stored in a tape, bubble sort is
better because in a tape, data is stored in sequential
format.
• Insertion sort is usually used to sort small
databases. When the database is almost sorted then
this technique work faster as not much memory is
needed.
• In small sequences, less number of swapping is there
in insertion sort as compared to bubble sort.

You might also like