Sorting Algorithms: Selection and Insertion Sort Key Concepts and Code

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/8

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

9 Terms

1
New cards

An algorithm that sorts an array swaps _____.

two elements at a time

2
New cards

Which is sorted into ascending order?

Sally, Sam, Sandy, Samantha, Sal

Ral, Reece, Rita, Ryan

Don, Dan, Dale, Dana

Alan, Andy, Al, Adam

Ral, Reece, Rita, Ryan

3
New cards

Which of the following is not an example of sorting?

Arranging patient records alphabetically

Arranging employee details based on beginning dates

Arranging student records neatly on a desk

Arranging musical instruments based on the number of strings they have

Arranging student records neatly on a desk

4
New cards

In selection sort, the smallest element is selected and swapped with the _____ unsorted element.

leftmost

5
New cards

The array [67, 23, 32, 80, 53, 60] is to be sorted using selection sort. What is the order of the elements after the third swap?

23, 32, 53, 80, 67, 60

6
New cards

What statement must replace the XXX to complete the selection sort algorithm below?

void selectionSort(int[] numbers) { for (int i = 0; i < numbers.length - 1; i++) { int indexSmallest = i; for (int j = i + 1; j < numbers.length; j++) { if (numbers[j] < numbers[indexSmallest]) { indexSmallest = j; } } int temp = numbers[i]; XXX numbers[indexSmallest] = temp; } }

numbers[i] = numbers[indexSmallest];

7
New cards

Given the array [77, 75, 70, 50, 10], what is the order of the elements after completing insertion sort's second outer loop iteration?

70, 75, 77, 50, 10

8
New cards

What replaces XXX to complete the insertion sort algorithm?

for (int i = 1; i < numbers.length; i++) { int j = i; XXX { int temp = numbers[j]; numbers[j] = numbers[j - 1]; numbers[j - 1] = temp; j--; } }

while (j > 0 && numbers[j] < numbers[j - 1])

9
New cards

What is the SMALLEST number of swaps that insertion sort may perform when sorting 20 elements?

0