Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

1. Suppose you have an array of n items (the "member items") and a separate list of k items (the "test items"). The member items are not stored in any particular order. You want to know which of the k test items belong to the set of member items. Here are two di?erent ways to solve the problem:

• Algorithm 1: Look up each test item in the array of member items, using sequential search.

• Algorithm 2: Sort the array of member items, using an optimal comparison- based sorting algorithm, and then look up each test item in the array of member items using binary search. Answer the following problems, and brie?y justify your answer to each part. (a) What is the worst-case running time of Algorithm 1 (asymptotically, in terms of n and k)? (b) What is the worst-case running time of Algorithm 2 (asymptotically, in terms of n and k)? (c) For a given value of n, for what values of k is Algorithm 2 at least as e?cient as Algorithm 1? (Express your answer using asymptotic notation, in terms of n). 2. Suppose we are given n numbers, initially stored in an array A and we wish to sort them. When the sort concludes, the sorted output is to be in the array A, in ascending order (i.e., the smallest value in A[0], the next smallest in A[1], etc.). Suppose we use, as our measure of time, the number of times we store a value into the array. In other words,

• If x is any value, an assignment statement of the form A[i] = x has a cost of 1. In particular, an assignment statement of the form A[i] = A[j ] has a cost of 1.

• Any other operation (including a comparison between two array items A[i] and A[j ], or an assignment x = A[i] where x is not a location in the array A) has a cost of 0. (a) Under this cost model, give a lower bound on the worst-case time required to sort the array A. Your answer should be an exact expression in terms of n (i.e., it should not involve asymptotic notation). (b) Describe a sorting algorithm that is optimal with respect to this cost model and uses O(n) space. That is, time used by your algorithm should exactly match the lower bound given in (a).) describe why your algorithm satis?es the cost and space requirements. 1 (c) Describe an in-place sorting algorithm that is optimal with respect to this cost model. That is, the time used by your algorithm should exactly match the lower bound given in (a).) describe why your algorithm satis?es the cost requirement and is in-place. 3. De?ne a sorting algorithm to be parsimonious if it never compares the same pair of input values twice. (Assume that all the values being sorted are distinct.) For ex, it was shown in the notes that quicksort is parsimonious. (a) Is insertion sort parsimonious? Justify your answer with either a counterex or a brief argument. (b) Is merge sort parsimonious? Justify your answer with either a counterex or a brief argument. (c) Is heap sort parsimonious? Justify your answer with either a counterex or a brief argument.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9114457

Have any Question?


Related Questions in Computer Engineering

At a certain temperature this reaction establishes an

At a certain temperature, this reaction establishes an equilibrium with the given equilibrium constant, Kc. Kc = 1.53 * 10^21 3A (g) + 2B (g) ------> 4C(g) If, at this temperature, 1.50 mol of A and 4.00 mol of B are pla ...

A cell phone company offers 15 different voice packages and

A cell phone company offers 15 different voice packages and 15 different data packages. Of those, 6 packages include both voice and data. How many ways are there to choose either voice or data, but not both?

Question what role should platform providers play in social

Question : What role should platform providers play in social dis-course? Do these technology companies have an obligation to understand the impacts they are having on society? Do they have a responsibility to participat ...

What are some examples of marketing activities that are

What are some examples of "marketing" activities that are associated with the Summer Olympics? How does global marketing and the use of new digital marketing techniques facilitate marketing activities at the Olympics in ...

Suppose that you have 5000 and you are contemplating the

Suppose that you have $5000 and you are contemplating the purchase of two investments, IBM and Walgreen's. One year from now, IBM can be sold at $ X per dollar invested, and Walgreen's can be sold for $ Y per dollar inve ...

Suppose a punched card has 80 columns and 12 rowsa if any

Suppose a punched card has 80 columns and 12 rows. (a) If any number of holes can be punched in the card, how many different cards can there be. If more convenient, you may give your answer in the form of an expression. ...

Task define a class bubble with data members static int

Task : Define a class Bubble with data member's static int objCount and 2D integer array mat [10] [10] and 2 integer members rows and cols. Define a default constructor which will increment objCount when an object is cre ...

Question creating an interface please respond to the

Question: "Creating an Interface" Please respond to the following: • Imagine you are managing a design project that will create an interface for automobile mechanics. The interface would be used by the mechanics to look ...

Question suppose we have a b-tree that holds keys and

Question : Suppose we have a B-Tree that holds keys and leaves. There are 100 million data records (N), and they are stored in the leaves (lowest level) of the B-Tree. Each leaf contains 100 data records. The leaves are ...

Suppose we evaluate the performance of a player based on

Suppose we evaluate the performance of a player based on the player's HR and RBI score. Assume each HR counts as 3 points while each RBI counts as 2 points. Find the playerIDs who have the highest score. -Select a random ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As