Find the smallest element in the unsorted portion. 2. Swap it with the first element of the unsorted portion. 3. Repeat for the remaining unsorted portion.
Flip to see [answer/question]
Flip to see [answer/question]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Flip
Revise later
SpaceTo flip
If confident
All Flashcards
What are the general steps of Selection Sort?
Find the smallest element in the unsorted portion. 2. Swap it with the first element of the unsorted portion. 3. Repeat for the remaining unsorted portion.
What are the general steps of Insertion Sort?
Assume the first element is sorted. 2. Take the next element and insert it into the correct position in the sorted portion. 3. Repeat for all remaining elements.
What are the steps to check if an ArrayList is sorted?
Iterate through the list. 2. Compare each element with the next. 3. If any element is greater than the next, the list is not sorted.
Steps of Selection Sort (detailed)
Find the minimum element in the unsorted array. 2. Swap the found minimum element with the first element of the unsorted array. 3. Move to the next element in the unsorted array. 4. Repeat until the array is sorted.
Steps of Insertion Sort (detailed)
Iterate from the second element to the end of the array. 2. For each element, compare it with the elements before it. 3. Shift the elements greater than the current element to one position ahead of their current position. 4. Insert the current element in the correct position.
Steps to determine if an ArrayList is sorted (detailed)
Start from the first element of the ArrayList. 2. Compare each element with the next element in the ArrayList. 3. If any element is greater than the next element, return false. 4. If the end of the ArrayList is reached, return true.
What is the first step in Selection Sort?
Find the smallest element in the unsorted portion.
What is the first step in Insertion Sort?
Assume the first element is sorted.
What is the first step to check if an ArrayList is sorted?
Iterate through the list.
What is the last step in Selection Sort?
Repeat for the remaining unsorted portion.
What is the core idea behind Selection Sort?
Repeatedly selecting the smallest element and moving it to the sorted portion.
What is the core idea behind Insertion Sort?
Building a sorted subarray by inserting elements from the unsorted portion into their correct positions.
How do you determine if an ArrayList is sorted?
Iterate through the list, checking if each element is less than or equal to the next.
What is the purpose of sorting algorithms?
To arrange elements in a specific order, typically ascending or descending, for easier searching and data retrieval.
What is the significance of run-time comparisons?
They help in understanding the efficiency of different algorithms and choosing the best one for a specific task.
What are the two subarrays in Selection Sort?
Sorted subarray and unsorted subarray.
What are the two subarrays in Insertion Sort?
Sorted subarray and unsorted subarray.
Why is it important to check if an ArrayList is sorted?
To ensure data integrity and efficiency in search and retrieval operations.
What is the main goal of comparing sorting algorithms?
To understand their relative efficiency and choose the best one for a given situation.
What is the role of swapping in sorting algorithms?
To rearrange elements in the correct order.
What is Selection Sort?
A sorting algorithm that divides the list into sorted and unsorted subarrays, repeatedly finding the minimum element from the unsorted subarray and placing it at the beginning.
What is Insertion Sort?
A sorting algorithm that builds the final sorted array one item at a time by repeatedly inserting elements from the unsorted portion into the correct position in the sorted portion.
What is an ArrayList?
A resizable array implementation of the List interface.
What is a sorted array?
An array where elements are arranged in a specific order (ascending or descending).
What is a subarray?
A contiguous part of an array.
What is ascending order?
Arrangement from smallest to largest.
What is descending order?
Arrangement from largest to smallest.
What is swapping?
Exchanging the positions of two elements in an array.
What is an algorithm?
A step-by-step procedure for solving a problem.
What is run-time comparison?
Evaluating the efficiency of algorithms by counting statement executions.