Deck 18: Searching and Sorting Algorithms

ملء الشاشة (f)
exit full mode
سؤال
Consider the following list:int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search for 75, after the first comparison, the search is restricted to ____.

A) list[0]...list[6]
B) list[0]...list[7]
C) list[5]...list[11]
D) list[6]...list[11]
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
The selection sort algorithm finds the location of the smallest element in the unsorted portion of the list.
سؤال
A sequential search of an n-element list takes ____ key comparisons if the item is not in the list.

A) 0
B) n/2
C) n
D) n2
سؤال
The binary search algorithm can be written iteratively or recursively.
سؤال
In a bubble sort, the smaller elements move toward the bottom, and the larger elements move toward the top of the list.
سؤال
With the binary search algorithm, ____ key comparison(s) is/are made in the successful case-the last time through the loop.

A) one
B) two
C) n-2
D) n
سؤال
The sequential search algorithm does not require that the list be sorted.
سؤال
In a binary search, first, the search item is compared with the last element of the list.
سؤال
The swap function of quick sort is written differently from the swap function for selection sort.
سؤال
In the average case, sequential search typically searches ____.

A) one quarter of the list
B) one third of the list
C) one half of the list
D) the entire list
سؤال
The formula to find the index of the middle element of a list is ____.

A) (mid + last)/2
B) (first + last) - 2
C) (first + last) / 2
D) (first + mid ) * 2
سؤال
Assume that list consists of the following elements.What is the result after bubble sort completes? int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16};

A) 89 73 56 46 34 25 16 10 5 2
B) 2 56 34 25 5 16 89 46 73
C) 2 5 10 16 25 34 46 56 73 89
D) 2 10 16 25 34 46 56 73 89
سؤال
In a bubble sort for list of length n, the first step is to compare elements ____.

A) list[0] and list[n]
B) list[0] and list[n-1]
C) list[0] and list[1]
D) list[n-1] and list[n+1]
سؤال
Consider the following list:int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search, the target is first compared with ____.

A) 4
B) 25
C) 39
D) 95
سؤال
The sequential search algorithm uses a(n) ____ variable to track whether the item is found.

A) int
B) bool
C) char
D) double
سؤال
In the bubble sort algorithm, the following code accomplishes swapping values in elements at positions index and index + 1.

A) list[index] = list[index + 1]
List[index + 1] = list[index]
B) list[index + 1] = list[index]
List[index] = list[index + 1]
C) list[index] = temp;
List[index] = list[index + 1];
Temp = list[index + 1];
D) temp = list[index];
List[index] = list[index + 1];
List[index + 1] = temp;
سؤال
Suppose that L is a sorted list of size 1024, and we want to determine whether an item x is in L.From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.
سؤال
During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.
سؤال
A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list.

A) 0
B) n/2
C) n
D) n2
سؤال
If n = 1000, then to sort the list, selection sort makes about 50,000 key comparisons.
سؤال
With insertion sort, the variable firstOutOfOrder is initialized to ____, assuming n is the length of the list.

A) 0
B) 1
C) n - 1
D) n
سؤال
The top node of a comparison tree is call the ____________________ node.
سؤال
For a list of length n, selection sort makes ____ item assignments.

A) n(n - 1)/2
B) 3(n - 1)
C) 3(n)
D) 4(n + 1)
سؤال
____ sort requires knowing where the middle element of the list is.

A) Merge
B) Bubble
C) Insertion
D) Selection
سؤال
A comparison tree is a(n) ____________________ tree.
سؤال
Assuming the following list declaration, which element is at the position 0 after the first iteration of selection sort? int list[] = {16, 30, 24, 7, 62, 45, 5, 55}

A) 5
B) 7
C) 16
D) 62
سؤال
The first step in the quick sort partition algorithm is to determine the ____________________ and swap it with the first element in the list.
سؤال
When moving array values for insertion sort, to move list[4] into list[2], first ____.

A) move list[2] to list[3]
B) delete list[2]
C) move list[4] to list[3]
D) copy list[4] into temp
سؤال
Let f be a function of n.By the term ____________________, we mean the study of the function f as n becomes larger and larger without bound.
سؤال
When working with the unsorted portion of a list, the second step in a selection sort is to ____.

A) divide the list into two parts
B) move the smallest element to the top of the list (position 0)
C) move the smallest element to the beginning of the unsorted list
D) find the smallest element
سؤال
If n = 1000, to sort the list, bubble sort makes about ____ item assignments.

A) 10,000
B) 100,000
C) 250,000
D) 500,000
سؤال
For a list of length n, insertion sort makes ____ key comparisons, in the worst case.

A) n(n - 1)/4
B) n(n - 1)/2
C) n2
D) n3
سؤال
For a list of length n, the bubble sort makes exactly ____________________ key comparisons.
سؤال
The ____________________ search algorithm is the optimal worst-case algorithm for solving search problems by using the comparison method.
سؤال
The behavior of quick sort is ____ in the worst case and ____ in the average case.

A) O(nlog2n), O(nlog2n)
B) O(n2), O(n)
C) O(nlog2n), O(n2)
D) O(n2), O(nlog2n)
سؤال
To construct a search algorithm of the order less than log2n, it cannot be ____________________ based.
سؤال
We can trace the execution of a comparison-based algorithm by using a graph called a ____.

A) pivot table
B) partition table
C) comparison tree
D) merge tree
سؤال
A sequence of branches in a comparison tree is called a(n) ____________________.
سؤال
In a quick sort, all of the sorting work is done by the function ____________________.
سؤال
The behavior of merge sort is ____ in the worst case and ____ in the average case.

