EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
implement merge-sort multithreadA is an array and p and q indexes of the array such as you gonna sort the sub-array A[p..r]. B is a sub-array which willbe populated by the sort.A call to p-merge-sort(A,p,r,B,s) sorts elements from A[p..r] and put them in B[s..s+r-p]
Code only_Given an unsorted array A of size N that contains only positive integers, find a continuous sub-array that adds to a given number S and return the left and right index(1-based indexing) of that subarray.
In case of multiple subarrays, return the subarray indexes which come first on moving from left to right.
Note:- You have to return an ArrayList consisting of two elements left and right. In case no such subarray exists return an array consisting of element -1..
Create a bottom-up mergesort that takes advantage of array order by doing the following each time it has to identify two arrays to merge: locate a sorted subarray (by incrementing a pointer until it finds an entry in the array that is smaller than its predecessor), then locate the next, and finally merge them. Examine the algorithm's running time in terms of array size and the number of maximal rising sequences in the array.
Chapter 9 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In a non-empty array of integers, the priority of a number is determined by thefrequency of its occurrence. Elements are added as they come but the most frequentelement is deleted first. If two elements have the same priority, then the elementwhich came first will be deleted first. For example: nums = [1,2,3,1,3,1,3,2,3]. Afterthe first deletion now the array will be num={1,2,1,1,2}. Implement a priority queuefor the aforementioned scenario.arrow_forwardIn a non-empty array of integers, the priority of a number is determined by the frequency of its occurrence. Elements are added as they come but the most frequent element is deleted first. If two elements have the same priority, then the element which came first will be deleted first. For example: nums = [1,2,3,1,3,1,3,2,3]. After the first deletion now the array will be num=[2,3,3,3,2,3]. Implement a priority queue for the aforementioned scenario. give the answer in brief and the correct one.arrow_forwardWrite an algorithmic faster version of this code. So the version that copies values from the first sorted half to a temp array then merges the values from the temp arr and the second sorted half into the original arr. public static <T extends Comparable<T>> void MergeSorting(T[] arr) {T[] tep = (T[]) new Comparable[arr.length];MergeSorting(arr, tep, 0, arr.length - 1);}//Recursive helper method for the merge sort algorithm.//arr The array to sort//tep Temporary array for merge operation//start Index of the left end of the region to sort //end Index of the right end of the region to sort. private static <T extends Comparable<T>> void mergeSort(T[] arr, T[] tep, int start,int end) {if (start >= end) {return;}int middle = (left + right) / 2;MergeSorting(arr, tep, start, middle); // first halfMergeSorting(arr, tep, middle + 1, end); //second halfMerge(arr, tep, start, middle, end);}private static <T extends Comparable<T>> void Merge(T[] arr, T[] tep,…arrow_forward
- Write a version of bottom-up mergesort that takes advantage of order in the array by proceeding as follows each time it needs to find two arrays to merge: find a sorted subarray (by incrementing a pointer until finding an entry thatis smaller than its predecessor in the array), then find the next, then merge them. Analyze the running time of this algorithm in terms of the array size and the number of maximal increasing sequences in the array.arrow_forwardWrite method findZero, as started below. findZero should return the index of the first element of array A that contains the value zero, starting from position 0 up through position pos. If no element of A from position 0 to position pos contains the value zero, then findZero should return –1. For example:(in java) Array (A) Position (pos) Value returned by findZero(A, pos) 1 0 2 5 6 0 -1 1 0 2 5 6 1 1 1 0 2 5 6 2 1 1 0 2 0 6 2 1 1 0 2 0 6 4 1 1 2 3 4 5 4 -1 Complete method findZero below. Assume that it is called only with values that satisfy its assumptions as stated below. // Description: Returns smallest index k // such that (0 <= k <= pos) and (A[k] == 0) // Assumptions: 0 <= pos < A.length public int findZero(int[] A, int pos) {arrow_forwardImplement substringList() that will produce the collection of words from the 1D array B that has substrings equivalent to the string key. The resulting collection should be stored in array C and this should contain only the unique set of words. The function returns the resulting total number of elements in array C. For your reference, a substring is a contiguous sequence of characters within a string. As an example, the strings “app”, “ppl”, “apple”, and “e” are among the substrings from the string “apple”. But, strings “ale” are “elppa” are not substrings from string “apple”. key = "or" array B = {"it's", "today", "now", "or", "forever", "today", "ACT"} array C should be {"or", "forever"} Rules: You can only use strcmp, strcat, and strcpy Maximize the use of loops (e.g., for) you can create local variables that can aid youarrow_forward
- Write a version of bottom-up mergesort that takes advantage of order in the array by proceeding as follows each time it needs to find two arrays to merge: find a sorted subarray (by incrementing a pointer until finding an entry that is smaller than its predecessor in the array), then find the next, then merge them. Analyze the running time of this algorithm in terms of the array size and the number of maximal increasing sequences in the array.arrow_forwardplease do what is says Given a string representing an array/vector/linked-list (your choice, will use array for clarity moving forward) of integers both positive and negative, output all the negative values on the left-hand side of the array and all positive numbers on the right-hand side of the array while maintaining their relative positions. You must do this in linear time and linear space complexity or better, i.e. you cannot scan the entire list multiple times again and again to place the values in an new array. You MUST utilize methods related to QuickSort to receive credit for this problem. We will NOT accept iterative solutions. NOTE: Do NOT sort the array, the elements need to remain in their original relative order. Hint: take a look at the partition function in QuickSort. Case 1: Input 3: 1 -1 2 -2 3 -3 4 -4 5 -5 Output 3: -1 -2-3-4 -5 1 2 3 4 5 Case 2: Input 2: 14 9 -12 -13 -11 4 -4 3 3 9 Output 2: -12 -13 -11…arrow_forward: In an array of integers, a "peak" is an element which is greater than or equalto the adjacent integers and a "valley" is an element which is less than or equal to the adjacentintegers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given anarray of integers, sort the array into an alternating sequence of peaks and valleys.EXAMPLEInput: {5, 3, 1, 2, 3}Output: {5, 1, 3, 2, 3}arrow_forward
- Implement the following algorithms in Java: A) A variant of QUICKSORT which returns without sorting subarrays with fewer than k elements and then uses INSERTION-SORT to sort the entire nearly-sorted array (slide 24).B) A variant of QUICKSORT using the median-of-three partitioning scheme.Slide 24:•Cutoff to INSERTION-SORT (as in MERGE-SORT). Alternatively: −When calling QUICKSORT on a subarray with fewer than k elements, return without sorting the subarray −After the top-level call to QUICKSORT returns, run INSERTION-SORT on the entire array to finish the sorting process −Taking advantage of the fast running time of INSERTION-SORT when its input is “nearly” sorted •Tail call optimisation convert the code so that it makes only one recursive call −Usually good compilers do that for us • Iterative version with the help of an auxiliary stackarrow_forward: In an array of integers, a "peak" is an element which is greater than or equal tothe adjacent integers and a "valley" is an element which is less than or equal to the adjacent integers. For example, in the array {5, 8, 6, 2, 3, 4, 6}, {8, 6} are peaks and {5, 2} are valleys. Given an arrayof integers, sort the array into an alternating sequence of peaks and valleys.EXAMPLEInput: {5, 3, 1, 2, 3}Output: {5, 1, 3, 2, 3}arrow_forwardImplement a mergeUniqueValues(arr1, arr2) method. When passed two arrays of strings, it will return an array containing the strings that appear in either or both arrays in sorted order. And the returned array should have no duplicates. For example, if you have two string arrays: arr1: {“Bear”, “Elephant”,”Fox”}arr2: {“Panda”, “Elephant”,”Eagle”} Calling mergeUniqueValues(arr1, arr2) should return a merged and sorted array like: Bear, Eagle, Elephant, Fox, Pandaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License