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

• 203

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 arraysï‚§Since Bubble Sort uses two embedded loopsâ€¢the outer loop looks at allnitemsâ€¢the inner loop looks at basicallynitemsâ€¢the resulting algorithm getsexponentiallyless efficientasnincreasesEfficiency of the Bubble SortSpring 2022Sacramento State - Cook - CSc 13033
Efficiency of the Bubble SortSpring 2022Sacramento State - Cook - CSc 13034ï‚§The 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 Sortï‚§Howeverâ€¦â€¢rather than "bubble up" smalleritems, it scans the entire arrayâ€¢it finds the smallest elementâ€¢onlythendoes it swap thevaluesSelection SortSpring 2022Sacramento State - Cook - CSc 13037
ï‚§Like the Bubble Sort, it consists of two For Loops â€“one outer and one innerï‚§Outer loop runs from the first to the lastï‚§Inner loop â€¦â€¢starts at the position of the outer loopâ€¢scans down and finds thesmallestvalueï‚§Then, 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

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 203 pages?

Course Hero member to access this document

Term
Fall
Professor
Nonya
Tags
Array data structure