Difference between revisions of "Interview Preparation Bubble Sort"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Created page with "I think this ia a simplest sorting algorithm for implementation. Algorithm for placing an array of elements n in an ascending order is listed below, a. Begin from the first...")
(No difference)

Revision as of 12:03, 25 November 2016

I think this ia a simplest sorting algorithm for implementation. Algorithm for placing an array of elements n in an ascending order is listed below, a. Begin from the first element and start comparing two elements. b. If the element at smaller index is greater swap the element. c. Increment the index by one and repeat step 2 for n-1 iteration. d. Repeat step b and C for n-1 times.

Similar algorithm can be framed for placing elements in descending order with minute changes.

For an array with n number of elements. Worst case complexity = О(n^2) and average complexity = О(n^2).