Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: Write another partition method to partition an array into left sublist and right sublist based on a pivot value in the quick sort

Question 1:

Write another partition method to partition an array into left sublist and right sublist based on a pivot value in the quick sort algorithm. All values in the left sublist are less than the pivot value, and all values in the right sublist are greater than or equals the pivot value.

When doing partitioning, using a start variable referencing the beginning of the array, and last variable referencing the ending of the array. We will still use the middle element as pivot value. Scan the array from both directions. If A[start] < pivot value, move start 1 position right, otherwise stop. If A[last] > pivot value, move last 1 position left, otherwise stop. Then swap A[start] and A[last]. Repeat the same process until start is the same as last. Then swap the pivot value with A[start] to finish the partition.

For example:

35 20 18 46 28 58 73 15 56 87

pivot value: 28

first we swap 35 with 28

start: index 1

last: index 9

20 < 28, move start to index 2. 18 < 28move start to index 3. 46 > 28, start stays here. endOfLeftList = index 2

87 > 28, move last to index 8, 56 > 28, move last to index 7. 15 < 28, last stays here

swap 46 with 15, endOfLeftList = 3.

swap pivot value with A[endOfLeftList]

Question 2: Implement the quick sort using the partition method defined in question 1.

Question 3: Analyze the time efficiency for your quick sort algorithm and get the big O of the algorithm.

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

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago