JFE301Xuất hiện trong 1 đề thi
The steps below are used to sort a dataset in descending order by using a max heap. [Steps] 1. Extract an element one by one from an unsorted dataset, and insert it into a max heap until all the elements are extracted and inserted. 2. Delete the root element from the max heap, and store it in a sorted dataset. Stop if all the elements are deleted. Otherwise, go to Step 3. 3. Move the rightmost element on the deepest level to the root. Go to Step 2 if the remaining elements are in the correct order as a max heap (that is, all the parent elements are greater than or equal to their corresponding child elements). Otherwise, go to Step 4. 4. Compare the replaced element with its children, and then exchange the element for its larger child. Go to Step 2 if all the elements are in the correct order as a max heap. Otherwise, continue Step 4 toward deeper levels. \nIn the max heap shown below, how many element exchanges in Step 4 are executed to build the next max heap after deletion of the root “5” in Step 2? \nmermaid\ngraph TD N5[5] --> N4[4] N5 --> N1[1] N4 --> N3[3] N4 --> N2[2]
Các lựa chọn
A1
B0
C2
D3