SlideShare a Scribd company logo
1 of 24
Download to read offline
IT 4043
Data Structures and Algorithms
Budditha Hettige
Department of Computer Science
1
Syllabus
• Introduction to DSA
• Abstract Data Types
• Arrays
• List Operation Using Arrays
• Recursion
• Stacks
• Queues
• Link List
•Sorting
• Algorithms Analysis
2
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
3
Example
• Before
• After
4
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.
5
Example
6
Algorithms
7
Example
8
Efficiency of the Bubble Sort
9
Java Application
10
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).
11
Example
12
Algorithms
13
Example
14
Efficiency of the Selection Sort
15
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.
16
Example
17
Insertion sort
18
Example
19
Efficiency of the Selection Sort
20
Quick Sort
21
Algorithm
22
Shell Sort
23
Questions
24
1. Identify which of the following is/are true? In each
case justify your answer.
1. In bubble sort and selection sort give O(N2) for the
worst case.
2. Quick sort is more efficacious than the bubble sort.
2. 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];
3. Implement the bubble sort algorithm and
implement a Java program to sort and print 10
integer values

More Related Content

What's hot

What's hot (20)

Queue ppt
Queue pptQueue ppt
Queue ppt
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
 
Queues
QueuesQueues
Queues
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
stack & queue
stack & queuestack & queue
stack & queue
 
Data structures
Data structuresData structures
Data structures
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Queues
QueuesQueues
Queues
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
Queue
QueueQueue
Queue
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 

Similar to Sorting

SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
 
Sorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxSorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxKalpana Mohan
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge SortGelo Maribbay
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-leSumedha
 
It elective cs366-barizo-shell
It elective cs366-barizo-shellIt elective cs366-barizo-shell
It elective cs366-barizo-shellChristianBarizo
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithmstechnologygyan
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsFerdin Joe John Joseph PhD
 
Radix and Shell sort
Radix and Shell sortRadix and Shell sort
Radix and Shell sorthannatamayao
 
Designing Algorithms using Divide and Conquer Approach
Designing Algorithms using Divide and Conquer ApproachDesigning Algorithms using Divide and Conquer Approach
Designing Algorithms using Divide and Conquer ApproachZain Ul Abiden
 

Similar to Sorting (20)

SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Sorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptxSorting Techniques for Data Structures.pptx
Sorting Techniques for Data Structures.pptx
 
Radix and Merge Sort
Radix and Merge SortRadix and Merge Sort
Radix and Merge Sort
 
Sorting.pptx
Sorting.pptxSorting.pptx
Sorting.pptx
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-le
 
Shellshort ppt
Shellshort pptShellshort ppt
Shellshort ppt
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
It elective cs366-barizo-shell
It elective cs366-barizo-shellIt elective cs366-barizo-shell
It elective cs366-barizo-shell
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
sorting_part1.ppt
sorting_part1.pptsorting_part1.ppt
sorting_part1.ppt
 
SearchAlgorithm.pdf
SearchAlgorithm.pdfSearchAlgorithm.pdf
SearchAlgorithm.pdf
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
 
daa unit 1.pptx
daa unit 1.pptxdaa unit 1.pptx
daa unit 1.pptx
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Radix and Shell sort
Radix and Shell sortRadix and Shell sort
Radix and Shell sort
 
Designing Algorithms using Divide and Conquer Approach
Designing Algorithms using Divide and Conquer ApproachDesigning Algorithms using Divide and Conquer Approach
Designing Algorithms using Divide and Conquer Approach
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 

More from Budditha Hettige

Graphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksGraphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksBudditha Hettige
 
Introduction to Computer Graphics
Introduction to Computer GraphicsIntroduction to Computer Graphics
Introduction to Computer GraphicsBudditha Hettige
 
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentalsComputer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentalsBudditha Hettige
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryBudditha Hettige
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryBudditha Hettige
 
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressingComputer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressingBudditha Hettige
 
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performanceComputer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performanceBudditha Hettige
 
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technologyComputer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technologyBudditha Hettige
 
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architectureComputer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architectureBudditha Hettige
 
Computer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 2: HistoryComputer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 2: HistoryBudditha Hettige
 
Computer System Architecture Lecture Note 1: introduction
Computer System Architecture Lecture Note 1: introductionComputer System Architecture Lecture Note 1: introduction
Computer System Architecture Lecture Note 1: introductionBudditha Hettige
 
Computer System Architecture Lecture Note 4: intel microprocessors
Computer System Architecture Lecture Note 4: intel microprocessorsComputer System Architecture Lecture Note 4: intel microprocessors
Computer System Architecture Lecture Note 4: intel microprocessorsBudditha Hettige
 

More from Budditha Hettige (19)

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Drawing Fonts
Drawing FontsDrawing Fonts
Drawing Fonts
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
 
Lighting
LightingLighting
Lighting
 
Viewing
ViewingViewing
Viewing
 
OpenGL 3D Drawing
OpenGL 3D DrawingOpenGL 3D Drawing
OpenGL 3D Drawing
 
2D Drawing
2D Drawing2D Drawing
2D Drawing
 
Graphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::BlocksGraphics Programming OpenGL & GLUT in Code::Blocks
Graphics Programming OpenGL & GLUT in Code::Blocks
 
Introduction to Computer Graphics
Introduction to Computer GraphicsIntroduction to Computer Graphics
Introduction to Computer Graphics
 
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentalsComputer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 9 IO fundamentals
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
 
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressingComputer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 7 addressing
 
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performanceComputer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 6: hardware performance
 
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technologyComputer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 5: microprocessor technology
 
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architectureComputer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 3: computer architecture
 
Computer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 2: HistoryComputer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 2: History
 
Computer System Architecture Lecture Note 1: introduction
Computer System Architecture Lecture Note 1: introductionComputer System Architecture Lecture Note 1: introduction
Computer System Architecture Lecture Note 1: introduction
 
Computer System Architecture Lecture Note 4: intel microprocessors
Computer System Architecture Lecture Note 4: intel microprocessorsComputer System Architecture Lecture Note 4: intel microprocessors
Computer System Architecture Lecture Note 4: intel microprocessors
 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

Sorting

  • 1. IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1
  • 2. Syllabus • Introduction to DSA • Abstract Data Types • Arrays • List Operation Using Arrays • Recursion • Stacks • Queues • Link List •Sorting • Algorithms Analysis 2
  • 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 3
  • 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. 5
  • 9. Efficiency of the Bubble Sort 9
  • 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). 11
  • 15. Efficiency of the Selection Sort 15
  • 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. 16
  • 20. Efficiency of the Selection Sort 20
  • 24. Questions 24 1. Identify which of the following is/are true? In each case justify your answer. 1. In bubble sort and selection sort give O(N2) for the worst case. 2. Quick sort is more efficacious than the bubble sort. 2. 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]; 3. Implement the bubble sort algorithm and implement a Java program to sort and print 10 integer values