We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x...
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1 6. Use limits to show that, for best case inputs, the asymptotic growth of the number of comparisons is (1). Show your work. 7. Use limits to show that, for worst case inputs, the asymptotic growth of the number of comparisons is O(n). Show your work.
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1 1. Describe what it does and compute what value is returned when the input is the list {1, 2, 3, 4, 5}. (Hint: We're using 0-based array indexing, so 0 would represent the index of the first element, 1 the second element, etc.) 2. Identify and describe the worst-case input. 3. Identify and...
Given the following algorithm: Algorithnm Input: a1, a2,...,an, a sequence of numbers n, the length of the sequence x, a number Output: ?? i:- 1 While (x2 # a, and i < n) i+1 End-while If (x- - a) Return(i) Return(-1) 3, -1, 2,9, 36,-7, 6,4 a) What is the correct output of the Algorithm with the following input: a1, a2,..an b) What is the asymptotic worst-case time complexity of the Algorithm? Algorithnm Input: a1, a2,...,an, a sequence of numbers...
1. Consider the following well-known sorting algorithm, which is studied later in the book, with a counter inserted to count the number of key comparisons. ALGORITHM SortAnalysis(A[0..n − 1]) //Input: An array A[0..n − 1] of n orderable elements //Output: The total number of key comparisons made count ←0 for i ←1 to n − 1 do v ←A[i] j ←i − 1 while j ≥ 0 and A[j ]> v do count ←count + 1 A[j + 1]←A[j ]...
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do if A[i]A[i+1] > A[i+2) then return i it i+1 return -1 4. Calculate how many times the comparison A[i]A[i+1] > A[i+2] is done for a worst-case input of size n. Show your work. 5. Calculate how many times the comparison A[i]A[i+1] > A[i+2] is done for a best-case input of size n. Show your work.
Exercise 1 Use Top-Down Design to “design” a set of instructions to write an algorithm for “travel arrangement”. For example, at a high level of abstraction, the algorithm for “travel arrangement” is: book a hotel buy a plane ticket rent a car Using the principle of stepwise refinement, write more detailed pseudocode for each of these three steps at a lower level of abstraction. Exercise 2 Asymptotic Complexity (3 pts) Determine the Big-O notation for the following growth functions: 1....
Consider the following Python function: def find_max (L): max = 0 for x in L: if x > max: max = x return max Suppose list L has n elements. In asymptotic notation, determine the best case running time as function of n In asymptotic notation, determine the worst case running time as function of n Now, assume L is sorted. Give an algorithm that takes asymptotically less time than the above algorithm, but performs the same function. Prove that...
4. The following algorithm step 1: 20 := r; j :=0 step 2: while x; # 0, do d; := remainder of integer divide x;/2 Xj+1 := quotient of integer divide x;/2 j:= + 1 end while can be used to convert a positive decimal integer x to its binary equivalent, x = (anan-1.0190)2. Implement the algorithm (write a computer program) and apply it to convert the following integers to their binary equivalents. (a) 56 (b) 1543 (The Matlab library...
(V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...
Consider the following algorithm: ocedure Algorithm (b: integer, n: positive integer,i datinct integem) proc answer :", 0 nand 6 while (j print(j, z, b, answer) if jSn then answer:-j return answer (8 points] Assume that this algorithm receives as input the numbers b-17 andn9nd the corresponding sequence or iaie i 2 3 4 516 7 8 corresponding sequence of integers 19 Fill out the table below: i 는, ↓answer (b) [I point] Assume that the algorithm receives the same input...