A) O(nlog2n), O(nlog2n)
B) O(n2), O(n)
C) O(nlog2n), O(n2)
D) O(n2), O(nlog2n)
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 18: Searching and Sorting Algorithms
1
Consider the following list:int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search for 75, after the first comparison, the search is restricted to ____.

A) list[0]...list[6]
B) list[0]...list[7]
C) list[5]...list[11]
D) list[6]...list[11]
D
2
The selection sort algorithm finds the location of the smallest element in the unsorted portion of the list.
True
3
A sequential search of an n-element list takes ____ key comparisons if the item is not in the list.

A) 0
B) n/2
C) n
D) n2
C
4
The binary search algorithm can be written iteratively or recursively.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
In a bubble sort, the smaller elements move toward the bottom, and the larger elements move toward the top of the list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
With the binary search algorithm, ____ key comparison(s) is/are made in the successful case-the last time through the loop.

A) one
B) two
C) n-2
D) n
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
The sequential search algorithm does not require that the list be sorted.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
In a binary search, first, the search item is compared with the last element of the list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
The swap function of quick sort is written differently from the swap function for selection sort.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
In the average case, sequential search typically searches ____.

A) one quarter of the list
B) one third of the list
C) one half of the list
D) the entire list
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
The formula to find the index of the middle element of a list is ____.

A) (mid + last)/2
B) (first + last) - 2
C) (first + last) / 2
D) (first + mid ) * 2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
Assume that list consists of the following elements.What is the result after bubble sort completes? int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16};

A) 89 73 56 46 34 25 16 10 5 2
B) 2 56 34 25 5 16 89 46 73
C) 2 5 10 16 25 34 46 56 73 89
D) 2 10 16 25 34 46 56 73 89
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
In a bubble sort for list of length n, the first step is to compare elements ____.

A) list[0] and list[n]
B) list[0] and list[n-1]
C) list[0] and list[1]
D) list[n-1] and list[n+1]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
Consider the following list:int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95} When performing a binary search, the target is first compared with ____.

A) 4
B) 25
C) 39
D) 95
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
The sequential search algorithm uses a(n) ____ variable to track whether the item is found.

A) int
B) bool
C) char
D) double
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
In the bubble sort algorithm, the following code accomplishes swapping values in elements at positions index and index + 1.

A) list[index] = list[index + 1]
List[index + 1] = list[index]
B) list[index + 1] = list[index]
List[index] = list[index + 1]
C) list[index] = temp;
List[index] = list[index + 1];
Temp = list[index + 1];
D) temp = list[index];
List[index] = list[index + 1];
List[index + 1] = temp;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
Suppose that L is a sorted list of size 1024, and we want to determine whether an item x is in L.From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
A sequential search of an n-element list takes ____ key comparisons on average to determine whether the search item is in the list.

A) 0
B) n/2
C) n
D) n2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
If n = 1000, then to sort the list, selection sort makes about 50,000 key comparisons.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
With insertion sort, the variable firstOutOfOrder is initialized to ____, assuming n is the length of the list.

A) 0
B) 1
C) n - 1
D) n
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
The top node of a comparison tree is call the ____________________ node.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
For a list of length n, selection sort makes ____ item assignments.

A) n(n - 1)/2
B) 3(n - 1)
C) 3(n)
D) 4(n + 1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
____ sort requires knowing where the middle element of the list is.

A) Merge
B) Bubble
C) Insertion
D) Selection
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
A comparison tree is a(n) ____________________ tree.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Assuming the following list declaration, which element is at the position 0 after the first iteration of selection sort? int list[] = {16, 30, 24, 7, 62, 45, 5, 55}

A) 5
B) 7
C) 16
D) 62
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
The first step in the quick sort partition algorithm is to determine the ____________________ and swap it with the first element in the list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
When moving array values for insertion sort, to move list[4] into list[2], first ____.

A) move list[2] to list[3]
B) delete list[2]
C) move list[4] to list[3]
D) copy list[4] into temp
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Let f be a function of n.By the term ____________________, we mean the study of the function f as n becomes larger and larger without bound.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
When working with the unsorted portion of a list, the second step in a selection sort is to ____.

A) divide the list into two parts
B) move the smallest element to the top of the list (position 0)
C) move the smallest element to the beginning of the unsorted list
D) find the smallest element
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
If n = 1000, to sort the list, bubble sort makes about ____ item assignments.

A) 10,000
B) 100,000
C) 250,000
D) 500,000
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
For a list of length n, insertion sort makes ____ key comparisons, in the worst case.

A) n(n - 1)/4
B) n(n - 1)/2
C) n2
D) n3
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
For a list of length n, the bubble sort makes exactly ____________________ key comparisons.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
The ____________________ search algorithm is the optimal worst-case algorithm for solving search problems by using the comparison method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
The behavior of quick sort is ____ in the worst case and ____ in the average case.

A) O(nlog2n), O(nlog2n)
B) O(n2), O(n)
C) O(nlog2n), O(n2)
D) O(n2), O(nlog2n)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
To construct a search algorithm of the order less than log2n, it cannot be ____________________ based.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
We can trace the execution of a comparison-based algorithm by using a graph called a ____.

A) pivot table
B) partition table
C) comparison tree
D) merge tree
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
A sequence of branches in a comparison tree is called a(n) ____________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
In a quick sort, all of the sorting work is done by the function ____________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
The behavior of merge sort is ____ in the worst case and ____ in the average case.

A) O(nlog2n), O(nlog2n)
B) O(n2), O(n)
C) O(nlog2n), O(n2)
D) O(n2), O(nlog2n)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.