![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 27.04.2021 15:40 gavianacandelar8522
Consider the Partition algorithm we discussed in class.
Partition(A)
pivot = A[0], i = 1, j = A. length-1; // Let the leftmost element be the pivot
while i<=j // Rearrange elements
while i < A. length-1 & A[i] < pivot,
i = i + 1
end while
while j > 0 & A[j] >= pivot,
j = j - 1
end while
if i >= j
break
end if
swap A[i] and A[j]
end while
swap A[0] and A[j]
return j; // Return the index of pivot after the partition
Upon completion of the Partition algorithm, the pivot element would be placed in the middle, elements less than pivot are placed on the left of pivot, and elements greater than or equal to pivot are placed on the right of pivot.
Given a list (A) of n elements, outline an O(n) time in-space algorithm based on the Partition algorithm such that upon completion of the algorithm, elements equal to the pivot (including the pivot element) would be placed in the middle, elements less than pivot are placed on the left of pivot, and elements greater than pivot are placed on the right of pivot.
For example, let A be {1, 2, 2, 2, 6, 1, 7, 0, -5, 2, 8, 1, 3, 1, 1}.
Let the first element 1 be the pivot.
If you call the original Partition method on list A, A would become:
{0, -5, 1, 2, 6, 1, 7, 2, 2, 2, 8, 1, 3, 1, 1}.
This problem asks you to design an algorithm, such that list A would become
{0, -5, 1, 1, 1, 1, 1, 2, 6, 7, 2, 2, 2, 8, 3}, such that the pivot 1 and all the other 1’s would be placed in the middle of the array, elements less than 1 would be on the left of all 1’s, and elements greater than 1 would be on the right of all 1’s.
Full credit (10 points) will be awarded for an algorithm that is O(n) and in-place. Algorithms that are NOT in-place or O(nlogn) or slower will be scored out of 3 points.
Note: In-place means no new arrays or extra data structure can be used.
a) describe the idea behind your algorithm in English
b) provide pseudocode
c) analyze its running time
![ansver](/tpl/images/cats/User.png)
Answers: 2
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Another question on Computers and Technology
![question](/tpl/images/cats/informatica.png)
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 06:30
To become an audio technician, the most successful tactics might include the following. (select all that apply). learning how to persuade other people gaining different types of experience in audio technology learning as much as possible about art history establishing a reputation as a reliable professional
Answers: 1
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 23:30
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
![question](/tpl/images/cats/informatica.png)
Computers and Technology, 24.06.2019 11:00
Why is it uncommon for users to perform searches directly in database tables? a.)users are discouraged from interacting directly with tables because they might confuse tables with spreadsheets. b.) users are discouraged from interacting directly with tables because this may result in unintended changes to source data. c.)users do not have the technical skills required to perform searches directly in database tables. d.)users do not have the permissions required to perform searches directly in database tables.
Answers: 1
You know the right answer?
Consider the Partition algorithm we discussed in class.
Partition(A)
pivot = A[0], i = 1, j...
pivot = A[0], i = 1, j...
Questions
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/health.png)
Health, 30.01.2020 16:51
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 30.01.2020 16:51
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/istoriya.png)
History, 30.01.2020 16:51
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 30.01.2020 16:51
![question](/tpl/images/cats/health.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 30.01.2020 16:51
![question](/tpl/images/cats/health.png)
Health, 30.01.2020 16:51
![question](/tpl/images/cats/mat.png)
Mathematics, 30.01.2020 16:51
![question](/tpl/images/cats/istoriya.png)
History, 30.01.2020 16:51
![question](/tpl/images/cats/mat.png)
Mathematics, 30.01.2020 16:51
![question](/tpl/images/cats/en.png)
English, 30.01.2020 16:51