Question

In: Advanced Math

1) At the end of the following algorithm segment, what value is in variable n? n:=...

1)

At the end of the following algorithm segment, what value is in variable n?

   n:= 31
   WHILE ( n is prime)
      n:= n -2
   END WHILE

2) Prove that there is no greatest negative real number using contradiction or contraposition.

Solutions

Expert Solution

The First Problem is a simple iteration of the while loop.

The Second Problem has been solved using proof by contradiction.


Related Solutions

n following code if variable n=0, a=5 and b=10 then what will be the value of...
n following code if variable n=0, a=5 and b=10 then what will be the value of variable ‘n’ after while loop executed. Show your working as well. while(n<=(a^b)) { n++; } printf("%d",n)
Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary array A[0..n − 1]...
Consider the following pseudocode for insertion-sort algorithm. The algorithm sorts an arbitrary array A[0..n − 1] of n elements. void ISORT (dtype A[ ], int n) { int i, j; for i = 1 to n – 1 {     //Insert A[i] into the sorted part A[0..i – 1]     j = i;     while (j > 0 and A[j] < A[j – 1]) {         SWAP (A[j], A[j – 1]);         j = j – 1 }     }...
Consider the following algorithm. Algorithm Mystery(n) //Input: A nonnegative integer n S ← 0 for i...
Consider the following algorithm. Algorithm Mystery(n) //Input: A nonnegative integer n S ← 0 for i ← 1 to n do S ← S + i * i return S a. What does this algorithm compute? b. What is its basic operation? c. How many times is the basic operation executed? d. What is the efficiency class of this algorithm? e. Suggest an improvement, or a better algorithm altogether, and indicate its efficiency class. If you cannot do it, try...
for an array A of size N, and A[0] != A[n-1]. devise an efficient algorithm for...
for an array A of size N, and A[0] != A[n-1]. devise an efficient algorithm for find a pair of elements A[i] and A[i+1] such that A[i] != A[i+1]. can you always find such pair and why
Let iqsort(A, 1, n) be an algorithm that sorts an array A with n integers. It...
Let iqsort(A, 1, n) be an algorithm that sorts an array A with n integers. It works as follows: iqsort(A, p, q){ if p ≥ q, return; r=partition(A, p, q); //run quick sort on the low part quicksort(A, p, r − 1); //run insert sort on the high part insertsort(A, r + 1, q); } Compute the best-case, worst-case, and average-case complexities of iqsort.
What is O(g(n)) for the following method? What sorting algorithm is this? /*Function to sort array...
What is O(g(n)) for the following method? What sorting algorithm is this? /*Function to sort array using ??? sort*/ void sort(int arr[]) { int n = arr.length; for (int i = 1; i < n; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j];...
1. Value the following scenario, assuming there is no end to the timeline and the following...
1. Value the following scenario, assuming there is no end to the timeline and the following data: Cost of equity = 17.75% Cost of debt = 6.83% Debt = $583MM Equity = $1237MM Tax rate = 40% Long-term growth expectations = 3.6% Future dividends are forecast as follows: Year 0: n/a Year 1: 128 Year 2: 149 Year 3: 162 Year 4: 175 Year 5: 182 (Round your answer to the nearest cent) 2. Use the data below to compute...
Consider the following recursive algorithm for computing the sum of the first n squares: S(n) =...
Consider the following recursive algorithm for computing the sum of the first n squares: S(n) = 12 +22 +32 +...+n2 . Algorithm S(n) //Input: A positive integer n //Output: The sum of the first n squares if n = 1 return 1 else return S(n − 1) + n* n a. Set up and solve a recurrence relation for the number of times the algorithm’s basic operation is executed. b. How does this algorithm compare with the straightforward non-recursive algorithm...
PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if...
PYTHON: Implement the following algorithm to construct magic n × n squares; it works only if n is odd. row ← n - 1 column ← n/2 for k = 1 . . . n2 do Place k at [row][column] Increment row and column if the row or column is n then replace it with 0 end if if the element at [row][column] has already been filled then Set row and column to their previous values Decrement row end if...
1.Which of the following is not a characteristic of a binomial random variable? a. n identical...
1.Which of the following is not a characteristic of a binomial random variable? a. n identical trials b. probability of failure is the same for each trial c. non-correlated outcomes for each trial d. non of the above 2. Which of the following are not binomial random variables(multiple answers) a. one hundred randomly selected individuals are asked about their opinion on health insurance b. one hundred people at a bar are asked about whether they are for or against restricting...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT