Question

We are given an array A holding n integers, for some large n. The array is...

We are given an array A holding n integers, for some large n. The array is sorted, and the
values in A range from -2147483648 to 2147483647, evenly distributed. Give Θ expressions
for the following tasks:
A. Running the insertion sort algorithm on the array A:
B. Running the selection sort algorithm on the array A:
C. Performing binary search for integer k which is not in A:
D. Performing interpolation search for integer k not in A:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A. Running the insertion sort algorithm on the array A:

(N), Insertion Sort takes (N) in best case as the Input is Sorted

B. Running the selection sort algorithm on the array A:


(N2), Selection Sort takes (N2) in worst case nd does not care much about the input. Even with Sorted Input it takes

(N2) time

C. Performing binary search for integer k which is not in A:

(Log N), Binary search space reduces by half hence it takes (Log N) time

D. Performing interpolation search for integer k not in A:

In worst case it can take upto O(n), hence (N)

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
We are given an array A holding n integers, for some large n. The array is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 10: Given an array of data: array1 10 5 15 2 7 21 Write the...

    Question 10: Given an array of data: array1 10 5 15 2 7 21 Write the code for the selection sort to sort the data and draw a table showing how the data is sorted using selection sort. Write the code for Binary search algorithm to find the value 15 from the sorted array. Draw the tree diagram showing the binary search of the list.

  • Please Use C++ Language. And Note that please donot post the answer already there Because there...

    Please Use C++ Language. And Note that please donot post the answer already there Because there is similar answer code but I need with modified Quick sort algorithm ​. Update your program from ... Create an array that holds 1000 random integers between 1-1000. Allow the user to enter an integer to search. Create and implement modified Quick sort algorithm which will sort the array before the Binary Search algorithm is executed. Create and implement a Binary Search Algorithm ....

  • Java: Write an application that has an array of at least 20 integers. It should call...

    Java: Write an application that has an array of at least 20 integers. It should call a method that uses the sequential search algorithm to locate one of the values. The method should keep a count of the number of comparisons it makes until it finds the value. Then the program should call another method that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these...

  • Given an n-element unsorted array A of n integers and an integer k, describe and implement...

    Given an n-element unsorted array A of n integers and an integer k, describe and implement a recursive algorithm for rearranging the elements in A so that all elements less than or equal to k come before any elements larger than k. What is the running time of your algorithm? Please prove the running time in the comments . in c++ please

  • Suppose you are given an array A holding n distinct integers (negative values are allowed) in...

    Suppose you are given an array A holding n distinct integers (negative values are allowed) in sorted order; in other words, A[i] < A[i + 1] for each i ∈ [0, n − 2]. We say the ith element is self referential if A[i] = i. Design an O(log n) time algorithm to determine if there is a self referencial element in the array. Your solution must include a) Statement of your algorithm in plain English. (Pseudo-code is optional.) b)...

  • An array A of n integers is called semi-sorted if it is increasing until some index...

    An array A of n integers is called semi-sorted if it is increasing until some index and then decreasing afterwards. In other words, there is some index 1 ≤ p ≤ n such that: • A[i] < A[i + 1] for 1 ≤ i < p, and • A[i] > A[i + 1] for p ≤ i < n. Note that in this case, A[p] is the maximum element of A. Give an algorithm with running time O(logn) that finds...

  • Declare an array of integers of size 8 and initialize it with any non-duplicate integer values...

    Declare an array of integers of size 8 and initialize it with any non-duplicate integer values you like. Don’t enter the values in any order. Print the unsorted array. Sort the array using selection sort or insertion sort in descending order. Print what sort you are using. Write any additional functions that you need for sorting. Keep monitoring the number of comparisons and number of swaps performed while sorting. Report both after sorting. Print the sorted array. in C++

  • Given an unsorted array of distinct positive integers A [ 1......n ] in the range between...

    Given an unsorted array of distinct positive integers A [ 1......n ] in the range between 1 and 10000 and an integer i in the sane range. Here n can be arbitrary large You want to find out whether there are 2 elements of the array that add up to i. Give an algorithm that runs in time (O(n).

  • The input is an array of N integers ( sorted ) and an integer X. The...

    The input is an array of N integers ( sorted ) and an integer X. The algorithm returns true if X is in the array and false if X is not in the array. Describe an algorithm that solves the problem with a worst case of O(log N) time.

  • Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case...

    Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT