Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 How many times can an list with 729 elements be cut into three equal

ID: 3828705 • Letter: Q

Question

Question 1

How many times can an list with 729 elements be cut into three equal pieces?

Question options:

4

5

6

7

Question 2

In the textbook, we found that the number of element visits for merge sort totaled n + 5nlog2n. Which of the following is the appropriate big-Oh notation for merge sort?

Question options:

5nlog2n

n + log2

n + 5n

nlog2n

Question 3

In big-Oh notation, when we consider the order of the number of visits an algorithm makes, what do we ignore?

I. Power of two terms

II. The coefficients of the terms

III. All lower order terms

Question options:

I only

II only

I and II only

II and III only

Question 4

Consider the following variation of the selection sort algorithm:

def sort(values) :

   for i in range(len(values)) :

      maxPos = i

      for j in range(i + 1, len(values)) :

         if values[j] > values[maxPos] :

            maxPos = j

   temp = values[maxPos]

   values[maxPos] = values[i]

   values[i] = values[maxPos]

If this algorithm takes 5 seconds to sort 15,000 elements, how long would you expect it to take to sort 30,000 elements?

Question options:

5 seconds

10 seconds

25 seconds

50 seconds

Question 5

The checklist function is shown below:

def checklist(lst) :

   if(lst[0] >= lst[len(lst)-1] :

      return True

   return False

What can you conclude about the running time of this function?

Question options:

Its running time will be O(n).

Its running time will be O(n2).

Its running time will be O(log n).

Its running time will be O(1).

Question 6

Consider the following function, which correctly merges two lists:

def mergeLists(first, second, values) :

   iFrist = 0

   iSecond = 0

   j = 0

   while iFirst < len(first) and iSecond < len(second) :

      if first[iFirst] < second[iSecond] :

         values[j] = first[iFirst]

         iFirst = iFirst + 1

      else :

         values[j] = second[iSecond]

         iSecond = iSecond + 1

      j = j + 1

   while iFrist < len(first) :

      values[j] = first[iFirst]

      iFirst = iFirst + 1

      j = j + 1

   while iSecond < len(second) :

      values[j] = second[iSecond]

      iSecond = iSecond + 1

      j = j + 1

     

What is the big-Oh complexity of this algorithm, where n is the total number of elements in first and second?

Question options:

O(1)

O(log(n))

O(n)

O(n2)

Question 7

The following program is supposed to time the performance of the selectionSort function. Right now it is missing the code, startTime = time(), which records the starting time. Where should the missing code be inserted?

                                   # Line 1

values = []

                                   # Line 2

for i in range(10000) :

   values.append(randint(1, 100))

                                   # Line 3

selectionSort(values)

                                   # Line 4

endTime = time()

Question options:

Line 1

Line 2

Line 3

Line 4

Question 8

An algorithm that cuts the work in half in each step is an ____ algorithm.

Question options:

O(n)

O(n2)

O(log n)

O(n log n)

Question 9

Consider the following function for performing a binary search:

def binarySearch(values, low, high, target) :

   if low <= high :

      mid = (low + high) // 2

      if values[mid] == target :

         return mid

      elif values[mid] < target :

         return binarySearch(values, mid + 1, high, target)

      else :

         return binarySearch(values, low, mid - 1, target)

   else :

      return -1

How many elements will be visited when values is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], low is 0, high is 9, and target is 10?

Question options:

0

2

4

10

Question 10

Suppose you have a phone number and need to find the address that it corresponds to. If there are 2,000,000 entries, how many do you expect to search in a printed phone directory before finding the address you are looking for?

Question options:

Approximately 50,000 records

Approximately 75,000 records

Approximately 1,000,000 records

Approximately 1,200,000 records

Question 11

Which of the following statements about running times of algorithms is correct?

Question options:

An algorithm that is O(1) means that only one comparison takes place.

When determining the running time, constants are not taken into consideration.

When determining the running time, lower-order terms must be taken into consideration.

An algorithm that is O(n) means that the number of comparisons does not grow as the size of the list increases.

Question 12

Consider the following class:

Which line(s) are part of the public interface for the class?

Question options:

Only line 1

Only line 2

Only lines 2 and 3

Only lines 3 and 4

Question 13

Consider the following class:

Which method is an accessor?

Question options:

getValue

click

unClick

Reset

Question 14

Consider the following class:

Which method(s) are mutators?

Question options:

Only reset

Only click and unClick

Only click, unClick and reset

All four methods are mutators

Question 15

Which of the following statements determines if x currently refers to an object containing an integer?

Question options:

if int(x) :

if x == int :

if x is int :

if isinstance(x, int) :

Question 16

Consider the code for mergeSort shown below, which works correctly:

What would happen if the line mid = len(values) // 2 was replaced with the line mid = len(values) // 4

Question options:

Merge sort would continue to work at the same speed as the original version

Merge sort would continue to work, but it would be slower than the original version

Merge sort would continue to work, and it would be faster than the original

The modified version would not sort the list successfully

4

5

6

7

Explanation / Answer

Answer in Bold

Question 1

How many times can an list with 729 elements be cut into three equal pieces?

Question options:

Answer: 6

(list of 243,84,27,9,3,1)

Question 2

In the textbook, we found that the number of element visits for merge sort totaled n + 5nlog2n. Which of the following is the appropriate big-Oh notation for merge sort?

Answer: nlog2n

Question 3

In big-Oh notation, when we consider the order of the number of visits an algorithm makes, what do we ignore?

I. Power of two terms

II. The coefficients of the terms

III. All lower order terms

Answer: II and III only

Question 4

Consider the following variation of the selection sort algorithm:

def sort(values) :

   for i in range(len(values)) :

      maxPos = i

      for j in range(i + 1, len(values)) :

         if values[j] > values[maxPos] :

            maxPos = j

   temp = values[maxPos]

   values[maxPos] = values[i]

   values[i] = values[maxPos]

If this algorithm takes 5 seconds to sort 15,000 elements, how long would you expect it to take to sort 30,000 elements?

Question options:

Answer: 25 seconds, its basically an O(n^2) time complexity method.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote