讲解:CISC-235、Data Structures、Python、PythonR|Database

CISC-235 Data StructuresAssignment 1.2January 17, 20191 Big-O, Big-, and Big-Θ Analysis and Proofs1) Determine the tighest upper bound (Big-O) for the following function:T(n) = 32n2 +52n 32) Prove that your answer for 1) is the tighest upper bound (Big-O). Hint:you need to prove that you can not find another slower growing functionwhich is also an upper bound (Big-O) for the function T(n).3) Prove that an algorithm with the complexity function T(n) = 3nlogn +4logn + 2 is O(nlogn).4) Let f(n) and g(n) be asymptotically nonnegative functions. Using the formaldefinition of Big-Θ notation, prove that max(f(n), g(n)) = Θ(f(n)+g(n))5) Prove or disprove (give True or False and then proof): 2n+1 = O(2n).6) Prove or disprove (give True or False and then proof): 22n = O(2n).2 Runtime Analysis of ProgramsLet us analyse the runtime complexity of two algorithms, i.e., linear search(Algorithm A) and binary search (Algorithm B) using experimental method.Note that we have introduced these two search algorithms in previous lectures(using book orgnization as the example).Algorithm A: Store the list S in an array or list, in whatever order the valuesare given. Search the list from beginning to end. If S[i] == x for any value ofi, stop searching and return True (i.e., found), otherwise return False.Algorithm B: Store the list S in an array or indexed list (such as the Pythonlist). Sort the list. Use binary search to determine if x is in S. Return Trueor False as appropriate.When using Algorithm A, searching for a value that is in the list will requirean average of n/2 comparisons, while in the worse case, searching for a value that1is not in the list will require n comparisons. When using Algorithm B, searchingfor any value will require an average of about logn comparisons. However,sorting the list will take O(nlogn) time.If we are doing a very small number of searches, Algorithm A is preferable.However if we are doing many searches of the same list, Algorithm B is preferablesince the time required to sort the list once is more than offset by the reducedtime for the searches. This is what complexity theory tells us.Your task is to conduct experiments to explore the relationship betweenthe size of the list and the number of searches required to make Algorithm Bpreferable to Algorithm A. See the detailed requirement below:1) Implement two algorithms using Python/Java/C++. When implementingAlgorithm B, you must write your own sort function and your own binarysearch function. You may use any sort algorithm that has complexity inO(nlogn).2) For n = 1000, 2000, 5000, and 10000, conduct the following experiment:- Use a pseudo-random number generator to create a list S containing nintegers.- For values of k ranging from 10 upwards:- Choose k target values, make sure half of which are in S and half arenot in S,- Use Algorithm A to search the list S for the k target values. UseAlgorithm B to search the list S for the k target values.- Determine the approximate smallest value of k for which Algorithm Bbecomes faster than Algorithm A – note that this may be greater than n.Call this value F(n). Create a table or graph showing your values of F(n)as a function of n.To easily create a list of search values, half of which are in S and half of whichare not: - when generating the list S, use only even integer values - randomlychoose some elements of S as the first half of the search list - randomly chooseodd integer values as the second half of the search listYou need to have some functions to record the running time of your algorithms,e.g., the timeit module of Python.3 Assignment RequirementsThis assignment is to be completed individually. Your need submit your documentedsource code and a report of your proofs, experiment, results and analysis,organized and formatted as described in the document “Assignment Reports”(in the OnQ system). Please combine all files into a .zip archive and submit itto OnQ system. The .zip archive should contain your student number.You can insert pictures into your assignment report, especially for the proofpart.Deadline: By the end of next Thursday (Jan-25,2019)转自:http://ass.3daixie.com/2019012368012102.html

你可能感兴趣的:(讲解:CISC-235、Data Structures、Python、PythonR|Database)