Exam 5: Algorithms

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

Under the assumption that N takes on only integer values,which of the following is the termination condition in the following recursive function? def xxx(N): If (N < 5): Print(N) Else: Xxx(N - 1)

Free
(Multiple Choice)
4.8/5
(79)
Correct Answer:
Verified

A

Use a repeat loop structure to produce a non-recursive program segment that prints the same sequence of numbers as the following recursive function. def xxx (N): print () if (<5): xxx(N+1)

Free
(Essay)
4.8/5
(84)
Correct Answer:
Verified

 repeat:  print (N) N=N+1 until (N>6)\begin{array} { l } \text { repeat: } \\\text { print (N) } \\N = N + 1 \\\text { until } ( N > 6 )\end{array}

What sequence of numbers would be printed if the following function were executed with the value of N being 0? def xxx(N): print(N) if (N < 5): xxx(N + 2) print(N) __________________

Free
(Short Answer)
5.0/5
(81)
Correct Answer:
Verified

0,2,4,6,6,4,2,0

Which of the following is a loop invariant at the point at which the test for termination is performed in the following loop structure? X = 3 While (X < 5): X = X + 2

(Multiple Choice)
4.8/5
(72)

What sequence of values would be printed if the function xxx described below were executed with the value of N being 9? def xxx(N): if (N < 4): print(N) yyy(7) else: yyy(2) print(N) def yyy(N): if (N < 5): print(N) zzz(6) else: zzz(5) def zzz(N): if (N == 5): print(7) else: print(8) ________________________

(Short Answer)
4.7/5
(72)

The following function was designed to compute the largest integer whose square is no greater than N,where N is assumed to be a positive number.(If N is 5,then the function should report the value 2.)Find and correct the error. def squareRoot () : =0 while (*<=) : =+1; return

(Essay)
4.7/5
(74)

In general,an algorithm in which of the following categories is considered more efficient?

(Multiple Choice)
4.8/5
(78)

Which of the following does not print the same sequence of numbers as the others?

(Multiple Choice)
5.0/5
(68)

What would be printed if the following instructions were executed? X = 3 print(X) Y = 5 if (X < Y): print(6) else: print(7) _________________

(Short Answer)
5.0/5
(88)

Identify a loop invariant associated with the point in the loop below at which a test for termination is performed. X = 0 repeat: print(X) X = X + 2 until (X > 6) ___________________

(Short Answer)
4.7/5
(72)

Which of the following is a representation?

(Multiple Choice)
4.9/5
(77)

What sequence of values will be printed when the following instructions are executed? X = 5 while (X < 7): print(X) X = X + 1 print(X) while (X > 2): print(X) X = X - 2 _______________________

(Short Answer)
4.7/5
(83)

At most,how many entries in a list of 5000 names will be interrogated when using the binary search algorithm? ___________

(Short Answer)
4.8/5
(69)

What would be printed if the following instructions were executed? X = 3 while (X > 0): print(X) X = X - 1 _________________

(Short Answer)
4.9/5
(76)

Which of the following is not a way of representing algorithms?

(Multiple Choice)
4.9/5
(75)

Preconditions,postconditions,and loop invariants are examples of which of the following?

(Multiple Choice)
5.0/5
(81)

The pseudocode used in this chapter included both an if-then statement and an if-then-else statement. Show how the statement if (X == 5): ... else: ... can be simulated with a program segment using only if-then statements.

(Essay)
4.9/5
(75)

Define each of the following terms. A. Algorithm _______________________________________________________________ B. Program _______________________________________________________________ C. Process _______________________________________________________________

(Short Answer)
4.9/5
(78)

What sequence of numbers would be printed if the following function were executed with the value of N being 0? def xxx(N): while (N < 4): print(N) N = N + 2 print(N) __________________

(Short Answer)
4.8/5
(84)

Which of the following is not a means of repeating a block of instructions?

(Multiple Choice)
4.9/5
(71)
Showing 1 - 20 of 53
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)