Sorting algorithms

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/20

flashcard set

Earn XP

Description and Tags

These flashcards cover key concepts surrounding elementary sorts, including selection sort, insertion sort, and various principles in sorting algorithms.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards

What is the purpose of sorting algorithms?

To rearrange an array of items in a particular order, usually ascending.

2
New cards

What are the two basic types of elementary sorting algorithms discussed?

Selection sort and insertion sort.

3
New cards

What is a key characteristic of a total order in sorting?

It must satisfy antisymmetry, transitivity, and totality.

4
New cards

How does selection sort operate?

It iteratively finds the minimum element from the unsorted part and swaps it with the first unsorted element.

5
New cards

In insertion sort, what does each iteration aim to do?

It moves the current element to its correct position among previously sorted elements.

6
New cards

Define 'inversion' in the context of sorting.

A pair of keys that are out of order.

7
New cards

What is the time complexity of selection sort in the average case?

O(n^2).

8
New cards

Why is insertion sort faster than selection sort on average for small datasets?

Because it makes fewer comparisons and moves elements only when necessary.

9
New cards

What type of array does insertion sort run in linear time on?

Partially sorted arrays.

10
New cards

What is a comparator?

An object that defines a sort order for sorting algorithms.

11
New cards

What characteristic makes insertion sort a stable sorting algorithm?

Equal items do not move past each other during sorting.

12
New cards

Why is selection sort not considered stable?

It can move equal items past one another due to long-distance exchanges.

13
New cards

What improvement does shuffle sort provide?

It generates a uniformly random permutation of the array.

14
New cards

What is the Java method to access the compareTo function in a Comparable object?

You invoke the compareTo method defined in the Comparable interface.

15
New cards

How can sorting algorithms be adapted to different data types in Java?

By using generics and Comparator interfaces.

16
New cards

What is the outcome of applying the compare() method in a Comparator?

It should return a negative integer, zero, or a positive integer based on the comparison of two objects.

17
New cards

What does it mean for a sort to be 'stable'?

It preserves the relative order of records with equal keys.

18
New cards

Which sorting method is demonstrated to involve shifting items instead of exchanging them?

Binary insertion sort.

19
New cards

How can you sort music by different criteria such as artist or song name?

By implementing comparators that define the desired sort order.

20
New cards

What is a common application of sorting algorithms in real life?

Sorting student records by name or section.

21
New cards

What is a key property that a usable comparator must fulfill?

It must enforce a total order on the items being compared.