Filters
Question type

Study Flashcards

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

E) A) and D)
F) A) and C)

Correct Answer

verifed

verified

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

E) A) and D)
F) None of the above

Correct Answer

verifed

verified

The in operator performs a binary search algorithm.

A) True
B) False

Correct Answer

verifed

verified

The amount of work of a logarithmic algorithm is proportional to the log2 of the problem size.

A) True
B) False

Correct Answer

verifed

verified

Python's in operator is implemented as a method named __contains__ in the list class.

A) True
B) False

Correct Answer

verifed

verified

All algorithms that perform the same task take the same amount of time to complete.

A) True
B) False

Correct Answer

verifed

verified

False

The merge sort employs a recursive, divide-and-conquer strategy to break the O( n2 ) barrier.

A) True
B) False

Correct Answer

verifed

verified

On sorted data, you can use a binary search.

A) True
B) False

Correct Answer

verifed

verified

The result of fib(4) is 8.

A) True
B) False

Correct Answer

verifed

verified

The number of Python instructions executed in an algorithm will differ from the number of machine language instructions executed.

A) True
B) False

Correct Answer

verifed

verified

True

In a selection sort, the outer loop executes n - 1 times.

A) True
B) False

Correct Answer

verifed

verified

The first two numbers in the Fibonacci sequence are 1s, and each number after that is the sum of the previous two numbers.

A) True
B) False

Correct Answer

verifed

verified

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

E) All of the above
F) None of the above

Correct Answer

verifed

verified

In a bubble sort, each pass through the main loop selects a single item to be moved.

A) True
B) False

Correct Answer

verifed

verified

What is the complexity of a selection sort?


A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

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

E) A) and D)
F) C) and D)

Correct Answer

verifed

verified

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

E) A) and B)
F) A) and C)

Correct Answer

verifed

verified

A

What is the worst-case complexity of a binary search?


A) O( n 2)
B) O( n )
C) O(log2 n )
D) O2

E) A) and B)
F) B) and D)

Correct Answer

verifed

verified

An algorithm that uses the exact same Python code run on two different machines should have the same performance data.

A) True
B) False

Correct Answer

verifed

verified

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

E) A) and C)
F) A) and B)

Correct Answer

verifed

verified

Showing 1 - 20 of 50

Related Exams

Show Answer