Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let A[O...n-1) be an unsorted array of positive integers, in the range of (0,..., n). Entries in A are not necessarily unique. Design an algorithm
Let A[O...n-1) be an unsorted array of positive integers, in the range of (0,..., n"). Entries in A are not necessarily unique. Design an algorithm that tests whether there are two numbers in A that are exactly ten apart, i.e. A[i] - A[j] = 10 for some indexes i, j = {0, 1,...n-1}. For example, the algorithm should return "yes" if the array is A= 4, 1, 10, 6, 5, 11), because numbers 1 and 11 are 10 units apart. It should return "no" on A= (10,5, 13, 1, 14,2). The worst-case run-time of your algorithm must be O(n). You can use O(n) additional space. Let A[O...n-1) be an unsorted array of positive integers, in the range of (0,..., n"). Entries in A are not necessarily unique. Design an algorithm that tests whether there are two numbers in A that are exactly ten apart, i.e. A[i] - A[j] = 10 for some indexes i, j = {0, 1,...n-1}. For example, the algorithm should return "yes" if the array is A= 4, 1, 10, 6, 5, 11), because numbers 1 and 11 are 10 units apart. It should return "no" on A= (10,5, 13, 1, 14,2). The worst-case run-time of your algorithm must be O(n). You can use O(n) additional space
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started