Question

Given a non-decreasingly sorted array A[p..q] and a number x, consider the following algorithm Search. SEARCH(A, p, q, x) 1 if A[q] ? x 2 return -1 3 if p == q 4 return p 5 else 6 mid = \lfloor(p + q)/2\rfloor 7 if A[mid] ? x 8 return SEARCH(A, mid + 1, q, x) 9 else 10 return SEARCH(A, p, mid, x) (1) (4pts) Run Search(A, 1, 6, 7) on array A[1..6] = <2, 3, 5, 6, 8, 9>. Find the final return value by listing all the recursive calls made to Search, along with the input p and q values of each call. Note that index starts from 1. (2) (2pts) Analyze the best-case running time of algorithm Search, in terms of n, size of the input array A[p..q] and give a tight bound (using \Theta) on it. (3) (4pts) Write a recurrence relation describing the worst-case running time of algorithm Search, in terms of n, and solve the recurrence to give a tight bound (using \Theta) on it.

          Given a non-decreasingly sorted array A[p..q] and a number x, consider the following
algorithm Search.
SEARCH(A, p, q, x)
1 if A[q] ? x
2	return -1
3 if p == q
4	return p
5 else
6	mid = \lfloor(p + q)/2\rfloor
7	if A[mid] ? x
8		return SEARCH(A, mid + 1, q, x)
9	else
10		return SEARCH(A, p, mid, x)
(1) (4pts) Run Search(A, 1, 6, 7) on array A[1..6] = <2, 3, 5, 6, 8, 9>. Find the final
return value by listing all the recursive calls made to Search, along with the input p
and q values of each call. Note that index starts from 1.
(2) (2pts) Analyze the best-case running time of algorithm Search, in terms of n, size
of the input array A[p..q] and give a tight bound (using \Theta) on it.
(3) (4pts) Write a recurrence relation describing the worst-case running time of
algorithm Search, in terms of n, and solve the recurrence to give a tight bound
(using \Theta) on it.
        
Show more…
Given a non-decreasingly sorted array A[p..q] and a number x, consider the following
algorithm Search.
SEARCH(A, p, q, x)
1 if A[q] ? x
2	return -1
3 if p == q
4	return p
5 else
6	mid = ⌊(p + q)/2⌋7	if A[mid] ? x
8		return SEARCH(A, mid + 1, q, x)
9	else
10		return SEARCH(A, p, mid, x)
(1) (4pts) Run Search(A, 1, 6, 7) on array A[1..6] = <2, 3, 5, 6, 8, 9>. Find the final
return value by listing all the recursive calls made to Search, along with the input p
and q values of each call. Note that index starts from 1.
(2) (2pts) Analyze the best-case running time of algorithm Search, in terms of n, size
of the input array A[p..q] and give a tight bound (using Θ) on it.
(3) (4pts) Write a recurrence relation describing the worst-case running time of
algorithm Search, in terms of n, and solve the recurrence to give a tight bound
(using Θ) on it.

Added by Cheryl M.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Given a non-decreasingly sorted array A[p..q] and a number x, consider the following algorithm Search. SEARCH(A, p, q, x) 1. if A[q] < x 2. return -1 3. if p == q 4. return p 5. else 6. mid = [(p + q)/2] 7. if A[mid] < x 8. return SEARCH(A, mid + 1, q, x) 9. else 10. return SEARCH(A, p, mid, x) (1) (4pts) Run Search(A, 1, 6, 7) on array A[1..6] = <2, 3, 5, 6, 8, 9>. Find the final return value by listing all the recursive calls made to Search, along with the input p and q values of each call. Note that index starts from 1. (2) (2pts) Analyze the best-case running time of algorithm search, in terms of n, size of the input array A[p..q] and give a tight bound (using O) on it. (3) (4pts) Write a recurrence relation describing the worst-case running time of algorithm Search, in terms of n, and solve the recurrence to give a tight bound (using O) on it.
Close icon
Play audio
Feedback
Powered by NumerAI
Jennifer Stoner Danielle Fairburn
Ivan Kochetkov verified

Sri K and 56 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
you-are-given-an-array-a-of-n-elements-whose-entries-are-distinct-integers-assume-that-n-2-an-index-j-is-called-a-local-minimum-of-a-if-one-of-the-following-conditions-holds-j-1-and-a1-a2-j-74773

You are given an array A of n elements whose entries are distinct integers. Assume that n ≥ 2. An index j is called a local minimum of A if one of the following conditions holds: • j = 1 and A[1] < A[2]. • j = n and A[n] < A[n − 1]. • 1 < j < n, A[j] < A[j − 1], and A[j] < A[j + 1]. Find a local minimum of A in O(log n) time. Go through each step, be very systematic. a. Convince an understanding of what a local minimum is by giving an example of an array A[1 . . . 10] of distinct integers such that none of the indices in {1, 2, 3, 4, 5} is a local minimum, but A has three different local minima. b. From now on, consider a general n. Prove that A is guaranteed to have a local minimum. Keep it brief. c. Provide pseudocode for a recursive divide-and-conquer algorithm that solves the problem of finding a local minimum of A. Prove the correctness of your algorithm by appropriately referring to or extending your previous proof. d. Prove that your algorithm’s worst-case runtime T(n) satisfies T(n) ≤ T(n/2) + O(1). Solve the recurrence, in an asymptotic sense, to complete the algorithm analysis.

Sri K.

1-given-the-array-9-20-14-17-85-3-21-6-4-10-determine-the-number-of-comparisons-used-by-bubble-sort-insertion-sort-selection-sort-merge-sort-quick-sort-heap-sort-2-prove-that-the-worst-case-71468

Given the array {9, 20, 14, 17, 85, 3, 21, 6, 4, 10}, determine the number of comparisons used by: - Bubble Sort - Insertion Sort - Selection Sort - Merge Sort - Quick Sort - Heap Sort

Akash M.

let-a-n-be-an-array-of-n-elements-we-assume-that-no-two-elements-of-a-are-equal-and-a-is-not-sorted_-let-m-be-another-given-number-our-goal-is-to-find-the-largest-element-x-in-a-such-that-th-57232

Let A[1 ...n] be an array of n elements. We assume that no two elements of A are equal and A is not sorted. Let M be another given number. Our goal is to find the largest element x in A such that the sum of the elements of A less than x is smaller than M (i.e., Σ_{a ∈ A, a < x} a < M). We assume that the sum of all elements of A is larger than M. For example, suppose A contains seven numbers: {4, 5, 2, 3, 6, 8, 1}, and M = 10. Then, the largest such number x we are looking for is 4. Design an O(n) time algorithm for the problem by using the Prune-and-Search technique.

Sri K.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,095 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,843 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,659 solutions

*

Transcript

-
00:01 Hello, let's look at the question for the first part.
00:03 The example of error with 10 elements will be minus 1, 1, 2, plus 1, minus 1, minus 2, minus 3, minus 5, minus 6, 10, 9, 13 and 12.
00:31 There is no local minimum, a 0, minus a4, and for a5 is minus 6 is the local minimum as a 0, and for a5 is minus 6 is the local minimum as, a4, a6 is greater than a5.
01:04 Now for a7 is 9 is local minimum as a6 a5 is greater than a 7 and our a9 is greater than a7 and our a9 is local minimum as a n minus 1 is greater than a n.
01:39 Hence there are three local minimums.
01:48 The second part will see if there is only one element, it's guaranteed to be distinct and it would be a local minimum...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Join the community

18,000,000+

Students on Numerade


Trusted by students at 8,000+ universities

Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever