Assume a modification of the divide and conquer solution where the right recursive call is always omitted. Provide a very basic example array where the modified algorithm would fail. Also explain why?
give a example that would make the algorithm fail where the left recursive call is always omitted
give an example that would make the algorithm fail where the find-max-subarray call is always omitted
Assume a modification of the divide and conquer solution where the right recursive call is always...
Assume a modification of the divide-and-conquer solution in which the Find-Max-Crossing-Subarray call is always omitted. Provide the most basic example array for which the modified algorithm would fail. Explain why it fails.
(13 pts) Given an array AlI,2,. .. ,n] integers, design and analyze an efficient Divide-and-Conquer algorithm to find some i and j, where j > 1, such that A[j]-Ali] is maximized. For example, given A 6, 1,3,8,4,5, 12,6], the maximum value of AL] - Ali] for j > i is 12-1 11 where j -7 and i 2. Give the underlying recurrence relation for your algorithm and analyze its running time. You should carefully state all details of your algorithm:...
6.) (a) A string contains several X's followed by several O's. Devise a divide-and-conquer algorithim that finds the number of X's in the string in log2n steps, where n is the length of the string. (b) An array originally contained different numbers in ascending order but may have been subsequently rotated by a few positions. For example, the resulting array may be: 21 34 55 1 2 3 4 5 8 13 Is it possible to adapt the Binary Search...
The zigzag sorting problem takes an array data of size n and outputs a per- mutation where data[1] <data[2] > data[3] = data[4] > data[5] S..., all the way to the end of the array. (In general data[i] = data[i+1] if i is odd and data[i] > data[i+1] if i is even.) Answer the following questions about developing algorithms for the zigzag sorting problem. 1. Give pseudocode for a brute force algorithm for zigzag sorting. Your pseudocode just needs to...
Implement the algorithm maxArray, discussed in Section 2.4.3, as
a C++ function.
Make sure the following requirements are met.
Program must compile and run.
maxArray function must be a recursive template function.
Add a main function to test the maxArray function so that you
have a complete program.
Test the maxArray function on two arrays of different
types.
Name the program maxarray.cpp. Make sure the following
requirements are met.
2.4.3 Finding the Largest Value in a Sorted or Unsorted Array...
This lab will use 2D arrays, recursive algorithms, and logical thinking. The following grid of hashes(#) and dots(.) is a 2D array representation of a maze # # # # # # # # # # # # # . . . # . . . . . . # . . # . # . # # # # . # # # # . # . . . . # . # # . . . . #...
Make a program using Java that asks the user to input an integer
"size". That integer makes and prints out an evenly spaced, size by
size 2D array (ex: 7 should make an index of 0-6 for col and rows).
The array must be filled with random positive integers less than
100. Then, using recursion, find a "peak" and print out its number
and location. (A peak is basically a number that is bigger than all
of its "neighbors" (above,...
PLEASE IMPLEMENT YOUR SOLUTION RECURSIVELY IN C++. IT
WOULD BE GREAT IF YOU COULD ALSO PROVIDE TEST CODE FOR
IT.
5) Design a recursive function to find the immediate successor of a target integer in an array o:f sorted integers. Here the immediate successor of a target is defined as the smallest number that is no smaller than the target in this sorted array int binarySuccessor(const int anArrayl, const int first, const int last, int target); In the above function...
Question 2 In the minimum grid-path problem we are given a two-dimensional grid, where each point on the grid has a value, which is a non-negative integer. We have to find a path from the top left corner of the grid to the bottom right corner, where each single step on the path must lead from one grid point to its neighbour to the right or below. The cost of the path is the sum of all values of the...
When sorting using merge sort, I get confused about what going on. Consider the following array A = [7,5,2,8,9,1] and the following code: -------------------------------------------------------------------------------------------------------------------------- int merge_sort(int *input, int start, int end) { if (start < end) { int middle = (start + end ) / 2; merge_sort(input, start, middle); merge_sort(input, middle+1, end); merge(input, start, middle, end); } return 0; } int merge(int *input, int left, int middle, int right) { // determine lenghts int length1 = middle - left +...