Let A = {a1...an}, B = {b1...bn}, and C = {c1...cn} be three sets of numbers. Co
ID: 3852130 • Letter: L
Question
Let A = {a1...an}, B = {b1...bn}, and C = {c1...cn} be three sets of numbers. Consider the problem of finding their intersection, i.e., the set D of all the numbers that are in A, B, and C.
• Design a brute-force algorithm to solve this problem and determine its efficiency.
• Design a presorting-based algorithm for solving this problem and determine its efficiency.
ALGORITHM BubbleSort(A[0.n 1]) //Sorts a given array by bubble sort //Input: An array A[0.. 1 of orderable elements //Output: Array A[0..n - 1] sorted in ascending order for i 0ton_2do for j 0 to n-2-doExplanation / Answer
Algorithm for brute foutce coat
Problem: Find the value of polynomial
p(x) = anxn + an-1xn-1 +… + a1x1 + a0
at a point x = x0
Algorithm:
p := 0.0
for i := n down to 0 do
power := 1
for j := 1 to i do
power := power * x
p := p + a[i] * power
Efficiency:
return p
Brute-Force Strengths and Weaknesses
Strengths
Wide applicability
Simplicity
Yields reasonable algorithms for some important
problems
(e.g., matrix multiplication, sorting, searching, string
matching)
Weaknesses
Rarely yields efficient algorithms
Some brute-force algorithms are unacceptably slow
Not as constructive as some other design techniques
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.