Your cart is currently empty!
1) (3 pts) Describe a 0(n lgn) time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. Explain why the running time is e(n lgn). (3 pts) For each of the following pairs of…
1) (3 pts) Describe a 0(n lgn) time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. Explain why the running time is e(n lgn).
(3 pts) For each of the following pairs of functions, either f(n) is O(g(n)), f(n) is O(g(n)), or f(n) =
E>(g(n)). Determine which relationship is correct and explain.
(4 pts) Let f1and f2 be asymptotically positive non-decreasingfunctions.Prove or disprove each of the following conjectures. To disprove give a counter example.
4) (10 pts) Merge Sort and Insertion Sort Programs
Implement merge sort and insertion sort to sort an array/vector of integers. You may implement the algorithms in the language of your choice, name one program “mergesort” and the other “insertsort”. Your programs should be able to read inputs from a file called “data.txt” where the first value of each line is the number of integers that need to be sorted,followed by the integers.
Example values for data.txt:
812345612
The output will be written to files called “merge.out” and “insert.out”. For the above example the output would be:
11223456
5) (10pts) Merge Sort vs Sort Running Time analysis
The goal of this problem is to compare the experimental running times of the two sorting algorithms
best?
Algorithms? Remember, the experimental running times were “average case” since the input arrays contained random integers.