Deck 3: Searching, Sorting, and Complexity Analysis

ملء الشاشة (f)
exit full mode
سؤال
The time() function returns the amount of time a program has been running in seconds.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
This bubble sort has the effect of bubbling the largest items to the end of the list.
سؤال
In the average case, where many items in a list are out of order, an insertion sort is linear.
سؤال
Using a binary search, a list of 1 million items requires only 20 comparisons.
سؤال
An algorithm that uses the exact same Python code run on two different machines should have the same performance data.
سؤال
Benchmarking is the process of using the computer's clock to obtain run time information for an algorithm.
سؤال
The order of complexity of a linear-time algorithm is On .
سؤال
The number of Python instructions executed in an algorithm will differ from the number of machine language instructions executed.
سؤال
In a bubble sort, each pass through the main loop selects a single item to be moved.
سؤال
On sorted data, you can use a binary search.
سؤال
The amount of work of a logarithmic algorithm is proportional to the log2 of the problem size.
سؤال
The bubble sort has a complexity of O( n 2).
سؤال
Algorithms with linear behavior do more work than those with quadratic behavior.
سؤال
In a selection sort, the inner loop is executed n - 2 times for every pass through the outer loop.
سؤال
The in operator performs a binary search algorithm.
سؤال
All algorithms that perform the same task take the same amount of time to complete.
سؤال
Python's in operator is implemented as a method named __contains__ in the list class.
سؤال
The performance of an algorithm in a single loop is linear.
سؤال
The sequential search algorithm does more work to find a target at the beginning of a list than at the end of the list.
سؤال
In a selection sort, the outer loop executes n - 1 times.
سؤال
The result of fib(4) is 8.
سؤال
Which of the following is a common way to measure the time cost of an algorithm?

A) count lines of code
B) use a stopwatch
C) calculate memory usage
D) use the computer's clock
سؤال
What type of algorithm is list indexing an example of?

A) constant-time
B) logarithmic-time
C) exponential-time
D) linear-time
سؤال
What does the Python time() function return?

A) The seconds elapsed since January 1, 1970
B) The number of instructions executed
C) The number of seconds the code has been running
D) The number of milliseconds to execute a line of code
سؤال
Which of the following is a method to estimate the efficiency of an algorithm that predicts the amount of work an algorithm performs regardless of the platform?

A) using a millisecond counter
B) counting instructions
C) determining memory usage
D) convert the algorithm to byte code
سؤال
What is the worst-case complexity of a binary search?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
سؤال
A bubble sort always requires approximately n2 comparisons.
سؤال
How can the following algorithm be described? left = 0
Right = len(sortedLyst) - 1
While left <= right:
Midpoint = (left + right) // 2
If target == sortedLyst[midpoint]:
Return midpoint
Elif target < sortedLyst[midpoint]:
Right = midpoint - 1
Else:
Left = midpoint + 1
Return -1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
سؤال
What should the missing code be in the following algorithm if the goal is to determine how many seconds the algorithm runs? start = time.time()
MyCount = 1
For x in range(100):
MyCount *= x
Elapsed = time.time() - < missing code >

A) myCount
B) elapsed
C) start
D) x
سؤال
Why is the efficiency of algorithms desirable?

A) an inefficient algorithm may use too much time or space
B) efficient algorithms always cost less money
C) inefficient algorithms always use too much memory
D) efficient algorithms always use less memory
سؤال
In the following code, what is the algorithm's complexity? minIndex = 0
CurrentIndex = 1
While currentIndex < len(lyst):
If lyst[currentIndex] < lyst[minIndex]:
MinIndex = currentIndex
CurrentIndex += 1
Return minIndex

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
سؤال
Which method of determining the efficiency of algorithms allows you to rate them independently of timings or instruction counts?

A) elapsed time profiling
B) byte-code assembly
C) complexity analysis
D) memory usage analysis
سؤال
How can an algorithm be described in which the work it does grows as a function of the square of the problem size?

A) exponential
B) logarithmic
C) quadratic
D) linear
سؤال
The first two numbers in the Fibonacci sequence are 1s, and each number after that is the sum of the previous two numbers.
سؤال
In a binary search of an ascending order list, where does the search algorithm begin the search?

A) the beginning of the list
B) a random spot in the list
C) the end of the list
D) the middle of the list
سؤال
How can the performance complexity of the following algorithm be described?
For x in range(numIterations):
Value = value * x
Print(value)

