Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT 4043 Data Structures and Algorithms

Similar presentations


Presentation on theme: "IT 4043 Data Structures and Algorithms"— Presentation transcript:

1 IT 4043 Data Structures and Algorithms
Budditha Hettige Department of Computer Science

2 Sorting Syllabus Algorithms Analysis Introduction to DSA
Abstract Data Types Arrays List Operation Using Arrays Recursion Stacks Queues Link List Sorting Algorithms Analysis

3 Sorting Sorting is so important and potentially so time consuming,
It has been the subject of extensive research in computer science Algorithms for sorting The bubble sort, The selection sort, The insertion sort The Quick sort The Shell Sort

4 Example Before After

5 Bubble Sort Bubble sort is a simple sorting algorithm
Compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no waps are needed, which indicates that the list is sorted. Here are the rules you’re following: 1. Compare two items 2. If the one on the left is taller, swap them. 3. Move one position right.

6 Example

7 Algorithms

8 Example

9 Efficiency of the Bubble Sort

10 Java Application

11 Selection Sort The selection sort improves on the bubble sort by reducing the number of swaps necessary from O(N2) to O(N). Unfortunately, the number of comparisons remains O(N2).

12 Example

13 Algorithms

14 Example

15 Efficiency of the Selection Sort

16 Insertion Sort Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

17 Example

18 Insertion sort

19 Example

20 Efficiency of the Selection Sort

21 Quick Sort

22 Algorithm

23 Shell Sort

24 Questions Identify which of the following is/are true? In each case justify your answer. In bubble sort and selection sort give O(N2) for the worst case. Quick sort is more efficacious than the bubble sort. Consider the following array with 10 elements. Apply “Bubble sort and selection sort” algorithm to sort this list. List = [45,82, 25, 94, 50, 60, 78, 32, 80, 93]; Implement the bubble sort algorithm and implement a Java program to sort and print 10 integer values


Download ppt "IT 4043 Data Structures and Algorithms"

Similar presentations


Ads by Google