This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dilumdesilva
suggested changes
Oct 19, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pubudu-m good work!
But I see some space to improve this version of the algorithm. You can introduce a shouldSwap
sort of flag before entering the loop to skip unnecessary looping rounds as it increases the cost of your algorithm.
Ideally if shouldSwap
logic is true only you should get into the loop and do the swap.
Here's a pseudo-code for what I suggest
Store data set
IF data_set.count < 1
Return data_set
last_position <- data_set.count - 1
shouldSwap <- true
while shouldSwap = true
shouldSwap <= false
FOR i <- 0 to last position
IF data_set[i] > data set[i + 1]
temp <- data_set [i+ 1]
data_set[i + 1] = data_set[I]
data_set[i] <- temp
shouldSwap <- true
END IF
ENDFOR
ENDWHILE
Please give it a look and update your PR if it helps to improve your algorithm.
Thanks.
dilumdesilva
suggested changes
Oct 19, 2021
Hi @dilum1995 updated the PR. Please help to review. TIA! |
@pubudu-m once you update this please mark the conversations as resolved as well. |
dilumdesilva
suggested changes
Oct 19, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add bubble sort algorithm using Swift programming language #76
Please help to review. TIA!