University of Nebraska, Omaha**We aren't endorsed by this school
Course
CSCI 3320
Subject
Computer Science
Date
Dec 16, 2024
Pages
4
Uploaded by DrDolphinPerson939
CSCI 3320 Programming Assignment #3Problems Description: Your algorithm first takes an input size (10 ≤ N < 20,000) from the user. First, your program will generate a random sequence of N integers ranging from-999,999,999 to 999,999,999and store them in an array A(list in Python). If N is less than 50, your program mustuse random numbers ranging from -99 to 99 and print allrandomly generated numbers on the screen. After generating random numbers, your program takes an input K from the user again, and determines if there are two numbers whose sum equals a given number K. For instance, if the random numbers are 8, 4, 1, 6 & 3 and K is 10, then the answer is ‘yes’ (since 4 + 6 = K). Do the following:Part I: Max –10 pointsGive O(N2) algorithmto solve this problem. Analyze the complexityof your approachusing your Python code.Give O(N log N) algorithmto solve the problem (Hint: Sort the array first using a Python sort and search ). Analyze the complexityof your approachusing your Python code.Give O(N) algorithmto solve the problem (Hint: Use the given implementation of hash table. Assume the initial size of the hash table is 5,003). Describe your idea and analyze the complexityof your approachusing your Python code.Compute the running times of three algorithms above.(Write your code in Python for (a), (b) and (c))Evaluate and compare the worst-case execution times of your algorithms for identifying pairs with sums equal to KKK over a minimum of 10 iterations. Then, generate a plot showing the average worst-case execution times for input sizes of 100, 200, 400, 800, and 1600. (You may adjust the input size range based on your computer's processing speed as needed.)Make sure that you measured the worst-case execution time. An easy way to measure the worst-case execution time is to make kgreater than 2,000,000,000.Plot the averaged worst-case execution times of your O(N2) and O(N log N) algorithms for the selected input sizes in the first graph.Plot the averaged worst-case execution times of your O(N log N) and O(N) algorithms for the selected input sizes in the second graph.(Your graphs must show the averaged worst-case executions time on the vertical axis and the input sizes on the horizontal axis) Here is a sample execution of the program: Scenario #1: Enter size of random array: 1075 35 -42 -26 -37 61 29 -71 -68 65Enter the K value: -33Running the algorithms ...< Quadratic Algorithm >Yes, there are two numbers whose sum equals to KK = -33, (Value 35 + Value -68)Execution time in nanoseconds: 35
< O(NlogN) Algorithm >Yes, there are two numbers whose sum equals to KK = -33, (Value 35 + Value -68)Execution time in nanoseconds: 55< Linear Algorithm >Yes, there are two numbers whose sum equals to KK = -33, (Value 35 + Value -68)Execution time in nanoseconds: 95Scenario #2: Enter size of random array: 1600Enter the K value: 2000000000 Running the algorithms ...< Quadratic Algorithm >The algorithm could not find two numbers whose sum equals to KExecution time in nanoseconds: 105417500< O(NlogN) Algorithm >The algorithm could not find two numbers whose sum equals to KExecution time in nanoseconds: 17990100< Linear Algorithm >The algorithm could not find two numbers whose sum equals to KExecution time in nanoseconds: 3007300Part II. (Optional, up to 2 extra points)Comparison of Open Addressing Schemes Based on the Load FactorThe provided hash table implementation incorporates three open addressing collision resolution methods: linear probing, quadratic probing, and double hashing. Evaluate the performance of these methods by varying the load factor () to 0.3, 0.4, 0.5, 0.6, 0.7, and 0.8.Deliverables: Tables presenting the ten worst-case execution time measurements for each scheme across various load factors (λ) are provided. A sample template for λ = 0.3 is shown below for reference. Similar tables should be included for other load factor values (i.e., λ = 0.4, λ = 0.5, λ = 0.6, λ = 0.7, and λ = 0.8).λ = 0.3Linear ProbingQuadratic ProbingDouble HashingTest 1Test 2Test 3Test 4Test 5Test 6Test 7Test 8Test 9Test 10AveragedWorst-case TimePlot the averaged worst-case execution times for the collision resolution schemes, incorporating all three methods into a single graph. The graphs should display the
averaged worst-case execution times on the vertical axis and the load factors (λ), ranging from 0.3 to 0.8, on the horizontal axis.Deliverable: A single zipped file that includes the followings:Part I (Max – 10 points)For (a), (b) and (c): In a text file(like MS Word), shown your algorithms with a brief explanation of your method and the complexity analysisof them (O(N2), O(NlogN), and O(N) algorithms), Tablescontaining ten worst-case execution time measurements for each algorithm across different input sizes, (A template of the table for input size =100 is shown below for your reference. You must add a similar table for each input size.)Input size (100)O(N2) algorithmO(NlogN) algorithmO(N) algorithm Test 1Test 2Test 3Test 4Test 5Test 6Test 7Test 8Test 9Test 10AveragedWorst-case TimeTwographs of measuredworst-case executions times, andAll source files.Part II (optional, up to 2 extra points): Clearly indicate the file is for Part II.Tables presenting the ten worst-case execution time measurementsA graph showing the averaged worst-case execution times for all three collisionresolution schemesFor Python Programmers: Use ‘PyCharm’ for your IDE.
For full credit, your code should be well documented with comments, and the styleof your code should follow the guidelines given below:Your programs must contain enough comments. Programs without comments or with insufficient and/or vague comments may cost you 30%.Every user-defined method or function (that you added in the source files) should have a comment headerdescribing inputs, outputs, and what it does. An example function comment is shown below: def quadratic_min_subsequence(array: List[int]):"""FUNCTIONquadratic_max_subsequence:Find the subsequence in the array with the maximum sum using an algorithm with O(n^2) time complexity.INPUT_Parameters:array (List[int]): Array to evaluate for the largest subsequence.Returns:ArraySubSequence: The subsequence with the largest sum in the array."""Inline comments should be utilized as necessary (but not overused) to make algorithms clearto the reader.Not-compile programs receive 0 point. By not-compile, I mean any reason that could cause an unsuccessful compilation, including missing files, incorrect filenames, syntax errors in your programs, and so on. Double check your files before you submit, since I will notchange your program to make it work. Compile-but-not-run programs receive no more than 50%. Compile-but-not-runmeans you have attempted to solve the problem to a certain extent but you failed to make it working properly. A meaningless or vague program receives no credit even though it compiles successfully. Programs delivering incorrect result, incomplete result, or incompatible output receive no more than 60%.