(a) Give the pseudo-code for a recursive algorithm called Find_Smallest(A, n) that returns the value of the smallest element in an array of n integers called A. Assume the elements in the array are at locations A[1]..A[n].
(b) Give a recurrence T(n) for the running time of your algorithm.
(c) Solve the recurrence in part (b)
******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As HOMEWORKLIB RULES expert answering guidelines,Experts are supposed to
answer only certain number of questions/sub-parts in a post.Please
raise the remaining as a new question as HOMEWORKLIB RULES
guidelines.
******************************************************************************************
Find_smallest(A,n)
if(n==1) then
return A[1]
else
return min(A[n],Find_smallest(A,n-1))
T(n)=T(n-1)+ 1
T(n-1)=T(n-2)+ 1
T(n-2)=T(n-3)+ 1
T(n)=T(n-2)+ 1+ 1
T(n)=T(n-3)+ 1+ 1+ 1
T(n)= T(n-i)+i
when n -i =1 then i=n-1
T(n)= T(1)+ n-1= 1+n-1= n
if we solve the recurrence we get T(n)=n
(a) Give the pseudo-code for a recursive algorithm called Find_Smallest(A, n) that returns the value of...
07-15 pts) Develop a recursive version of the Bubble Sort algorithm. (a) Write the pseudo code of the algorithm and justify that it is recursive and works correctly Write the recurrence relation for the algorithm and solve it using one of the two approaches discussed in class, as appropriate. Solve the recurrence relation and show that the time complexity of the recursive algorithm is θ(n).
Consider the following: Algorithm 1 Smallest (A,q,r) Precondition: A[ q, ... , r] is an array of integers q ≤ r and q,r ∈ N. Postcondition: Returns the smallest element of A[q, ... , r]. 1: function Smallest (A , q , r) 2: if q = r then 3: return A[q] 4: else 5: mid <--- [q+r/2] 6: return min (Smallest(A, q, mid), Smallest (A, mid + 1, r)) 7: end if 8: end function (a) Write a recurrence...
The following algorithm (Rosen pg. 363) is a recursive version of linear search, which has access to a global list of distinct integers a_1, a_2,..., a_n. procedure search(i, j, x : i,j, x integers, 1 < i < j < n) if a_i = x then return i else if i = j then 4. return 0 else return search(i + 1, j, x) Prove that this algorithm correctly solves the searching problem when called with parameters i = 1...
When asked to describe an algorithm you are expected to give a clear pseudo-code description of the algorithm 1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...
ngu Cons eY Ja Question 1 a) Write pseudo code to output a singly-linked list in reverse order when you are NOT allowed to allocate memory dynamically. What is the running time of the algorithm? b) Write pseudo code to output a singly-linked list in reverse order when you are ALLOWED to allocate memory dynamically. What is the running time of the algorithm? c) You have an increasingly-sorted circular list (using an array) of n elements that is full. The...
Design an algorithm for the following description. Solution can be done in pseudo-code or steps of the algorithm. Describe and analyze an algorithm that takes an unsorted array A of n integers (in an unbounded range) and an integer k, and divides A into k equal-sized groups, such that the integers in the first group are lower than the integers in the second group, and the integers in the second group are lower than the integers in the third group,...
2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting the left side, sorting the right side, and then merging them. Write a similar recursive algorithm that finds the maximum element of an array. (Find the max of the left side, then find the maximum of the right side, then compare the two.) Write pseudo-code for this algorithm. Give the recurrence relation that describes the number of comparisons that your algorithm uses.
Give an example of either iterative or recursive algorithm that has Ө( log n) running time. Give detailed time performance analysis (recurrence relation for recursive)
Write a pseudo code of an algorithm that returns "yes" if the input array (contains integers) is a palindrome, and no if it is not (means first item is the same as last one, second one is the same as second from the last & ...)
(20 points) Recall the following deterministic select algorithm: (a) Divide the n elements into groups of size 5. So n/5 groups. (b) Find the median of each group. (c) Find the median x of the n/5 medians by a recursive call to Select. (d) Call Partition with x as the pivot. (e) Make a recursive call to Select either on the smaller elements or larger elements (de- pending on the situation); if the pivot is the answer we are done....