Deck 12: Searching and Sorting

ملء الشاشة (f)
exit full mode
سؤال
____________________ is the process of arranging a group of items into a defined order.

A) Searching
B) Sorting
C) Selecting
D) Helping
E) none of the above
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
A _______________ search is more efficient than a linear search.

A) binary
B) selection
C) insertion
D) bubble
E) none of the above
سؤال
Which of the following is not a sorting algorithm?

A) Bubble sort
B) Quick sort
C) Merge sort
D) Selection sort
E) all of the above are sorting algorithms
سؤال
Which of the following algorithms is most easily expressed recursively?

A) linear search
B) quick sort
C) bubble sort
D) selection sort
E) none of the above algorithms are easily expressible recursively
سؤال
Which of the following algorithms has a worst case complexity of O(n log2n)?

A) insertion sort
B) selection sort
C) bubble sort
D) merge sort
E) none of the above
سؤال
Bubble sort is the most efficient searching algorithm.
سؤال
The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted.

A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort
سؤال
As the number of items in a search pool grows, the number of comparisons required to search _______________ .

A) increases
B) decreases
C) stays the same
D) goes to 0
E) none of the above
سؤال
The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if the are not in order relative to each other.

A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort
سؤال
Which of the following algorithms has a time complexity of O(log2 n)?

A) insertion sort
B) selection sort
C) bubble sort
D) linear search
E) binary search
سؤال
If there are more items in a search pool, then it will typically require more comparisons to find an item.
سؤال
A linear search always requires more comparisons than a binary search.
سؤال
Every algorithm for a problem has the same efficiency.
سؤال
A __________________ search looks through the search pool one element at a time.

A) binary
B) clever
C) insertion
D) selection
E) linear
سؤال
Which of the following algorithms has a worst-case complexity of O(n2)?

A) insertion sort
B) selection sort
C) bubble sort
D) all of the above
E) neither a, b, nor c
سؤال
The ___________________ of an algorithm shows the relationship between the size of the problem and the value we hope to optimize.

A) growth function
B) growth analysis
C) size function
D) size analysis
E) none of the above
سؤال
A linear search is more efficient than a binary search.
سؤال
_____________________ is the process of finding a designated target element within a group of items.

A) Sorting
B) Searching
C) Recursing
D) Helping
E) none of the above
سؤال
In a binary search, _______________________________ .

A) it is assumed that all of the elements are integers.
B) it is assumed that all of the elements are Strings.
C) it is assumed that the search pool is small.
D) it is assumed that the search pool is ordered.
E) it is assumed that the search pool is large.
سؤال
Suppose we have algorithms that solve a particular problem that have the following complexities. Which one is most efficient?

A) O(1)
B) O(log2n)
C) O(n2)
D) O(n3)
E) O(2n)
سؤال
Write a method that accepts an array of integers as a parameter and sorts them using the selection sort algorithm.
سؤال
To represent constant time complexity we use O(c).
سؤال
The selection sort algorithm sorts a list of values by repeatedly putting a particular value into its final, sorted position.
سؤال
Explain how merge sort works.
سؤال
Write out the state while being sorted using the insertion sort algorithm:
91 6 3 55 110 8 1 703
سؤال
Write a method that accepts an integer array as a parameter and sorts it using the bubble sort algorithm.
سؤال
Write out the state of the list while being sorted using the selection sort algorithm:
91 6 3 55 110 8 1 703
سؤال
What is the complexity of the following code (in terms of the length of the array)?
for(int i = 0; i < 5; i++)
System.out.println(array[i]);
سؤال
What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a complexity of O(1)?
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array.length; j++)
someMethod(array[j]);
سؤال
Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. The method should use a linear search.
سؤال
Suppose we would like to swap the elements at index i and index j in an array. Does the following code work? If so, explain how. If not, explain why it fails.
array[i] = array[j];
array[j] = array[i];
سؤال
In the binary search algorithm, if the number of elements in the search pool is even, which value is used as the midpoint? Explain.
سؤال
Bubble sort works by separating a list into two lists, recursively sorting the two lists using bubble sort, and then combining the sorted sublists into a sorted list.
سؤال
Quick sort works by separating a list into two lists, and recursively sorting the two lists using quick sort.
سؤال
Explain why a faster computer can never make an exponential time algorithm run faster than a polynomial time algorithm on all inputs.
سؤال
Explain what O(1) means.
سؤال
How many times will the following code print out Hello World (in terms of the length of the array)?
for(int i = 0; i < array.length; i++) {
for(int j = 0; j < array.length; j++) {
for(int k = 0; k < array.length; k++) {
System.out.println("Hello World!");
}
}
}
سؤال
Explain how quick sort works.
سؤال
With each comparison, a binary search eliminates approximately half of the items remaining in the search pool.
سؤال
Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. You may assume that the array is sorted, and your method should use a binary search..
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 12: Searching and Sorting
1
____________________ is the process of arranging a group of items into a defined order.

