Question

We know that binary search on a sorted array of size n takes O(log n) time....

We know that binary search on a sorted array of size n takes O(log n) time. Design a similar divide-and-conquer algorithm for searching in a sorted singly linked list of size n. Describe the steps of your algorithm in plain English. Write a recurrence equation for the runtime complexity. Solve the equation by the master theorem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Steps of Algorithm:

  • Here, start node(set to Head of the list), and the last node(set to NULL initially) are given.
  • The middle is calculated using two pointers approach.
    • Traverse linked list using two pointers. Move one pointer by one and other pointer by two. When the fast pointer reaches end slow pointer will reach middle of the linked list.
  • If middle’s data matches the required value of search, return it.
  • Else if middle’s data < value, move to upper half(setting start to middle's next).
  • Else go to lower half(setting last to middle).
  • The condition to come out is, either element found or entire list is traversed. When entire list is traversed, last points to start i.e. last -> next == start.

Master's Theorem:

Go through this and let me know through comments if you have any doubts about this!

Thank you :)

Add a comment
Know the answer?
Add Answer to:
We know that binary search on a sorted array of size n takes O(log n) time....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers,...

    1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers, you want to find out whether there is an index i for which Al = i. Give a divide-and-conquer algorithm that runs in time O(log n). Provide only the main idea and the runtime analysis.

  • Analysis Divide & Conquer: Analyze the complexity of algorithm A1 where the problem of size n...

    Analysis Divide & Conquer: Analyze the complexity of algorithm A1 where the problem of size n is solved by dividing into 4 subprograms of size n - 4 to be recursively solved and then combining the solutions of the subprograms takes O(n2) time. Determine the recurrence and whether it is “Subtract and Conquer” or “Divide and Conquer“ type of problem. Solve the problem to the big O notation. Use the master theorem to solve, state which theorem you are using...

  • Suppose that, even unrealistically, we are to search a list of 700 million items using Binary...

    Suppose that, even unrealistically, we are to search a list of 700 million items using Binary Search, Recursive (Algorithm 2.1). What is the maximum number of comparisons that this algorithm must perform before finding a given item or concluding that it is not in the list “Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into n subinstances of size n/3, and the dividing and combining steps take linear time. Write a...

  • Using a recurrence relation, prove that the time complexity of the binary search is O(log n)....

    Using a recurrence relation, prove that the time complexity of the binary search is O(log n). You can use ^ operator to represent exponentiation operation. For example, 2^n represents 2 raised to the power of n.

  • Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a...

    Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing and combining steps take a time in Θ(n n). Write a recurrence equation for the running time T (n) , and solve the equation for T (n) 2. Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing...

  • Consider an ordered array A of size n and the following ternary search algorithm for finding...

    Consider an ordered array A of size n and the following ternary search algorithm for finding the index i such that A[i] = K. Divide the array into three parts. If A[n/3] > K. the first third of the array is searched recursively, else if A[2n/3] > K then the middle part of the array is searched recursively, else the last thud of the array is searched recursively. Provisions are also made in the algorithm to return n/3 if A[n/3]...

  • 1. Randomized Binary Search Which are true of the randomized Binary Search algorithm? Multiple answers:You can...

    1. Randomized Binary Search Which are true of the randomized Binary Search algorithm? Multiple answers:You can select more than one option A) It uses a Variable-Size Decrease-and-Conquer design technique B) Its average case time complexity is Θ(log n) C) Its worst case time complexity is Θ(n) D) It can be implemented iteratively or recursively E) None of the above 2. Randomized Binary Search: Example Assume you have an array, indexed from 0 to 9, with the numbers 1 4 9...

  • The zigzag sorting problem takes an array data of size n and outputs a per- mutation...

    The zigzag sorting problem takes an array data of size n and outputs a per- mutation where data[1] <data[2] > data[3] = data[4] > data[5] S..., all the way to the end of the array. (In general data[i] = data[i+1] if i is odd and data[i] > data[i+1] if i is even.) Answer the following questions about developing algorithms for the zigzag sorting problem. 1. Give pseudocode for a brute force algorithm for zigzag sorting. Your pseudocode just needs to...

  • We are using sequential search to search an array of size n. It is known that...

    We are using sequential search to search an array of size n. It is known that the item we are looking is definitely present in the array. The probability that the item we are looking for is the last one in the array is 1/3. The probabilities of all other items are equal. What is the average case time complexity(counting the number of comparisons) of the algorithm in this case?

  • fill in the blank Binary Search Tree AVL Tree Red-Black Tree complexity O(log N), O(N) in...

    fill in the blank Binary Search Tree AVL Tree Red-Black Tree complexity O(log N), O(N) in the worst case O(log N) O(log N) Advantages - Increasing and decreasing order traversal is easy - Can be implemented - The complexity remains O(Log N) for a large number of input data. - Insertion and deletion operation is very efficient - The complexity remains O(Log N) for a large number of input data. Disadvantages - The complexity is O(N) in the worst case...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT