تم الحل ✓
categoryعلوم الحاسوب وتقنية المعلومات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
Question 2: (50 pts) Consider the Find and Replace Problem:
Input: A two dimensional nxn (n is an even number) binary array, A =
ani an2
ann
U11 U12
W11 W12
and 2 x 2 binary arrays v =
and w=
121 U22
W21 22
Output: Find the v array in the A array and replace them with the w array.
Ex: Let n 6 and the array be A
1 0 0 1 0 0
1 1 0 1 1 0
001101
101000
10 1100
and we want to find the array
0 1 0 0 0
v=
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, the resulting array will be
A' =
1 1 1 1 1 1
1 0 0 1 0 0|
00
01
10
1 0 1 0 1
0 1 0 0 0 0
1. (25 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.
2. (15 pts) Analyze the time complexity of your algorithm. Give an asymptotic upper
bound on the running time of your algorithm.
Calculate the running time of your Java code for n = 10, 100, 1000 and visualize the
asymptotic upper bound and the experimental time complexity in one plot.
3. (10 pts) Is Find & Replace algorithm an efficient algorithm? Why, why not? Submit
the Java codes.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.