Using the pseudocode answer these questions
1.)
The given pseudo code traverses the array until the present element power next element is greater than the next next element if it finds so then it would return the index of the element
For example consider the array 1 2 3 5
current element is 1 next element is 2 and next next element to 1 is 3
so if =1 is not greater than 3 so we traverse the array
now index is at 2 and =8 >5 since this satisfies index 1 would be returned (given 0 indexing)
After complete traversal of the array if it could not find out the element then it would -1 .
...............................
Given array = {1, 2, 3, 4, 5}
iteration i=0
a[i]=1 a[i+1]=2 a[i+2]=3
so =1 is not greater than 3 so increment i
Now i=1
a[i]=2 a[i+1]=3 a[i+2]=4
=8 > 4 since the condition is satisfied i will be returned
Here i=1 so index 1 will be returned.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2.)Worst case input is if we do not find the index that is satisfying the given condition
So if in the given array after traversing the whole array if the index is not returned that means if the condition is not satisfied for any of the elements in the array then it is the worst case input
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3)Best case input is the one if the condition is satisfied in the first location that is returning the index 0 as output is the best case input
For example consider an array 2 3 4 1
here the condition is satisfied in the first location hence it would index of 2 which is 0
this is the best input case
Using the pseudocode answer these questions Algorithm 1 CS317FinalAlgorithm (A[O..n-1]) ito while i<n - 2 do...
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.
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.
(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...
Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x is an element from the set {n EN|2sn s50). What is the worst-case number of comparisons that this algorithm will perform? O O O O O O
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
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...
pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positive integer k21. Mystery (n) if n<4 3 for i1 to 9 5 for i-1 to n 2 return 1 Mystery (n/3) Print "hello" 6 (1) (5 points) Please analyze the worst-case asymptotic execution time of this algorithm. Express the execution time as a function of the input...
URGENT Question 3 25 pts ArrayMystery: Input: n: a positive integer Pseudocode: Let output be an empty array For i = 1 to n j = 1 While ij <= n Addj to the end of output j - j + 1 Return output Answer the following questions about the ArrayMystery algorithm above. a) How many times will the inner while loop iterate? You should express your answer in terms of i and n, using Big-Oh notation. Briefly justify your...
a. Write a pseudocode for computing for any positive integer n Besides assignment and comparison, your algorithm may only use the four basic arithmetical operations. What is the time efficiency of your algorithm for the worst and best cases? Justify your answer. (The basic operation must be identified explicitly). Give one instance for the worst case and one instance for the best case respectively if there is any difference between the worst case and best case. Otherwise please indicate that...
1.Write in pseudocode a recursive algorithm for the operation deleteHighest (t), where t is the root of the BST, to delete the largest element in a BST 2.Fill in the following table, giving the “worstcase”time complexity for each operation, ineach of the two implementations, assumingthe PQ contains n elements. insert deleteHighest Worst case time compexity Heap BST