Dictionary and Sorting
Dictionary and Sorting
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