
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
![Show how the mergesort algorithm executes on the string MATERIAL
You should recall from lecture that we can use a graph to visualize the merge sort algorithm. At the very top of the
graph, you have one node representing the original input list. At the very bottom, you have one node representing a
sorted version of your input list. In the midle, you have nodes and edges representing the steps you take to execute
merge sort.
For this question, you are to execute the merge sort algorithm and show your work, with the provided string for
input. You will consider each character in the input string as an element in an input list to merge sort. For example,
the string "HELLO" would mean you input the list ["H", "E", "L", "L", "O"] into the merge sort algorithm.
Fòr convenience, the pseudocode of the mergesort algorithm is shown below:
MergeSort(array V, int p, int r) {
if (p = r) then // do nothing
else {
// we have at least 2 items
q = (p + r)/2
MergeSort(V, p, q) // sort V[p..a]
MergeSort(V, q+1, r) // sort V[q+1.r]
Merge(V, p, q, r) // merge everything together
Merge(array V, int p, int q, int r) {
// merges V[p..g] with V[q+1.r]
// declare a temporary array S to store
// the sorted sequence
array S[p..r]
i = k = p// initialize pointers
j = q+1
while (i <= q and j <= r) {
// while both subarrays are nonempty
if (V[i] <= V[j]) then
// copy from left subarray
S[k++] = V[i++]
else
// copy from right subarray
S[k++] = V[i++]
%3D
// copy any leftover to S from the left subarray
while (i <= q) do
S[k++] = V[i++]
// copy any leftover to S from the right subarray
while (j <= r) do
S[k++] = V[j++]
// copy S back to V
for i = p to r do V[i) = S[i]
%3D
%3D](https://content.bartleby.com/qna-images/question/183ee7e8-b711-4dd7-b072-d0d5e1b740e4/c611d375-1ac1-4fd7-8857-c45c4efe7898/po73j4o_thumbnail.jpeg)
Transcribed Image Text:Show how the mergesort algorithm executes on the string MATERIAL
You should recall from lecture that we can use a graph to visualize the merge sort algorithm. At the very top of the
graph, you have one node representing the original input list. At the very bottom, you have one node representing a
sorted version of your input list. In the midle, you have nodes and edges representing the steps you take to execute
merge sort.
For this question, you are to execute the merge sort algorithm and show your work, with the provided string for
input. You will consider each character in the input string as an element in an input list to merge sort. For example,
the string "HELLO" would mean you input the list ["H", "E", "L", "L", "O"] into the merge sort algorithm.
Fòr convenience, the pseudocode of the mergesort algorithm is shown below:
MergeSort(array V, int p, int r) {
if (p = r) then // do nothing
else {
// we have at least 2 items
q = (p + r)/2
MergeSort(V, p, q) // sort V[p..a]
MergeSort(V, q+1, r) // sort V[q+1.r]
Merge(V, p, q, r) // merge everything together
Merge(array V, int p, int q, int r) {
// merges V[p..g] with V[q+1.r]
// declare a temporary array S to store
// the sorted sequence
array S[p..r]
i = k = p// initialize pointers
j = q+1
while (i <= q and j <= r) {
// while both subarrays are nonempty
if (V[i] <= V[j]) then
// copy from left subarray
S[k++] = V[i++]
else
// copy from right subarray
S[k++] = V[i++]
%3D
// copy any leftover to S from the left subarray
while (i <= q) do
S[k++] = V[i++]
// copy any leftover to S from the right subarray
while (j <= r) do
S[k++] = V[j++]
// copy S back to V
for i = p to r do V[i) = S[i]
%3D
%3D
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- Question 3 Full explain this question and text typing work only havearrow_forwardThe interchange implementation was supposed to be better than the transpose implementation as it implements the same algorithm without the need of copying the 640,000 elements. However, it is not. How do you explain this inconsistency?arrow_forwardDescribe your algorithmarrow_forward
- The algorithm: –In an array of n elements, go to index [n/2] –If the record there is the one you want, you are done –If the record value there is smaller than your search value, all records less than the current record can be ignored – set your search range of elements to [n/2+1…n] and return to step 1 –Otherwise, set your range of elements to [0…(n/2)-1] and return to step 1 –Repeat this loop until you have 0 elements (record is not found) or record is found Short answer Another approach to the update algorithm is to perform use the delete function for the old value and if it is successful, call the insert function using the new value. Explain in your own words if you think this approach is significantly better, worse, or in the same category as the algorithm discussed in the slides, and why.arrow_forwardthere are similar questions please come up with an original answer because the questions are slighty different, thank you.arrow_forwardUse Python Code correctly to solve this problem and also give the output.arrow_forward
- Assume you are playing a card game using a standard 52-card deck. You are dealt a hand of cards that are all the same suit, spades. You are dealt first a 5, then a 3, then 8, and finally 4. You first took the 5 into your hand. Then you put the three before the 5. Next you put the 8 behind the 5. Finally, you put the 4 between the 3 and 5. Which sorting algorithm is most similar to how you sorted your hand? Group of answer choices 1. Quick Sort 2. Insertion Sort 3. Merge Sort 4. Selection Sortarrow_forwardConsider a situation of a boarding gate of a plane where passengers are allowed to board on the place based on their age. All passengers are on a line (queue) to board on the place, however, the oldest one is always allowed to board first no matter when he/she got in the line (queue). In this case, you cannot sort the passengers by their age, however, you know that oldest ones are always at the top of the line. This is an example of a priority queue where data will be accessed and processed based on their level of priority. Suppose you need to organize such type of data so that the data in highest priority can be accessed in a constant time, O(1). What type of data structure would you use in such cases? Justify your answer.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY