Exercise 9. Describe in plain English an algorithm that computes the number of common elements in 2 arrays of integers. You can assume that there are no duplicates in the first array, and also no duplicates in the second array. For example if array a₁ = [9, 3, 1, 5, 7, 11] and array a2 = [6, 2, 7, 8, 10, 5, 1], the algorithm should return 3 because the two arrays have three numbers in common, namely 1,5,7. Your algorithm should run in O(n log n) time.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question
Exercise 9. Describe in plain English an algorithm that computes the number of common elements in
2 arrays of integers. You can assume that there are no duplicates in the first array, and also no duplicates in
the second array. For example if array a₁ = [9, 3, 1, 5, 7, 11] and array a2 = [6, 2, 7, 8, 10, 5, 1], the algorithm
should return 3 because the two arrays have three numbers in common, namely 1,5,7. Your algorithm
should run in O(n log n) time.
Transcribed Image Text:Exercise 9. Describe in plain English an algorithm that computes the number of common elements in 2 arrays of integers. You can assume that there are no duplicates in the first array, and also no duplicates in the second array. For example if array a₁ = [9, 3, 1, 5, 7, 11] and array a2 = [6, 2, 7, 8, 10, 5, 1], the algorithm should return 3 because the two arrays have three numbers in common, namely 1,5,7. Your algorithm should run in O(n log n) time.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning