Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 22

Teacher’s Name BISHWAJIT BANERJEE Class XII

& designation PGT (CS)


Subject Computer Science Time 35 min
Topic Sorting Techniques (Bubble Sort) Date 04-12-2013
What is sorting
Sorting is any process of arranging items
according to a certain sequence
In computer science, sorting is one of the most
extensively researched subjects because of the
need to speed up the operation on thousands or
millions of records during a search operation
We have studied selection sort technique in
previous class.
What is bubble Sort technique?
Comparing each pair of adjacent items
and swapping them if they are in the wrong
order. The pass through the list is repeated until
no swaps are needed, which indicates that the
list is sorted.
53 13 23 15 3 20
13 53 23 15 3 20
13 23 53 15 3 20
13 23 15 53 3 20
Remaining series to be sorted
Largest number
End position
13 23 15 3 53 20
-> First pass
53 13 23 15 3 20
-> First data item placed
13 53 23 15 3 20 at its desired position
-> Repeat the process
13 23 53 15 3 20 for rest the series

13 23 15 53 3 20

13 23 15 3 53 20

Total five comparisons and sweepings were done


To place one data item to its desired place among six
Data items
13 23 15 3 20 53

No sweeping shall be done as 13 is smaller than 23


13 23 15 3 20 53
13 15 23 3 20 53
13 15 3 23 20 53
Remaining series to be sorted
Second largest number
Second last position
13 15 3 23 20 53
-> Second pass
13 23 15 3 53 20
-> Second data item placed
13 23 15 3 20 53 at its desired position
-> Repeat the process
13 15 23 3 20 53 for rest the series

13 15 3 23 20 53

Total four comparisons and sweepings were done


To place one data item to its desired place among five
Data items
Recapitulation
Sorting is arranging data elements in either
ascending or descending order.

In selection sort technique one data vale is selected


at a time and sent it to its desired place and same
processes is repeated for rest of the data values.
In bubble sort technique; comparing each pair of
adjacent items and swapping them if they are in
the wrong order

Bubble sort technique need more write operations


as compare to selection sort technique.
Evaluation Tool/ Assessment
a) Which of the following describes sorting?

1. Accessing and procession each record exactly


once.
2. Finding a location of record with given key.
3. Arranging data (record) in some given order.
4. Adding a new record to data structure.
Evaluation Tool/ Assessment
b) What is the need of arranging data in
specific order?
1. It looks good when being read.
2. For quick and easy access to the desired
information.
3. It saves computer memory.
4. All of the above
Evaluation Tool/ Assessment
c) Why do we use arrays?
1. To handle bulk of similar kind of data.
2. For easy access to data value by sharing
same name.
3. Structured way of program.
4. All of the above.
Evaluation Tool/ Assessment
d) Which sorting technique uses comparison
with neighbouring element?
1. Selection sort
2. Bubble Sort
3. Insertion sort
4. None of the above
Evaluation Tool/ Assessment
e) What is the role of swap function in sorting
techniques?
1. To arrange data in specific order.
2. Just to interchange values of given variables.
3. To find highest value.
4. All of the above.
Evaluation Tool/ Assessment
f) Which sorting method needs more number of
write operations?
1. Selection sort
2. Bubble sort
3. Both have equal number of write operation.
4. This comparison is not valid.

You might also like