تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
1) (25 pts) Consider the Find and Replace Problem:
Input: A two dimensional n x n binary array,
11 12
A =
and an2
dan
and 2 x 2 binary arrays v =
and w=
[W11 W12]
21 22
W21 W22
Output: Continuously find the v array in the A array and replace them
with the w array until there is no more v array in the A array.
[100 100
110110
001101
Ex: Let n 6 and the array be A =
and we want to
101000
101100
010010
continously find the array v =
=[%] to
to replace with the array w=
Note that, we highlight the v arrays in A with colors. Observe that the entry
0 is in the intersection of two v arrays. To avoid ambiguity, whenever you
detect a v array in A immediately replace it with the w array. Then, after
the first round of the replacement we obtain
1 1
1
A'
100 100
1 110 1
001110
1 0 1 0 1 1
0100 00
which still includes a v array.
Then, in the second round we obtain
A"
111111
1 0 0 1 0 0
1 1 1 0 1
11 10
0 0 1 0 1 1
0100 00
, the final result since there is no more v array.
(1.1) (15 pts) Design an algorithm, say Find & Replace algorithm, to obtain
the updated array. Write the pseudocode of your algorithm.
Code your algorithm in Java by randomly generating the input arrays
A, v and w.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.