Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Q. Explain the complexity of an algorithm?  What are the worst case analysis and best case analysis explain with an example.                                                                                                                

Ans:

The complexity of the algorithm M is the function f(n) which gives the running time or storage space requirement of the algorithm in terms of the size n of the input data. Frequently, the storage space needed by an algorithm is just a multiple of the data size n. Therefore, the term "complexity" should be referring to the running time of the algorithm.

We find the complexity function f(n) for the certain number of cases. The two cases to which one usually investigates in complexity theory are as follows:-
i. The worst case:-  the maximum value of f(n) for any input possible
ii. The best case:-  the least possible value of f(n)

For example:-

Hear if we take an example of linear search in which an integer Item is to searched or found in an array Data. The complexity if the search algorithm is given by number C of comparisons between Item and Data[k].

Worst case:-

The worst case occurs when the Item is last element in the array Data or is it not there at all. In both of these cases, we get

C(n)=n

In the average case, we presume that the Item is present is the array and is likely to be present in any position in the array. Hence the number of comparisons can be any of the numbers 1, 2, 3........n and each number occurs with probability

p = 1/n.

C(n) = 1. 1/n + 2.1/n + ... + n.1/n

= (n+1) / 2

hence the average number of comparisons needed to locate the Item in to array Data is approximately the same to half the number of elements in the Data list.

Computer Engineering, Engineering

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

Have any Question?


Related Questions in Computer Engineering

For the following c statement what is the corresponding

For the following C statement, what is the corresponding RISC-V assembly code? Assume that the variables f, g, h, and i are given and could be considered integers as declared in a C program. Use a minimal number of assem ...

For the following c statement what is the corresponding

For the following C statement, what is the corresponding RISC-V assembly code? Assume that the variables f, g, h, and i are given and could be considered integers as declared in a C program. Use a minimal number of assem ...

Question suppose three items r s and t are placed in a

Question : Suppose three items R, S, and T are placed in a queue in that order. Then one item is removed from the queue before a fourth item, X is placed in the queue. Then one item is removed from the queue, the items Y ...

You are given a test to enter graduate school you must

You are given a test to enter graduate school. You must select 10 of the 13 essay questions to answer to determine your writing skills. How many ways can you select those questions?

Is there any difference in terms of the information that

Is there any difference in terms of the information that could be provided to the decision maker by an IS that was created using HSM and an IS that was created using SSM?

Can someone please wirte a complete algorith in c language

Can someone please wirte a complete algorith in c language that works without any errors on Visual Studio 2015 Given a list of integers, write a C function, similar to the partition process in QuickSort, that will rearra ...

Question a file is to be shared among different processes

Question : A file is to be shared among different processes, each of which has a unique id number and a priority level number. The file can be accessed simultaneously by several processes, subject to the following constr ...

The sales figures for a business are as follows for the

The sales figures for a business are as follows for the first six months of the year: R40 000, R44 000, R52 000, R64 000, R80 000, R84 000. The owner believes that the sales curve can be approximated by a quadratic funct ...

You are the senior consultant at abacus consulting tasked

You are the Senior Consultant at Abacus Consulting, tasked with the database project for Amadeus Real Estate client. The company employs real estate agents who work with customers to buy and sell properties (both residen ...

Assume newspaper for garbage or recycling has a standard

Assume newspaper for garbage or recycling has a standard deviation of 2 pounds. If we want to estimate the average amount of newspaper for garbage or recycling within .25 pounds with 90% confidence, how many households m ...

  • 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