95.6k views
4 votes
Write down the pseudo code for a brute-force algorithm to compare elements in array A with elements in array B.

User Yeny
by
5.0k points

1 Answer

5 votes

Answer:

def brute_force(array1, array2):

for item in array1:

for element in array 2:

if element == item:

print(f"{element} and {item} are a match")

Step-by-step explanation:

A brute-force algorithm is a direct-to-solution algorithm that searches and compares variables. It is like trying to unlock a safe but not knowing its four-digit combination, brute-force starts from 0000 through 9999 to get a match.

The python program implements the algorithm using two nested for loops. The first loop iterates over array1 while the second, over array2. For every item in the first array, the program loops through the length of the second array. For every match, the items are printed on the screen.

User Jim Richards
by
5.6k points