Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, a path is any sequence of edges that leads from the root to a leaf of a tree. The length of a

In this problem, a path is any sequence of edges that leads from the root to a leaf of a tree. The length of a path is the number of edges it traverses. So a path from A to B to C to D has length 3.

Here is the pseudocode for standard mergesort:

// Sorts A[lo .. hi] into ascending order mergesort_normal (A, lo, hi) if (hi-lo >= 1) mid = (lo+hi)/2 mergesort(A, lo, mid) mergesort(A, mid+1, hi) merge(A, lo, mid, hi)

Here is an optimized version that performs the merge operation only if the last element of the first half of the array is greater than the first element of the second half of the array:

// Sorts A[lo .. hi] into ascending order mergesort_optimized (A, lo, hi) if (hi-lo >= 1) mid = (lo+hi)/2 mergesort(A, lo, mid) mergesort(A, mid+1, hi) if (A[mid] > A[mid+1] merge(A, lo, mid, hi)

Suppose you draw two decision trees for both mergesorts when applied to an array of 4 elements. What will be the exact length of the longest and shortest paths in the tree for both of these trees?

What is the shortest length of the decision tree for mergesort_optimized when applied to an array size image text in transcribed?

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

Step: 3

blur-text-image

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

Students also viewed these Databases questions