Deck 12: Sorting Data
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/30
Play
Full screen (f)
Deck 12: Sorting Data
1
Sorting is often done on arrays because sorted array elements can be referenced in memory and moved around more easily.
True
2
Data in data structures, such as linked lists and binary trees, cannot be sorted.
False
3
A bubble sort is more efficient than a selection sort because only one swap is made in each pass.
False
4
When you swap the values of two variables or array elements, you need a third variable, a temporary one, to hold one of the values until the swap is completed.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
5
Sorting an array of data elements involves moving them around.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
6
On the first pass of a bubbles sort, when two adjacent elements are compared, if the one on the left has a greater value than the one on the right, they are swapped.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
7
You can make an ascending bubble sort move the smallest value to the leftmost location first, and then work toward the right of the array.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
8
The programming logic for a bubble sort requires two loops: an outer loop for each pass through the array and an inner loop to compare elements during a pass.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
9
When you are sorting in descending order, use the greater than operator (>) in the comparison to swap adjacent elements if the first element is greater than the second.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
10
To sort in ascending order, use the less than operator (<) to swap elements if the first element is less than the second.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
11
A bubble sort requires passes through an array, but it makes one fewer pass than the number of array elements.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
12
When sorting a selection sort in ascending order, the array is scanned for the smallest value on the first pass, and when its position is determined, it is swapped with the element at subscript [0].
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
13
The insertion sort algorithm builds a sorted array one element at a time.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
14
All sorting algorithms use an outer For loop to go through an array.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
15
The selection sort uses a nested While loop to compare and swap elements because an element is not placed until its correct position is determined.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
16
The sort() method arranges array elements in descending order.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
17
In JavaScript, lexigraphical sorting treats numbers as characters.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
18
An optional argument called a function reference can be used with the sort() method; it bases the sorting order of any two array elements on the value the function returns.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
19
Putting data items in order is called ____.
A) swapping
B) batch processing
C) sorting
D) data hiding
A) swapping
B) batch processing
C) sorting
D) data hiding
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
20
A(n) ____ is the most straightforward sorting algorithm but often the least efficient.
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
21
A(n) ____ involves comparing adjacent elements and swapping them, if needed, until all elements are in their correct positions.
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
22
A(n) ____ finds which element belongs in a particular position on each pass through the array and moves it there.
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) ____ builds a sorted array by determining where each element should be in the sorted part of the array and inserting it in that position while moving all other sorted elements over one position.
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
A) selection sort
B) bubble sort
C) insertion sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
24
A sorting algorithm can involve switching the places of two elements being compared, a process called ____.
A) swapping
B) data hiding
C) batch processing
D) sorting
A) swapping
B) data hiding
C) batch processing
D) sorting
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following swaps the values of someNums[0] and someNums[1], which currently contain the values 8 and 3, respectively?
A) someNums[0] = someNums[1]
SomeNums[1] = someNums[0]
B) temp = someNums[0]
SomeNums[0] = someNums[1]
C) temp = someNums[0]
SomeNums[0] = someNums[1]
SomeNums[1] = temp
D) someNums[0] = someNums[1]
SomeNums[1] = someNums[0]
SomeNums[1] = temp
A) someNums[0] = someNums[1]
SomeNums[1] = someNums[0]
B) temp = someNums[0]
SomeNums[0] = someNums[1]
C) temp = someNums[0]
SomeNums[0] = someNums[1]
SomeNums[1] = temp
D) someNums[0] = someNums[1]
SomeNums[1] = someNums[0]
SomeNums[1] = temp
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
26
In a(n) ____, the number of comparisons made in each pass is one less than the number of elements remaining to be sorted because an element must be compared with the element next to it.
A) selection sort
B) heap sort
C) bubble sort
D) insertion sort
A) selection sort
B) heap sort
C) bubble sort
D) insertion sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
27
The following algorithm represents the logic of a(n) ____.
For maxElement = ARRAYSIZE - 1 To 1 Step - 1
For index = 0 To maxElement - 1
If someNums[index] > someNums[index + 1] Then
Temp = someNums[index]
SomeNums[index] = someNums[index + 1]
SomeNums[index + 1] = temp
End If
End For
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
For maxElement = ARRAYSIZE - 1 To 1 Step - 1
For index = 0 To maxElement - 1
If someNums[index] > someNums[index + 1] Then
Temp = someNums[index]
SomeNums[index] = someNums[index + 1]
SomeNums[index + 1] = temp
End If
End For
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
28
The following algorithm represents the logic of a(n) ____.
// Outer loop designates a position
// from first to last element
For currEl = 0 To ARRAYSIZE - 1
MinValue = someNums[currEl]
MinPosition = currEl
// Inner loop steps through array,
// finding smallest value
For index = currEl + 1 To ARRAYSIZE - 1
If someNums[index] < minValue Then
MinValue = someNums[index]
MinPosition = index
End If
End For
// Swap minimum value with element at
// designated position if different
If minPosition != currEl Then
Temp = someNums[currEl]
SomeNums[currEl] = someNums[minPosition]
SomeNums[minPosition] = temp
End If
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
// Outer loop designates a position
// from first to last element
For currEl = 0 To ARRAYSIZE - 1
MinValue = someNums[currEl]
MinPosition = currEl
// Inner loop steps through array,
// finding smallest value
For index = currEl + 1 To ARRAYSIZE - 1
If someNums[index] < minValue Then
MinValue = someNums[index]
MinPosition = index
End If
End For
// Swap minimum value with element at
// designated position if different
If minPosition != currEl Then
Temp = someNums[currEl]
SomeNums[currEl] = someNums[minPosition]
SomeNums[minPosition] = temp
End If
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
29
The following algorithm represents the logic of a(n) ____.
// Loop pulls each element from 1 to the end of the array
For pulledIndex = 1 to ARRAYSIZE - 1
PulledValue = someNums[pulledIndex]
InsertIndex = pulledIndex
// If element to the left is greater,
// shift it to the right
// and look at the next element to the left
While insertIndex > 0
And someNums[insertIndex - 1] > pulledValue
SomeNums[insertIndex] = someNums[insertIndex - 1]
InsertIndex = insertIndex - 1
End While
// Insert the pulled value when the shifting ends
SomeNums[insertIndex] = pulledValue
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
// Loop pulls each element from 1 to the end of the array
For pulledIndex = 1 to ARRAYSIZE - 1
PulledValue = someNums[pulledIndex]
InsertIndex = pulledIndex
// If element to the left is greater,
// shift it to the right
// and look at the next element to the left
While insertIndex > 0
And someNums[insertIndex - 1] > pulledValue
SomeNums[insertIndex] = someNums[insertIndex - 1]
InsertIndex = insertIndex - 1
End While
// Insert the pulled value when the shifting ends
SomeNums[insertIndex] = pulledValue
End For
A) selection sort
B) insertion sort
C) bubble sort
D) merge sort
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
30
To reverse the order of array elements, you use the JavaScript method ____.
A) reverse()
B) reverse.sort()
C) sort.reverse()
D) reverseSort()
A) reverse()
B) reverse.sort()
C) sort.reverse()
D) reverseSort()
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck