Skip to content

Refactor bubble sort for improved efficiency#15

Open
Akesh-28 wants to merge 1 commit intoRekhuGopal:mainfrom
Akesh-28:patch-1
Open

Refactor bubble sort for improved efficiency#15
Akesh-28 wants to merge 1 commit intoRekhuGopal:mainfrom
Akesh-28:patch-1

Conversation

@Akesh-28
Copy link

@Akesh-28 Akesh-28 commented Feb 1, 2026

Refactor bubble sort algorithm to improve efficiency by reducing the range of each pass based on the last swap position.

Refactor bubble sort algorithm to improve efficiency by reducing the range of each pass based on the last swap position.
@Akesh-28
Copy link
Author

Akesh-28 commented Feb 1, 2026

This is my first open-source contribution.
I would appreciate any feedback or suggestions for improvement.

new_n=0 # Stores the index of the last swap in this pass
for i in range(1,n):
if(arr[i-1]>arr[i]): # Check if adjacent elements are in wrong order
arr[i],arr[i-1]=arr[i-1],arr[i] #swap the elements

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants