Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 i = 0 to length(A) { # iterate through A for j = 0 to length(B) { # 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 Theta bound. (b) For n = 5, describe input arrays A_1, B_1 that will be the best case, and arrays A_2, B_2 that will be the worst case for findCommonElement. (c) Write pseudocode for an algorithm that runs in Theta(n) time for solving the problem. Your algorithm should use the fact that A and B are sorted arrays

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

What is the message repetition?

Answered: 1 week ago