A) exponential
B) logarithmic
C) quadratic
D) linear
سؤال
The merge sort employs a recursive, divide-and-conquer strategy to break the O( n2 ) barrier.
سؤال
What term best describes the following code?
X = myList[ i ]
MyList[ i ] = myList[ j ]
MyList[ j ] = x

A) sequential search
B) binary sort
C) selection algorithm
D) swap function
سؤال
In the first step of the quicksort, you begin by selecting the item at the list's midpoint.
سؤال
How can the following algorithm be described?
Position = 0
While position < len(lyst):
If target == lyst[ position ]:
Return position
Position += 1
Return -1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
سؤال
What is the complexity of a selection sort?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
سؤال
What is the best case performance of a sequential search?

A) O n
B) linear
C) quadratic
D) O(1)
سؤال
An analysis of an algorithm's complexity divides its behavior into what three types of cases?

A) best case, worst case, average case
B) minimum case, maximum case, average case
C) linear case, quadratic case, logarithmic case
D) sequential case, exponential case, binary case
سؤال
What type of algorithm is the following code?
I = 0
While i < len(myList) - 1:
MinIndex = i
J = i + 1
While j < len(myList):
If myList[ j ] < myList[ minIndex ]:
MinIndex = j
J += 1
If minIndex != i:
Swap(myList, minIndex, i)
I += 1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
سؤال
How many loops are found in a typical insertion sort?

A) 1
B) 2
C) 3
D) 4
سؤال
In terms of complexity, what is the average case for an insertion sort?

A) linear
B) quadratic
C) exponential
D) logarithmic
سؤال
What type of algorithm is the following code?
N = len(myList)
While n > 1:
I = 1
While i < n:
If myList[ i ] < myList[ i - 1 ]:
Swap(myList, i, i - 1)
I += 1
N -= 1

A) linear sort
B) bubble sort
C) insertion sort
D) selection sort
سؤال
What should the missing code be in the following insertion sort algorithm? i = 1
While i < len(myList):
ItemToInsert = myList[i]
J = i - 1
While j >= 0:
If itemToInsert < myList[j]:
MyList[j + 1] = myList[j]
J -= 1
Else:
Break
< missing code >
I += 1

A) myList[ i + 1 ] = itemToInsert
B) myList[ j ] = itemToInsert
C) myList[ j + 1 ] = itemToInsert
D) myList[ i ] = itemToInsert
سؤال
In terms of complexity, what is the worst-case scenario for an insertion sort?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
سؤال
Which type of algorithm is analogous to how many people organize playing cards in their hands?

A) linear sort
B) bubble sort
C) insertion sort
D) selection sort
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 3: Searching, Sorting, and Complexity Analysis
1
The time() function returns the amount of time a program has been running in seconds.
False
2
This bubble sort has the effect of bubbling the largest items to the end of the list.
True
3
In the average case, where many items in a list are out of order, an insertion sort is linear.
False
4
Using a binary search, a list of 1 million items requires only 20 comparisons.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
An algorithm that uses the exact same Python code run on two different machines should have the same performance data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
Benchmarking is the process of using the computer's clock to obtain run time information for an algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
The order of complexity of a linear-time algorithm is On .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
The number of Python instructions executed in an algorithm will differ from the number of machine language instructions executed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
In a bubble sort, each pass through the main loop selects a single item to be moved.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
On sorted data, you can use a binary search.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
The amount of work of a logarithmic algorithm is proportional to the log2 of the problem size.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The bubble sort has a complexity of O( n 2).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
Algorithms with linear behavior do more work than those with quadratic behavior.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
In a selection sort, the inner loop is executed n - 2 times for every pass through the outer loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
The in operator performs a binary search algorithm.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
All algorithms that perform the same task take the same amount of time to complete.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
Python's in operator is implemented as a method named __contains__ in the list class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
The performance of an algorithm in a single loop is linear.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
The sequential search algorithm does more work to find a target at the beginning of a list than at the end of the list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
In a selection sort, the outer loop executes n - 1 times.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
The result of fib(4) is 8.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which of the following is a common way to measure the time cost of an algorithm?

A) count lines of code
B) use a stopwatch
C) calculate memory usage
D) use the computer's clock
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
What type of algorithm is list indexing an example of?

A) constant-time
B) logarithmic-time
C) exponential-time
D) linear-time
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
What does the Python time() function return?

A) The seconds elapsed since January 1, 1970
B) The number of instructions executed
C) The number of seconds the code has been running
D) The number of milliseconds to execute a line of code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
Which of the following is a method to estimate the efficiency of an algorithm that predicts the amount of work an algorithm performs regardless of the platform?

