Course Hero Logo

0 array 1 2 3 4 bubble sort example 73 42 11 58 5

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 79 - 100 out of 203 pages.

0array1234Bubble Sort Example734211585Spring 2022Sacramento State - Cook - CSc 13022Outer LoopInner Loop
0array1234Bubble Sort Example734258115Spring 2022Sacramento State - Cook - CSc 13023Outer LoopInner Loop
0array1234Bubble Sort Example731158425Spring 2022Sacramento State - Cook - CSc 13024Outer LoopInner Loop
0array1234Bubble Sort Example421158735Spring 2022Sacramento State - Cook - CSc 13025Outer LoopInner Loop
0array1234Bubble Sort Example421158735Spring 2022Sacramento State - Cook - CSc 13026Outer LoopInner Loop
0array1234Bubble Sort Example573584211Spring 2022Sacramento State - Cook - CSc 13027Outer LoopInner Loop
0array1234Bubble Sort Example542587311Spring 2022Sacramento State - Cook - CSc 13028Outer LoopInner Loop
0array1234Bubble Sort Example542581173Spring 2022Sacramento State - Cook - CSc 13029Outer LoopInner Loop
0array1234Bubble Sort Example511587342Spring 2022Sacramento State - Cook - CSc 13030Outer LoopInner Loop
0array1234Bubble Sort Example511427358Spring 2022Sacramento State - Cook - CSc 13031Outer LoopInner Loop
0array1234Bubble Sort Example511427358Spring 2022Sacramento State - Cook - CSc 13032Outer LoopInner Loop
The Bubble Sort isextremelyinefficient and onlygood for tiny arraysSince Bubble Sort uses two embedded loopsthe outer loop looks at allnitemsthe inner loop looks at basicallynitemsthe resulting algorithm getsexponentiallyless efficientasnincreasesEfficiency of the Bubble SortSpring 2022Sacramento State - Cook - CSc 13033
Efficiency of the Bubble SortSpring 2022Sacramento State - Cook - CSc 13034The Bubble SortO(n2)… two embedded loops thatare based onn… and all that swappingdoesn't help either!
Bubble SortTime AverageO(n2)Time BestO(n2)Time WorstO(n2)Auxiliary spaceO(1)StableYes – Equal element order preservedOnline?No – Entire array in useSpring 2022Sacramento State - Cook - CSc 13035Bubble Sort Summary
Selection SortThe Human Way
TheSelection Sortis a similarto the Bubble SortHowever…rather than "bubble up" smalleritems, it scans the entire arrayit finds the smallest elementonlythendoes it swap thevaluesSelection SortSpring 2022Sacramento State - Cook - CSc 13037
Like the Bubble Sort, it consists of two For Loops –one outer and one innerOuter loop runs from the first to the lastInner loop …starts at the position of the outer loopscans down and finds thesmallestvalueThen, after the scan, do a single swapSelection SortSpring 2022Sacramento State - Cook - CSc 13038
for(i= 0;i< count-1;i++){best=i;for(j=i;j< count;j++){if (array[j] < array[best]){best=j;}}//swap array[i] and array[best]}The Selection SortSpring 2022Sacramento State - Cook - CSc 13039
Selection Sort ExampleSpring 2022Sacramento State - Cook - CSc 130400array1234734211585Outer LoopInner Loop
Selection Sort Example: New BestSpring 2022Sacramento State - Cook - CSc 130410array1234734211585Outer LoopInner Loop

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 203 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Nonya
Tags
Array data structure

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture