Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Activity 4 . 5 . 2 : Selection Sort Consider the following algorithm on an array of numbers x 1 , x 2 , x

Activity 4.5.2: Selection Sort
Consider the following algorithm on an array of numbers x1, x2, x3,..., xn.
The element in the first position is compared to the n 1 remaining elements; whenever one is found that is less, the first element is swapped with it. Then the element in the second position is compared with the remaining n 2 elements. Whenever one is found that is less, the elements are swapped. This continues until the (n1)st element; if it is out of order with the nth element, the elements are swapped. The algorithm pseudocode is shown below:
The selection sort algorithm
Step through this algorithm when applied to the array x1=9, x2=4, x3=7, x4=1. Record the values of the array every time they change.
In terms of n, how many comparisons does this algorithm make on an array of length n?
Activity 4.6.2: Big-O Notation
Let g(n)=7n +90 and f(n)=2n.
Suppose K =3. Is there a value of N >0 such that g(n)<= K f (n) for all n >= N ? If so, what value works? If no such value exists, explain why.
Suppose K =5. Is there a value of N >0 such that g(n)<= K f (n) for all n >= N ? If so, what value works? If no such value exists, explain why.
Is g O(f)? Justify your answer using the definition.
Let g(n)=3n2+100. Use the definition to show that g O(n2). Specifically, find values of K and N that satisfy the definition, where f(n)= n2.
Let g(n)= n3. Prove, by contradiction, that g O(n2), by completing the following steps.
Suppose, to the contrary, that g in O(n2). Then the definition of big-O says that there are numbers K and N and an inequality involving K and n that must hold for all n >= N . Write this inequality.
Explain why the above inequality leads to a contradiction.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

3. Give short, clear directions before, not during, transitions.

Answered: 1 week ago