quiz حل الأسئلة الجامعية manage_search الأرشيف

تم الحل ✓
categoryعلوم الحاسوب وتقنية المعلومات schoolبكالوريوس event_available2026-07-13

السؤال

Transcribed Image Text:

1. (10 pts) You are given two arrays of integers A and B, both of which are sorted in ascending order. Consider the following algorithm for checking whether or not A and B have an element in common. findCommonElement (A, B) : # assume A, B are both sorted in ascending order for i0 to length (A) { for j 0 to length (B) { # iterate through A # iterate through B if (A[i]B[j]) { return TRUE } # check pairwise } } return FALSE (a) If arrays A and B have size n, what is the worst case running time of the procedure findCommonElement? Provide a O bound. (b) For n=5, describe input arrays A₁, B₁ that will be the best case, and arrays A2, B2 that will be the worst case for findCommon Element. (c) Write pseudocode for an algorithm that runs in O(n) time for solving the problem. Your algorithm should use the fact that A and B are sorted arrays. (Hint: repurpose the merge procedure from MergeSort.)

check_circle الجواب — حل مفصل خطوة بخطوة

hourglass_top