SlideShare a Scribd company logo
1 of 57
Algorithms in Java
Lesson 1: Bubble sort
2
Algorithms in Java
Bubble sort:
7 3 6 5 1 9 2 4 8
3
Algorithms in Java
Bubble sort:
[7] [3] 6 5 1 9 2 4 8
4
Algorithms in Java
Bubble sort:
[3] [7] 6 5 1 9 2 4 8
5
Algorithms in Java
Bubble sort:
3 [7] [6] 5 1 9 2 4 8
6
Algorithms in Java
Bubble sort:
3 [6] [7] 5 1 9 2 4 8
7
Algorithms in Java
Bubble sort:
3 6 [7] [5] 1 9 2 4 8
8
Algorithms in Java
Bubble sort:
3 6 [5] [7] 1 9 2 4 8
9
Algorithms in Java
Bubble sort:
3 6 5 [7] [1] 9 2 4 8
10
Algorithms in Java
Bubble sort:
3 6 5 [1] [7] 9 2 4 8
11
Algorithms in Java
Bubble sort:
3 6 5 1 [7] [9] 2 4 8
12
Algorithms in Java
Bubble sort:
3 6 5 1 7 [9] [2] 4 8
13
Algorithms in Java
Bubble sort:
3 6 5 1 7 [2] [9] 4 8
14
Algorithms in Java
Bubble sort:
3 6 5 1 7 2 [9] [4] 8
15
Algorithms in Java
Bubble sort:
3 6 5 1 7 2 [4] [9] 8
16
Algorithms in Java
Bubble sort:
3 6 5 1 7 2 4 [9] [8]
17
Algorithms in Java
Bubble sort:
3 6 5 1 7 2 4 [8] [9]
18
Algorithms in Java
Bubble sort:
3 6 5 1 7 2 4 8 9
The last element of the array is in the correct spot. Next cycle
will not include 9.
19
Algorithms in Java
Bubble sort:
[3] [6] 5 1 7 2 4 8 9
20
Algorithms in Java
Bubble sort:
3 [6] [5] 1 7 2 4 8 9
21
Algorithms in Java
Bubble sort:
3 [5] [6] 1 7 2 4 8 9
22
Algorithms in Java
Bubble sort:
3 5 [6] [1] 7 2 4 8 9
23
Algorithms in Java
Bubble sort:
3 5 [1] [6] 7 2 4 8 9
24
Algorithms in Java
Bubble sort:
3 5 1 [6] [7] 2 4 8 9
25
Algorithms in Java
Bubble sort:
3 5 1 6 [7] [2] 4 8 9
26
Algorithms in Java
Bubble sort:
3 5 1 6 [2] [7] 4 8 9
27
Algorithms in Java
Bubble sort:
3 5 1 6 2 [7] [4] 8 9
28
Algorithms in Java
Bubble sort:
3 5 1 6 2 [4] [7] 8 9
29
Algorithms in Java
Bubble sort:
3 5 1 6 2 4 [7] [8] 9
30
Algorithms in Java
Bubble sort:
3 5 1 6 2 4 7 8 9
Now 8 and 9 are in the correct spot. Next cycle will skip both
31
Algorithms in Java
Bubble sort:
[3] [5] 1 6 2 4 7 8 9
32
Algorithms in Java
Bubble sort:
3 [5] [1] 6 2 4 7 8 9
33
Algorithms in Java
Bubble sort:
3 [1] [5] 6 2 4 7 8 9
34
Algorithms in Java
Bubble sort:
3 1 [5] [6] 2 4 7 8 9
35
Algorithms in Java
Bubble sort:
3 1 5 [6] [2] 4 7 8 9
36
Algorithms in Java
Bubble sort:
3 1 5 [2] [6] 4 7 8 9
37
Algorithms in Java
Bubble sort:
3 1 5 2 [6] [4] 7 8 9
38
Algorithms in Java
Bubble sort:
3 1 5 2 [4] [6] 7 8 9
39
Algorithms in Java
Bubble sort:
3 1 5 2 4 [6] [7] 8 9
40
Algorithms in Java
Bubble sort:
3 1 5 2 4 6 7 8 9
Once again the last number has been put in the correct
location: next cycles will skip 7, 8 and 9
41
Algorithms in Java
Bubble sort:
[3] [1] 5 2 4 6 7 8 9
42
Algorithms in Java
Bubble sort:
[1] [3] 5 2 4 6 7 8 9
43
Algorithms in Java
Bubble sort:
1 [3] [5] 2 4 6 7 8 9
44
Algorithms in Java
Bubble sort:
1 3 [5] [2] 4 6 7 8 9
45
Algorithms in Java
Bubble sort:
1 3 [2] [5] 4 6 7 8 9
46
Algorithms in Java
Bubble sort:
1 3 2 [5] [4] 6 7 8 9
47
Algorithms in Java
Bubble sort:
1 3 2 [4] [5] 6 7 8 9
48
Algorithms in Java
Bubble sort:
1 3 2 4 [5] [6] 7 8 9
49
Algorithms in Java
Bubble sort:
1 3 2 4 5 6 7 8 9
Next cycle will skip 6, 7, 8 and 9
50
Algorithms in Java
Bubble sort:
[1] [3] 2 4 5 6 7 8 9
51
Algorithms in Java
Bubble sort:
1 [3] [2] 4 5 6 7 8 9
52
Algorithms in Java
Bubble sort:
1 [2] [3] 4 5 6 7 8 9
At this stage the array is ordered. However as the algorithm is
not aware of this, the remaining cycles will run anyway
53
Algorithms in Java
Bubble sort:
1 2 [3] [4] 5 6 7 8 9
54
Algorithms in Java
Bubble sort:
1 2 3 [4] [5] 6 7 8 9
55
Algorithms in Java
Bubble sort:
1 2 3 4 5 6 7 8 9
56
Algorithms in Java
Bubble sort:
[1] [2] 3 4 5 6 7 8 9
And so on...
57
Algorithms in Java
Bubble sort:
1) Bigger arrays take longer than smaller ones as this
algorithm runs in O(N2
), as N = number of elements of the
array
2) Extremely disordered arrays take longer than fairly ordered
ones as less swaps are necessary

More Related Content

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Algorithms In Java | Bubble Sort | Full Code Shown