4. Given two lists A of size m and B of length n, our goal is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
4. Given two lists A of size m and B of length n, our goal is to construct a list of all elements in list A that are also in list B. Consider the following two algorithms to solve this problem. procedure Search1 (List A of size m, List B of size n) Initialize an empty list L. SORT* list B. 1. 2. 3. 5. 6. for each item a A, if BinarySearch(a, B) #0 then Append a to list L. return L *Note: Assume that the SORT algorithm used in Search1 takes time proportional to k log k on an input list of size k, and that BinarySearch(a, B) matches the procedure binary search (x: integer, al, a2, an increasing integers) from lecture slides. procedure Search 2 (List A of size m, List B of size n) Initialize an empty list L. for each item a A, if Linear Search(a, B) #0 then Append a to list L. 1. 2. 3. 4. 5. return L (a) (2 points) Determine the runtime of Search1 in (b) (2 points) Determine the runtime of Search2 in (c) (2 points) When m (d) (2 points) When m notation, in terms of m and n. notation, in terms of m and n. (1), which algorithm has an asymptotically faster runtime? (n), which algorithm has an asymptotically faster runtime? (e) (2 points) Find a function f(n) so that when m e(f(n)), both algorithms have equal runtime asymptotically. 4. Given two lists A of size m and B of length n, our goal is to construct a list of all elements in list A that are also in list B. Consider the following two algorithms to solve this problem. procedure Search1 (List A of size m, List B of size n) Initialize an empty list L. SORT* list B. 1. 2. 3. 5. 6. for each item a A, if BinarySearch(a, B) #0 then Append a to list L. return L *Note: Assume that the SORT algorithm used in Search1 takes time proportional to k log k on an input list of size k, and that BinarySearch(a, B) matches the procedure binary search (x: integer, al, a2, an increasing integers) from lecture slides. procedure Search 2 (List A of size m, List B of size n) Initialize an empty list L. for each item a A, if Linear Search(a, B) #0 then Append a to list L. 1. 2. 3. 4. 5. return L (a) (2 points) Determine the runtime of Search1 in (b) (2 points) Determine the runtime of Search2 in (c) (2 points) When m (d) (2 points) When m notation, in terms of m and n. notation, in terms of m and n. (1), which algorithm has an asymptotically faster runtime? (n), which algorithm has an asymptotically faster runtime? (e) (2 points) Find a function f(n) so that when m e(f(n)), both algorithms have equal runtime asymptotically.
Expert Answer:
Answer rating: 100% (QA)
The image provided contains two procedure definitions Search1 and Search2 both of which are designed to find common elements between two lists A and B ... 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
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Name each of the following compounds using R,S and E,Z (Section 3.5) designations where necessary: a. b. c. d. e. f. g. h. CH2CH3 H- CH3 H2CH C-C C-C CI Br CH,CH CH-CH,CH,CH, - H3C CH2CH2l CH2CH...
-
The following financial assets appeared in a recent balance sheet of Apple, Inc. (dollar amounts are stated in millions). Cash and cash...
-
A casting machine is supposed to produce units for which the standard deviation of weights is 0.4 ounces. According to the maker of the machine, it should be shut down and thoroughly examined for...
-
A microwave oven uses 2.4 GHz electromagnetic waves. A cell phone uses electromagnetic waves at a slightly lower 1.9 GHz frequency. What can you say about the wavelengths of the two? A. The waves...
-
(a) Is Justins enthusiasm over the idea of a debt-consolidation loan justified? Why or why not? (b) Why can the bank offer such a good deal to Justin? (c) What compromise would Justin make to remit...
-
About "Dream Toy" manufactory Most of the company processes are not digitized. They use classic product development methods: their commercialization method is in-person B2B only, low to no tech day...
-
XYZ, Inc. is considering a 5-year project. The production will require net working capital investments each year equal to 15% of the projected sales. Total fixed costs are $1,350,000 per year,...
-
1. An undirected graph is said to be connected iff every pair of vertices in the graph are reachable from one another. Prove the following statement: Any connected undirected graph with n nodes has...
-
The Baldwin Company currently has the following balances on their balance sheet: Total Assets$175,467 Total Liabilities $105,271 Retained Earnings$32,013 Suppose next year the Baldwin Company...
-
Identify how the work was infringed. Identify the type of license that would have been necessary for the use. Discuss the harm incurred by the infringement (monetarily and/or otherwise) on the...
-
Environmental Economics Valuation of Ecosystems Think back to your previous experiences and prior knowledge with respect to valuation of ecosystems. Share what you know about environmental...
-
Discuss whether ethics in law is different than ethics in other fields, such as business or medicine.
-
Describe how this scene illustrates the role of reflected appraisal and social comparison in forming a person's self-concept. Discuss how Ben and Katie could use the textbook material on Emotions to...
-
B. Unity of Roots 2 1. z = 12i 4 2. z* = -2 5i 3. z=(-3+2i)
-
For the data in Exercise 17-19, use the FIFO method to summarize total costs to account for, and assign these costs to units completed and transferred out, and to units in ending work in process....
-
What is the probability that a k-string over a set of size n forms a k-permutation? How does this question relate to the birthday paradox?
-
Show that if f (n) = (n log b a lg k n), where k 0, then the master recurrence has solution T (n) = (n log b a lg k + 1 n). For simplicity, confine your analysis to exact powers of b.
-
Is the operation of deletion "commutative" in the sense that deleting x and then y from a binary search tree leaves the same tree as deleting y and then x? Argue why it is or give a counterexample.
-
For the pediatrician presented in Example 1, find the probability that a randomly selected three-year-old girl is between 35 and 40 inches tall, inclusive. That is, find P(35 X 40). By-Hand...
-
The heights of a pediatricians three-year-old females are approximately normally distributed, with mean 38.72 inches and standard deviation 3.17 inches. Find the height of a three-year-old female at...
-
Find the value of z 0.10 . Approach We wish to find the z-value such that the area under the standard normal curve to the right of the z-value is 0.10.
Study smarter with the SolutionInn App