Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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-do

Explanation / 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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote