Question

Quicksort is an efficient sorting algorithm. Question: For the non-randomized version of Quicksort, what are the...

Quicksort is an efficient sorting algorithm.

Question:

For the non-randomized version of Quicksort, what are the best and the worst initial arrangements of the elements to be sorted? Justify your answer

Homework Answers

Answer #1

I believe you are learning quick sort.

Before i start to answer lets look at few insights,

Quicksort, select a pivot and pivot is the last element in the array,

Now, this pivot needs to be placed, at its right position, this means if we follow this procedure for every array value, array gets sorted.

Now lets look at,

BEST CASE

1 2 3 6 7 8 4

Now see, the pivot is 4, and its right position is 3 in the array that means after PARTITION we will have array like this,

1 2 3 4 6 7 8, now as you can see, pivot 4 has divided array into 2 equal arrays,

1 2 3 and 6 7 8

So we have n-1/2 and n-1/2, sizes of 2 arrays

Thus, this takes us to time complexity of

NlogN, best case

WORST CASE

1 2 3 4 5 6 7 8

If pivot is 8, it will divide array like

1 2 3 4 5 6 7 and 8

Which is n-1 and 1

This gives us time complexity of

N*N,

Now as you can see, if array is sorted in

Desc or Asc order, it will give you the WORST CASE.

Hope i helped you.

Happy Learning.

Know the answer?
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
Similar Questions
Python question The quicksort algorithm is a recursive algorithm that works by selecting an element, termed...
Python question The quicksort algorithm is a recursive algorithm that works by selecting an element, termed the pivot; dividing the original list into three parts, namely those that are greater than the pivot, those equal to the pivot, and those less than the pivot; and recursively sorting the first and third, appending the results to obtain the final solution. Write a quicksort method that accept a list of numbers and use list comprehension to construct the method. Note that you...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
step by step solution for the below question please Flag this Question Question 11 pts What...
step by step solution for the below question please Flag this Question Question 11 pts What is the difference between positive economics and normative economics? Group of answer choices Positive economics deals with dynamic systems, while normative economics focuses on static systems. Normative economics deals with how the world actually works, whereas positive economics focuses on what people ought to do. Positive economics requires making value judgments, while normative economics relies solely on factual statements. Normative economics applies in cases...
QUESTION 2 Securities that trade in the money markets are an example of what major asset...
QUESTION 2 Securities that trade in the money markets are an example of what major asset class? Cash Fixed Income Bonds None of the above QUESTION 12 Common stock is included in the equity asset class and represents a share of ownership rights in a company. True False QUESTION 15 Which answer best describes a Yankee bond? A bond issued in US dollars by a non-US company. A bond issued in US dollars by a US company. A bond issued...
Suppose that you want to add items to an array such that the items are always...
Suppose that you want to add items to an array such that the items are always ordered in ascending order; e.g., [1, 2, 2, 4, 5, 8, 9, 14, 32], and any duplicate values are adjacent to each other. We haven’t talked about sorting algorithms yet, so assume you want to be able to keep the items in the array in order without having to sort them. So for example, suppose you want to add the integer value 7 to...
QUESTION 1 ? What is the relationship between family dysfunction and schizophrenia? a. ?Research has substantiated...
QUESTION 1 ? What is the relationship between family dysfunction and schizophrenia? a. ?Research has substantiated a link between family dysfunction and schizophrenia but can't say which causes the other. b. ?Family dysfunction is a major causative factor for schizophrenia. c. ?Research has failed to substantiate a direct causal link between family dysfunction and schizophrenia. d. ?Family dysfunction plays a minor role in developing schizophrenia. 1.00000 points    QUESTION 2 ? Chuck has no life plan; he simply lives from...
Discussion Question: What would you do case? (CH10) DUE 5/6 The words “Cessna Skyhawk” have special...
Discussion Question: What would you do case? (CH10) DUE 5/6 The words “Cessna Skyhawk” have special meaning for anyone who has ever wanted to learn to fly. At 27 feet long and 8 feet tall, with a 36-foot wingspan, a 140 mph cruising speed, and room for two adults and their luggage, more people have learned to fly with a Cessna Skyhawk than with any other plane in aviation history. In fact, the Cessna Skyhawk is the best-selling plane of...
1. What is an ISP (Integrated Service Provider) for supply chains? (1 point) A. A consultant...
1. What is an ISP (Integrated Service Provider) for supply chains? (1 point) A. A consultant agency which integrates the supply chain for companies B. A 2 PL or a 3PL, but not a 4PL C. A company supplying transportation and warehousing services D. A logistics service company specialized in suppling VAS (value added services) 2. What characterizes a 4 PL? (1 point) A. They are non-asset based and provides integrated services primarily supplied by asset based providers, for example...
Question -Organizational change goes beyond promotions and the threat of layoffs. What ways other than those...
Question -Organizational change goes beyond promotions and the threat of layoffs. What ways other than those discussed in the case would you use to entice people to embrace proposed changes? Provide several suggestions and justify their rationale. CASE STUDY- Blue Cross and Blue Shield, and Others: Understanding the Science behind Change Kevin Sparks has been trying to get his staff to change the way it monitors and supports the data center for the past year, but he hasn’t been getting...
read Seasons of Love chapter:measuring a child's life after suicide. please answer the questions : reflect...
read Seasons of Love chapter:measuring a child's life after suicide. please answer the questions : reflect on what happens to the families when there is a suicide in the family, based on the Seasons of Love chapter...how should people be told? What details are best left unshared? below is the story These theories may have a certain face-validity, but they often neglect environmental or contextual factors that are innate to answering the question of “why” a person might engage in...