A) using a millisecond counter
B) counting instructions
C) determining memory usage
D) convert the algorithm to byte code
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
What is the worst-case complexity of a binary search?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
A bubble sort always requires approximately n2 comparisons.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
How can the following algorithm be described? left = 0
Right = len(sortedLyst) - 1
While left <= right:
Midpoint = (left + right) // 2
If target == sortedLyst[midpoint]:
Return midpoint
Elif target < sortedLyst[midpoint]:
Right = midpoint - 1
Else:
Left = midpoint + 1
Return -1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
What should the missing code be in the following algorithm if the goal is to determine how many seconds the algorithm runs? start = time.time()
MyCount = 1
For x in range(100):
MyCount *= x
Elapsed = time.time() - < missing code >

A) myCount
B) elapsed
C) start
D) x
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
Why is the efficiency of algorithms desirable?

A) an inefficient algorithm may use too much time or space
B) efficient algorithms always cost less money
C) inefficient algorithms always use too much memory
D) efficient algorithms always use less memory
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
In the following code, what is the algorithm's complexity? minIndex = 0
CurrentIndex = 1
While currentIndex < len(lyst):
If lyst[currentIndex] < lyst[minIndex]:
MinIndex = currentIndex
CurrentIndex += 1
Return minIndex

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which method of determining the efficiency of algorithms allows you to rate them independently of timings or instruction counts?

A) elapsed time profiling
B) byte-code assembly
C) complexity analysis
D) memory usage analysis
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
How can an algorithm be described in which the work it does grows as a function of the square of the problem size?

A) exponential
B) logarithmic
C) quadratic
D) linear
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
The first two numbers in the Fibonacci sequence are 1s, and each number after that is the sum of the previous two numbers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
In a binary search of an ascending order list, where does the search algorithm begin the search?

A) the beginning of the list
B) a random spot in the list
C) the end of the list
D) the middle of the list
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
How can the performance complexity of the following algorithm be described?
For x in range(numIterations):
Value = value * x
Print(value)

A) exponential
B) logarithmic
C) quadratic
D) linear
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
The merge sort employs a recursive, divide-and-conquer strategy to break the O( n2 ) barrier.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
What term best describes the following code?
X = myList[ i ]
MyList[ i ] = myList[ j ]
MyList[ j ] = x

A) sequential search
B) binary sort
C) selection algorithm
D) swap function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
In the first step of the quicksort, you begin by selecting the item at the list's midpoint.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
How can the following algorithm be described?
Position = 0
While position < len(lyst):
If target == lyst[ position ]:
Return position
Position += 1
Return -1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
What is the complexity of a selection sort?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
What is the best case performance of a sequential search?

A) O n
B) linear
C) quadratic
D) O(1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
An analysis of an algorithm's complexity divides its behavior into what three types of cases?

A) best case, worst case, average case
B) minimum case, maximum case, average case
C) linear case, quadratic case, logarithmic case
D) sequential case, exponential case, binary case
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
What type of algorithm is the following code?
I = 0
While i < len(myList) - 1:
MinIndex = i
J = i + 1
While j < len(myList):
If myList[ j ] < myList[ minIndex ]:
MinIndex = j
J += 1
If minIndex != i:
Swap(myList, minIndex, i)
I += 1

A) binary search
B) bubble sort
C) sequential search
D) selection sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
How many loops are found in a typical insertion sort?

A) 1
B) 2
C) 3
D) 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
In terms of complexity, what is the average case for an insertion sort?

A) linear
B) quadratic
C) exponential
D) logarithmic
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
What type of algorithm is the following code?
N = len(myList)
While n > 1:
I = 1
While i < n:
If myList[ i ] < myList[ i - 1 ]:
Swap(myList, i, i - 1)
I += 1
N -= 1

A) linear sort
B) bubble sort
C) insertion sort
D) selection sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
What should the missing code be in the following insertion sort algorithm? i = 1
While i < len(myList):
ItemToInsert = myList[i]
J = i - 1
While j >= 0:
If itemToInsert < myList[j]:
MyList[j + 1] = myList[j]
J -= 1
Else:
Break
< missing code >
I += 1

A) myList[ i + 1 ] = itemToInsert
B) myList[ j ] = itemToInsert
C) myList[ j + 1 ] = itemToInsert
D) myList[ i ] = itemToInsert
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
In terms of complexity, what is the worst-case scenario for an insertion sort?

A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
Which type of algorithm is analogous to how many people organize playing cards in their hands?

A) linear sort
B) bubble sort
C) insertion sort
D) selection sort
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.