Suppose you have an unsorted array A containing n distinct integers in the range 0 to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose you have an unsorted array A containing n distinct integers in the range 0 to n, where n = 2* - 1 for some positive integer k. Each integer in the range 0 to n appears exactly once in the array, except for one missing integer. Design a Divide and Conquer algorithm to find the missing number. Argue informally that your algorithm is correct and analyze its running time. Q2. (5 points) Write a recursive Java function to print all permutations of a string. For example; all possible permutations of "abc" are: "abc", "acb", "bac", "bca", "cab", and "cba". a. (3 points) Submit the Java code for testing the function. b. (2 points) Analyze the running time of your function with explanation. Q3. (5 points) Write a recursive Java function to Binary() that convert a given decimal number to binary. a. (3 points) Submit the Java code for testing the function. b. (2 points) Analyze the running time of your function with explanation. Q4. (15 points) Binary Insertion Sort is a sorting algorithm that is similar to Insertion Sort, but instead of using linear search to find the location where to insert an element, it uses binary search. a. (10 points) Write a Java program that generates a list of N random integers and sorts them in increasing order using each of the two algorithms: Insertion Sort and Binary Insertion Sort. b. (5 points) Measure the execution time for each of the two algorithms for randomly generated lists of size N = 40000, 100000, 200000, and 400000. Present your results in a table as shown below and plot the results in a chart. For each value of N, run your program 5 times and write in the table the average of the 5 runs. Insertion Sort Binary Insertion Sort N= 40,000 Run Time (average of 5 runs) N=100,000 N=200,000 N=400,000 Important Note: For each value of N, the two algorithms must sort the same list. Make sure you keep a copy of the generated list before sorting it with one of the algorithms and use the saved original copy (not the sorted list) as input for the second algorithm. Suppose you have an unsorted array A containing n distinct integers in the range 0 to n, where n = 2* - 1 for some positive integer k. Each integer in the range 0 to n appears exactly once in the array, except for one missing integer. Design a Divide and Conquer algorithm to find the missing number. Argue informally that your algorithm is correct and analyze its running time. Q2. (5 points) Write a recursive Java function to print all permutations of a string. For example; all possible permutations of "abc" are: "abc", "acb", "bac", "bca", "cab", and "cba". a. (3 points) Submit the Java code for testing the function. b. (2 points) Analyze the running time of your function with explanation. Q3. (5 points) Write a recursive Java function to Binary() that convert a given decimal number to binary. a. (3 points) Submit the Java code for testing the function. b. (2 points) Analyze the running time of your function with explanation. Q4. (15 points) Binary Insertion Sort is a sorting algorithm that is similar to Insertion Sort, but instead of using linear search to find the location where to insert an element, it uses binary search. a. (10 points) Write a Java program that generates a list of N random integers and sorts them in increasing order using each of the two algorithms: Insertion Sort and Binary Insertion Sort. b. (5 points) Measure the execution time for each of the two algorithms for randomly generated lists of size N = 40000, 100000, 200000, and 400000. Present your results in a table as shown below and plot the results in a chart. For each value of N, run your program 5 times and write in the table the average of the 5 runs. Insertion Sort Binary Insertion Sort N= 40,000 Run Time (average of 5 runs) N=100,000 N=200,000 N=400,000 Important Note: For each value of N, the two algorithms must sort the same list. Make sure you keep a copy of the generated list before sorting it with one of the algorithms and use the saved original copy (not the sorted list) as input for the second algorithm.
Expert Answer:
Answer rating: 100% (QA)
Solution Lets break down each question and provide solutions Q1 Divide and Conquer Algorithm To find the missing number in an unsorted array we can use a Divide and Conquer algorithm Heres an informal ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
This problem examines three algorithms for searching for a value x in an unsorted array A consisting of n elements. Consider the following randomized strategy: pick a random index i into A. If A[i] =...
-
make a small case or use a situation/problem from real life. You will discuss this situation together with a discussion that works through a solution of your own to the problem posed. Problems or...
-
A 50.0-kg stunt pilot who has been diving her all plane vertically pulls out of the dive by changing her course to a circle in a vertical plane. (a) If the plane's speed at the lowest point of the...
-
Shostak showed the following details regarding its notes receivable: Round calculations to the nearest whole cent Required For each note: a. Determine the maturity date. b. Calculate the days of...
-
In 2014, Barker contacted Price about a van Price had advertised for sale. The advertisement described the van as a 1994 Ford E350. Barker and Price agreed to meet, and, on April 9, Barker inspected...
-
Jill has decided that the BackPack Company must have very good customer service. She has asked you to develop a level aggregate plan using inventories but not back orders. All demand must be met each...
-
1. What is the selection bias in the regressions? When will the bias occur? 2. Please explain why the random assignment could be used to address. the selection bias problem.
-
Healthy Eating Foods Company is a distributor of nutritious snack foods such as granola bars. On December 31, 2016, the firms general ledger contained the accounts and balances that follow. ACCOUNTS...
-
XYZ firm plans to pay three annual special dividends of $3 per share over the next three years to reflect the windfall from the completion of a major successful project. Thereafter, starting exactly...
-
Why is not specializing and reaping the gains from trade inefficient? .
-
What protection is given to consumers by the Electronic Fund Transfer Act?
-
Capital accumulation and technological change bring economic growth: Production that was unattainable yesterday becomes attainable today; production that is unattainable today will become attainable...
-
Explain why Singapore has experienced faster economic growth than the United States.
-
Prior to his marriage, Edward Garber had been in financial difficulty and had a poor credit rating. His wife, Natalie, applied for a credit card in her family name, fearing that she would be turned...
-
Muon-particles are created at an altitude of more than 6000 m by cosmic rays coming from the outer space. These particles have an average life of 2 x 10^-6s in their rest frame and travel towards the...
-
The area of a rectangle is 30 cm 2 and its perimeter is 26 cm. Find the length and width of the rectangle.
-
Explain how to find the minimum key stored in a B-tree and how to find the predecessor of a given key stored in a B-tree.
-
Let e be a maximum-weight edge on some cycle of connected graph G = (V, E). Prove that there is a minimum spanning tree of G = (V, E {e}) that is also a minimum spanning tree of G. That is, there is...
-
Suppose that each source s i in a flow network with multiple sources and sinks produces exactly p i units of flow, so that v f(s i , v)= P i. Suppose also that each sink t j consumes exactly q j...
-
See Table 2.5 showing financial statement data and stock price data for Mydeco Corp. a. Compute Mydecos PE ratio each year from 2019 to 2023. In which year was it the highest? b. What was Mydecos...
-
See Table 2.5 showing financial statement data and stock price data for Mydeco Corp. a. Compute Mydecos ROE each year from 2019 to 2023. b. Compute Mydecos ROA each year from 2019 to 2023. c. Which...
-
In early 2018, United Airlines (UAL) had a market capitalization of \($25.14\) billion, debt of \($12.73\) billion, and cash of \($5.59\) billion. United also had annual revenues of \($38.72\)...
Study smarter with the SolutionInn App