What is wrong if lines 6–15 in Listing 23.6, MergeSort.java, are replaced by the following code?
// Merge sort the first half
int[] firstHalf = new int[list.length / 2 + 1];
System.arraycopy(list, 0, firstHalf, 0, list.length / 2 + 1);
mergeSort(firstHalf);
// Merge sort the second half
int secondHalfLength = list.length - list. length / 2 - 1;
int[] secondHalf = new int[secondHalfLength];
System.arraycopy(list, list.length / 2 + 1,
secondHalf, 0, secondHalfLength);
mergeSort(secondHalf);
Want to see the full answer?
Check out a sample textbook solutionChapter 23 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Starting Out with Programming Logic and Design (4th Edition)
C++ How to Program (10th Edition)
Artificial Intelligence: A Modern Approach
Introduction To Programming Using Visual Basic (11th Edition)
- 1-Let the list have a head and a tail. That is, a pointer (have a marker) to both the beginning (first Node) of the list and the last Node. What process does Tail facilitate? 2-insert(int index, int element): adds this element to the index position. For example, if index is 4, it adds this element between index 3 and 4 in the list. The size of the list has increased by one. 3-append(int elem): Adds the element to the end of the list. The size of the list has increased by one. 4-get(int index): Returns the element at the index position of the list, no change in the list. 5-remove(int index): Returns the element at the index position of the list. This element is removed from the list and the list size is reduced by one. 6-findMin(): returns the index of the smallest number in the list. 7-findMax(): returns the index of the largest number in the list. 8-search(int elem): searches elem in the list. It returns -1 when you can't find elem's index when you find it. 9-ToArray(): Return an…arrow_forwardCreate a list – l1 with element 1,2,3,4,5. Convert this list into an array name ar. What is the dimension of this array – one dimension, 2 dimension or multidimension What is the datatype of elements of array. Print the second element of an array. Create a nested list – l2 with three lists. Elements of each lists are – [1,2,3];[4,5,6];[7,8,9] Convert this list into an array ar2. What is the dimension of this array. Observe the parenthesis. Print 8 from this array. Without using list, create an array ar3, which has the even number from 2 -10. Use the np.arange(start, end, skip). Run the following code and observe the output.arrow_forward1-Let the list have a head and a tail. That is, a pointer (have a marker) to both the beginning (first Node) of the list and the last Node. What process does Tail facilitate? 2-insert(int index, int element): adds this element to the index position. For example, if index is 4, it adds this element between index 3 and 4 in the list. The size of the list has increased by one. 3-append(int elem): Adds the element to the end of the list. The size of the list has increased by one. 4-get(int index): Returns the element at the index position of the list, no change in the list. 5-remove(int index): Returns the element at the index position of the list. This element is removed from the list and the list size is reduced by one. 6-findMin(): returns the index of the smallest number in the list. 7-findMax(): returns the index of the largest number in the list. 8-search(int elem): searches elem in the list. It returns -1 when you can't find elem's index when you find it. 9-ToArray(): Return an…arrow_forward
- 5. The following function indexCounter aims to find and return all the indices of the element x in a list L. if x is not in the list L, return an empty list. However, the implementation has a flaw, so that many times it will return error message. Can you fix the flaw? def indexCounter(L, x): indexList [] startIndex = 0 while startIndex < len(L): indexList.append (L.index (x, startIndex)) startIndex = L.index (x, startIndex) + 1 return indexListarrow_forwarddef find_missing(input_list): sum_of_elements = sum(input_list) # There is exactly 1 number missing n = len(input_list) + 1 actual_sum = (n * ( n + 1 ) ) / 2 return int(actual_sum - sum_of_elements)list_1 = [1,5,6,3,4] find_missing(list_1)# 2.arrow_forwardConsider the following list: int list[] = (14, 18, 29, 35, 44, 49, 55, 58, 66, 71, 75, 80, 89, 95, 98) %3D When performing a binary search for 75, after the first comparison, the search is restricted to O list[8].. .list[14] O list [5]...list[11] O list[0].. .list[7] O list [0]. . .list[6]arrow_forward
- def update_grid(grid: List [List [str]], w: int, h: int, px: int, py: int, dx: int, dy: int) -> Optional [Tuple [int, int]]: Given the player's current position as px and py, and the directional changes in dx and dy, update the given grid to change the player's x-coordinate by dx, and their y-coordinate by dy. More information: Use the given w and h (representing the grid's width and height) to figure out whether or not the move is valid. If the move is not valid (that is, if it is outside of the grid's boundaries), then NO change occurs to the grid. The grid stays the same, and nothing is returned. If the move IS possible, then the grid is updated by adding dx to the player's x-coordinate, and adding dy to the player's y-coordinate. The new position in the grid is changed to the player icon ' (x)', and the old position the player used to be in is changed to an empty space 'O'. The new x- and y coordinates of the player is returned as a tuple. This function does NOT create or return a…arrow_forwardUsing java, write an easier version of a linked list with only a couple of the normal linked list functions and the ability to generate and utilize a list of ints. The data type of the connection to the following node can be just Node, and the data element can be just an int. You will need a reference like (Java) or either a reference to the first node, as well as one to the last node. (Answer the following questions) 1) Create a method or function that accepts an integer, constructs a node with that integer as its data value, and then includes the node to the end of the list. If the new node is the first one, this function will also need to update the reference to the first node. This function will need to update the reference to the final node. Consider how to insert the new node following the previous last node, and keep in mind that the next reference for the list's last node should be null. 2) Create a different method or function that iteratively explores the list, printing…arrow_forwardWhat is stored in list after the following C++ code executes? int list[8];list[0] = 1;list[1] = 2; for (int i = 2; i < 8; i++){list[i] = list[i – 1] * list[i – 2];if (i > 5)list[i] = list[i] - list[i - 1];}arrow_forward
- Java - What is the resulting list after shell sort with a gap value of 1?arrow_forwardin C++ Write a method ‘void addBack(double x)’ that adds value x to the back of a linked list. Assume you have access to a ‘head’ pointer pointing to the first node in the list. Please note that you do NOT have a tail pointer. Be sure to check for any special cases.arrow_forwardYou will reverse your student ID by the linked list of Struct in C!!!! Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Create a linked list and insert your student ID elementwise to the list. Reverse the linked list and printout the result. Hint: You can use additional pointers to reverse the linked list. You can also use a stack and then simply assign the element to the stack and it will be reversed. Linked list, Stack, Queue example source code is available on week 7 resources section.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education