This part involves finding a new algorithm by yourself. You do NOT have to implement it with C++. You may just state the algorithm in pseudo-code. The problem is as follows: You have an integer array of n elements. You want to return true if there is a set of more than n/2 elements in the array with the same value, false otherwise. Notice that if the array is sorted (that is you are allowed to use a sorting algorithm), the solution becomes easy: Just go over the sorted array by keeping track of the number of elements of the same value. However, for this part, you are NOT allowed to use a sorting algorithm. The only operation you can perform is to compare the values of two elements of the array, which tells you if they are equal or not. Let us call this operation equality testing. Give an algorithm using O(n log n) equality testing operations. You should use the divide-and-conquer paradigm discussed in the lectures. For partial credit, give an algorithm using O(n^2 ) equality testing operations (which is in fact very easy).
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
This part involves writing and testing code. You are to make an experiment with 3 sorting algorithms partially given on Blackboard: Insertion sort, Mergesort, Quicksort. First, create a positive integer array of 10000 (ten thousand) elements with random values in it. Then, run the algorithms on this array by recording their running times. That is, take note of the time just before the sorting starts, and just after the sorting finishes, and record the difference. For a complete experiment, do...
Design and analysis of algorithms
Type in answer
Problem 5. Given a sorted array of distinct integers A[1- -n], you want to find out whether there is an index I for which Ai-i. Give a divide-and-conquer algorithm that runs in time O(log n)
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 and compare sorting algorithms. The task is to sort a list of integers using 5 sorting algorithms: selection sort insertion sort merge sort heap sort quicksort Your program should include 5 separate sorting methods, though it is fine for them to call some common methods (like "swap") if needed. Each sorting method should also count the number of comparison operations and assignment operations on the array elements during the sorting process. In the main program, two types of array...
Data Structures: For each of the following situations, name the best sorting algorithm we studied. (For one or two questions, there may be more than one answer deserving full credit, but you only need to give one answer for each.) (a) The array is mostly sorted already (a few elements are in the wrong place). (b) You need an O(n log n) sort even in the worst case and you cannot use any extra space except for a few local...
1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers, you want to find out whether there is an index i for which Al = i. Give a divide-and-conquer algorithm that runs in time O(log n). Provide only the main idea and the runtime analysis.
In the text box below, write down a divide and conquer algorithm for counting the number of entries in a sorted array of ints that are smaller than a given value. In other words, the function takes as input an array A and an int value and returns the number of ints in A that are less than value. To get any credit, your solution must use the divide and conquer technique. To get full credit, your solution should run in time in the...
the question from the course COMP 4040 that Analysis of
Algorithms
if you want to answer it by code please use C or C++
5. Algorithm Design (20 points) Input: array A contains n distinct numbers from 1 to n, in arbitrary order. Output: number of inversions (defined as the number of pair(i, j) of array indices with i < j and A[i] > Aj]) (a) (5 points) What array with elements from the set {1, 2, ..., n) has...
Implement in C SharpCreate a new algorithm based on the algorithm, selection sort. The new algorithm should be able to sort an array like this: Input: an array that has n elements, and the values of its elements are assigned randomly, for example: Index 0 1 2 3 4 5 value 7 3 6 2 1 5 Output: an array - its first n/2 elements are sorted in ascending order and its second n/2 elements sorted in descending order. That...
Suppose that you have two sorted numerical arrays A[1 . . . m] and B[1 . . . n]. You want to compute the k’th smallest number in the merged array of all m + n elements. Please design a divide- and-conquer algorithm that can do so in O(log(m + n)). You can assume for simplicity that k is even.