Problem 4: Divide and conquer. (i) Let A be an array containing n different integers. Elements in A are sorted in increasing order. Given an integer x describe an algorithm which in time O(log n) finds an index i of x in A, that is, A[i] = x, where the length n of A is unknown (you may assume that the implementation of an array is such that for A[i], where i > n, a special character ∞ is returned). (ii) Let A be an array containing n different integers. Elements in A are not necessary sorted. Given an integer x describe an algorithm which in time O(n log n) tests whether there exist two elements u and v in A such that their sum is equal to x, that is, u + v = x. The length n of A is known.

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 16SA
icon
Related questions
Question

Problem 4: Divide and conquer.
(i) Let A be an array containing n different integers. Elements in A are sorted in
increasing order. Given an integer x describe an algorithm which in time O(log n)
finds an index i of x in A, that is, A[i] = x, where the length n of A is unknown
(you may assume that the implementation of an array is such that for A[i], where
i > n, a special character ∞ is returned).
(ii) Let A be an array containing n different integers. Elements in A are not necessary
sorted. Given an integer x describe an algorithm which in time O(n log n) tests
whether there exist two elements u and v in A such that their sum is equal to x, that
is, u + v = x. The length n of A is known.

Expert Solution
steps

Step by step

Solved in 7 steps with 4 images

Blurred answer
Knowledge Booster
Basic Operations
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