(a) The best case running time is Θ(n)
(b) The worst case running time is also Θ(n)
(c) If L is already sorted, the the max element is the last element
in the list. The function can return L[n-1]. This algorithm is
useless as to sort the list it will take O(nlogn) time to sort
itself. So total time to find the max element will be O(nlogn).
Consider the following Python function: def find_max (L): max = 0 for x in L: if...
Question 4 CLO3 The following Python script implements an algorithm to find and prints the max value in a list of values. MAX 0 def MaxVal (Ist): for i in Ist: if( MAX < i): MAX = i return (MAX) Marks (20,24,26,19,5,31,24,32,32,45 print (MaxVal (Marks) a. Express the number of operations in terms of a function f(n), where n is the input size. (1 Mark) b. What is the total number of operations in the for loop of the algorithm...
Write a python code function that selects top ten max numbers from a sequence of n integers, test it, and determine the Big-Oh of running time for the algorithm (Do not have to prove) -1/i and Write a python recursive function for computing the nth Harmonic number, Hn= test it.
2. Here is a sorting algorithm that I like to use. Given an unsorted list of size n, let Xx represent the data in location k of the unsorted list. Compare xi to X2 and switch if necessary so that they are in sorted order, smallest first. Compare Xn-1 and Xn and switch if necessary so that they are in sorted order, smallest first. • Compare x3 with its left neighbors, switching if necessary so that the 3 first entries...
1. What is the worst case time complexity of insertion into a binary search tree with n elements? You should use the most accurate asymptotic notation for your answer. 2. A binary search tree is given in the following. Draw the resulting binary search tree (to the right of the given tree) after deleting the node with key value 8. 10 3. You have a sorted array B with n elements, where n is very large. Array C is obtained...
problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...
Python pls CENGAGE MINDTAP Q Search this course Programming Exercise 11.1 x Instructions search.py + >_ Terminal + A sequential search of a sorted list can halt when the target is less than a given element in the list. 1 " 2 File: search.py 3 Project 11.1 4 5 Optimizes sequential search for sorted lists. 6 The complexity is O(n) in the worst case and 0(1) in the best case. 7 The average case is less than n / 2,...
Question3 10 pts Let A [L.n] be a max-heap with n > 1 and consider the index ị such that l 〈 i 〈 n . Assume that all the elements of A are distinct. Write the pseudocode of an algorithm which replaces A [i] by A i 100 and then re-arranges the elements of A into a max-heap. The running time of your algorithm must be O (log, n Upload Choose a File Question3 10 pts Let A [L.n]...
For each problems segment given below, do the following: Create an algorithm to solve the problem Identify the factors that would influence the running time, and which can be known before the algorithm or code is executed. Assign names (such as n) to each factor. Identify the operations that must be counted. You need not count every statement separately. If a group of statements always executes together, treat the group as a single unit. If a method is called, and...
In python Programming Exercise 1 Write a function that will have a list as an input, the task of the function is to check if all the elements in the list are unique,( i.e. no repetition of any value has occurred in the list), then the function returns true otherwise it returns false. Your program should include a main method that call the method to test it. Algorithm Analysis For the function you implemented in part 1, please calculate T(n),...
7. (20 points) Assume L is a list, and assume that int n=L length() returns the number of elements in the list, and Bubblsort(L, 0,i) sorts the list from 0 to i usin the g the Bubble sort algorithm. Determine asymtotic running time as function of n, e(T(n), for the average case time for the following code fragments a) for( int i = 1;i < n; i* 2) Bubblsort (L,0,i); for( int i=0;i 7. (20 points) Assume L is a...