A) Searching
B) Sorting
C) Selecting
D) Helping
E) none of the above
B
Explanation: Sorting is the process of arranging a group of items into a defined order.
2
A _______________ search is more efficient than a linear search.

A) binary
B) selection
C) insertion
D) bubble
E) none of the above
A
Explanation: A binary search is more efficient than a linear search, but it assumes that the search pool is ordered.
3
Which of the following is not a sorting algorithm?

A) Bubble sort
B) Quick sort
C) Merge sort
D) Selection sort
E) all of the above are sorting algorithms
E
Explanation: All of the algorithms listed are examples of sorting algorithms.
4
Which of the following algorithms is most easily expressed recursively?

A) linear search
B) quick sort
C) bubble sort
D) selection sort
E) none of the above algorithms are easily expressible recursively
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following algorithms has a worst case complexity of O(n log2n)?

A) insertion sort
B) selection sort
C) bubble sort
D) merge sort
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
Bubble sort is the most efficient searching algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted.

A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
As the number of items in a search pool grows, the number of comparisons required to search _______________ .

A) increases
B) decreases
C) stays the same
D) goes to 0
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if the are not in order relative to each other.

A) insertion sort
B) selection sort
C) bubble sort
D) quick sort
E) merge sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following algorithms has a time complexity of O(log2 n)?

A) insertion sort
B) selection sort
C) bubble sort
D) linear search
E) binary search
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
If there are more items in a search pool, then it will typically require more comparisons to find an item.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
A linear search always requires more comparisons than a binary search.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Every algorithm for a problem has the same efficiency.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
A __________________ search looks through the search pool one element at a time.

A) binary
B) clever
C) insertion
D) selection
E) linear
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which of the following algorithms has a worst-case complexity of O(n2)?

A) insertion sort
B) selection sort
C) bubble sort
D) all of the above
E) neither a, b, nor c
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
The ___________________ of an algorithm shows the relationship between the size of the problem and the value we hope to optimize.

A) growth function
B) growth analysis
C) size function
D) size analysis
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
A linear search is more efficient than a binary search.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
_____________________ is the process of finding a designated target element within a group of items.

A) Sorting
B) Searching
C) Recursing
D) Helping
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
In a binary search, _______________________________ .

A) it is assumed that all of the elements are integers.
B) it is assumed that all of the elements are Strings.
C) it is assumed that the search pool is small.
D) it is assumed that the search pool is ordered.
E) it is assumed that the search pool is large.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Suppose we have algorithms that solve a particular problem that have the following complexities. Which one is most efficient?

A) O(1)
B) O(log2n)
C) O(n2)
D) O(n3)
E) O(2n)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
Write a method that accepts an array of integers as a parameter and sorts them using the selection sort algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
To represent constant time complexity we use O(c).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
The selection sort algorithm sorts a list of values by repeatedly putting a particular value into its final, sorted position.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
Explain how merge sort works.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
Write out the state while being sorted using the insertion sort algorithm:
91 6 3 55 110 8 1 703
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
Write a method that accepts an integer array as a parameter and sorts it using the bubble sort algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
Write out the state of the list while being sorted using the selection sort algorithm:
91 6 3 55 110 8 1 703
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
What is the complexity of the following code (in terms of the length of the array)?
for(int i = 0; i < 5; i++)
System.out.println(array[i]);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
What is the complexity of the following code (in terms of the length of the array), assuming someMethod has a complexity of O(1)?
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array.length; j++)
someMethod(array[j]);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. The method should use a linear search.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
Suppose we would like to swap the elements at index i and index j in an array. Does the following code work? If so, explain how. If not, explain why it fails.
array[i] = array[j];
array[j] = array[i];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
In the binary search algorithm, if the number of elements in the search pool is even, which value is used as the midpoint? Explain.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
Bubble sort works by separating a list into two lists, recursively sorting the two lists using bubble sort, and then combining the sorted sublists into a sorted list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
Quick sort works by separating a list into two lists, and recursively sorting the two lists using quick sort.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Explain why a faster computer can never make an exponential time algorithm run faster than a polynomial time algorithm on all inputs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
Explain what O(1) means.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
How many times will the following code print out Hello World (in terms of the length of the array)?
for(int i = 0; i < array.length; i++) {
for(int j = 0; j < array.length; j++) {
for(int k = 0; k < array.length; k++) {
System.out.println("Hello World!");
}
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
Explain how quick sort works.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
With each comparison, a binary search eliminates approximately half of the items remaining in the search pool.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
Write a method that accepts an integer and an array of integers, and returns true if the integer is contained in the array. You may assume that the array is sorted, and your method should use a binary search..
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.