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
The program is the same as shown at the end of the Merge sort section, with the following changes:
- Numbers are entered by a user in a separate helper function, ReadNums(), instead of defining a specific array in main(). The first number is how many integers to be sorted, and the rest are the integers.
- Output of the array has been moved to the helper function PrintNums().
- An output has been added to MergeSort(), showing the indices that will be passed to the recursive function calls.
Add code to the merge sort
Add code at the end of main() that outputs "comparisons: " followed by the number of comparisons performed (Ex: "comparisons: 12")
Hint: Use a global variable to count the comparisons.
Note: Take special care to look at the output of each test to better understand the merge sort algorithm.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Similar questions
- use c language You wish to create a simple educational game for pre-school children to learn number sorting of either descending or ascending. Your program only supports 2-number sorting. Firstly, the program asks user for a preference, either descending (enter ‘d’ or ‘D)’ or ascending (enter’a’ or ‘A’). Then, it asks user to enter 2 numbers to sort and stores the 2 numbers in an array. Then, the program sort the numbers in ascending and descending order and store the sorted numbers (large, small) in SEPARATE array. Finally, it displaysarrow_forwardWrite a following functions to do the following operations on the int array b[20]: a. SetArr( ) to assign values for the array b[ ]. b. MaxArr( ) to find the maximum element of an array. c. SortArr( ) to sort any array in ascending order.arrow_forwardQuicksort SPLIT (the 2-pointer algorithm covered in class) is applied to the integer array [4,3,5,7,9,2,1], using the first entry as the pivot. Show the series of item swaps that are performed in the split process, and the array after each of these swaps, up to and including the step of placing the pivot at its correct location. You only need to show the split of the original array, you are not required to continue working on the subarrays after the split.arrow_forward
- Program by using "C language " my student number is : 1910206534arrow_forward1. The sorted values array contains 16 integers 5, 7, 10, 13, 13, 20, 21, 25, 30,32, 40, 45, 50, 52, 57, 60. Indicate the sequence of recursive calls that are made tobinaraySearch, given an initial invocation of binarySearch(32, 0, 15).show only the recursive calls. For example, initial invocation is binarySearch(45,0,15)where the target is 45, first is 0 and last is 15.arrow_forwardWrite the following function that merges two sorted lists into a new sorted list:def merge(list1, list2): Implement the function in a way that takes len(list1) + len(list2) comparisons. Write a test program that prompts the user to enter two sorted lists and displays the merged list.arrow_forward
- Write a program in C++arrow_forwardComplete my C++ program: Instructions: You have to continue on implementing your Array List namely the following functions: Example ArrayList: [10, 30, 40, 50] void addAt(int num, int pos) This method will add the integer num to the posth position of the list. Performing addAt(20, 2) in the example list will add 20 at the 2nd position and the array will now look like this: [10, 20, 30, 40, 50] When the value of pos is greater than the size + 1 or less than one, output "Position value invalid" void removeAt(int pos) Removes the number in the posth position of the list. Performing removeAt(3) in the example list will remove the 3rd element of the list and the updated array will be: [10, 30, 50] When the value of pos is greater than the size or less than one, output "Position value invalid" void removeAll(int num) Removes all instances of num in the array list. In this array [10, 10, 20, 30, 10], performing removeAll(10) will remove all 10's and the list will look like this: [20,…arrow_forwardugbarrow_forward
- //convert array of numbers from farenheit to celcius// example:// argument: [23, 32, 41, 50, 59]// return: [-5, 0, 5, 10, 15]// hint: use Array.mapfunction toCelcius(array){ } //write a function that takes an input array and returns an array of booleans (>=75) or fail (<75)// example:// argument: [20, 30, 50, 80, 90, 100]// return: [false, false, false, true, true, true]// hint: use Array.mapfunction passOrFail(array){ }arrow_forwardExercise 1: Write a main program that reads the elements of a 2 x 2 integer matrix, A, from the user. It then performs the following tasks: • prints the matrix row-by-row using a nested looping structure, • adds all matrix elements in row 0 using a looping structure and prints the sum. For example, for matrix, A| [i 3 A[2][2] = 7 9 The Sample Session will be as follows: CA Microsoft Visual Studio Debug Console Enter element at row 0 column 0: 1 Enter element at row e column 1: 3 Enter element at row 1 column 0: 7 Enter element at row 1 column 1: 9 The matrix entered by the user is: 13 7 9 Sum of row 0 elements: 4 C:\Users\User\source\repos \Project1\Debug\Project1.exe (process 52912) exited with code 0. Press any key to close this windowarrow_forwardDESIGN YOUR OWN SETTING Task: Devise your own setting for storing and searching the data in an array of non-negative integers redundantly. You may just describe the setting without having to give an explicit algorithm to explain the process by which data is stored. You should explain how hardware failures can be detected in your method. Once you have described the setting, include the following to your answer: Write a pseudocode function to describe an algorithm where the stored data can be searched for a value key: if the data is found, its location in the original array should be returned; -1 should be returned if the data is not found; -2 should be returned if there is a data storage error Include a short commentary explaining why your pseudocode works Describe the worst-case and best-case inputs to your search algorithm Derive the worst-case and best-case running times for the search algorithm Derive the Theta notation for the worst-case and best-case running timesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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