Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the obvious algorithm for chocking whether a list of integers is sorted: start at the beginning of the list, and scan along until we
Consider the obvious algorithm for chocking whether a list of integers is sorted: start at the beginning of the list, and scan along until we first find a successive pair of elements that is out of order. In that case, return false. If no such pair is found by the time we reach the end of the list, return true. Our elementary operation is a comparison between two integers. (a) What is the worst case running time of this algorithm on an input list containing n elements? Write all 5-element input lists which contain the numbers 1, 2, 3, 4, 5 and yield the worst case. (b) What is the best case running time of this algorithm on an input list with n elements? How many input lists are there which have size n, all elements being different, and yield the best case? (c) Suppose that the input list is a random permutation of 1, 2, ..., n and all such permutations are equally likely. Derive the average-case expected running time. Give both an exact and asymptotic
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started