Algorithms and Data Structures in Python: Bubble Sort and its Optimization

Introduction

Sorting is one of the most basic algorithm types and it appears quite often in interview. Among them, bubble sort is probably the most fundamental one. The naive bubble sort is usually not that efficient, however, it’s important to understand how it works and how it can be optimized.

Naive Bubble Sort

Native bubble sort used a nested loop to iterate through the target array, and swap each pair of adjacent elements if…

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

what do @Insert, @Update, @Delete, or @Query do

Python & MBA — Financial Sensitivity Study with Excel formula and Python

KYVE TESTNET!

Windows Like a Mac (for developers)

Local K3s Cluster Made Easy With Multipass

From start-up to scale-up

Secure Pub/Sub With NATS

How to Deploy a Python App to Heroku in Under 5 Minutes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yue

Yue

More from Medium

Leetcode 1886. Determine Whether Matrix Can Be Obtained By Rotation

image.png

LeetCode #167 | Two Sum II — Input Array Is Sorted (Python)

Segment Tree — Unravelled

LeetCode 11. Container With Most Water — Python Solution