100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS2611 Assignment 3 Solution 2022 R200,00   Add to cart

Other

COS2611 Assignment 3 Solution 2022

 21 views  1 purchase

Assignment Solution for COS2611 Assignment 3 - 2022

Preview 2 out of 7  pages

  • August 8, 2022
  • 7
  • 2022/2023
  • Other
  • Unknown
book image

Book Title:

Author(s):

  • Edition:
  • ISBN:
  • Edition:
All documents for this subject (54)
avatar-seller
StudyWellNotes
Programming: Data Structures
COS2611
Assignment 3 - 2022

, Question 1: Searching

Describe how the binary search algorithm searches for 27 in the following list:
5, 6, 8, 12, 15, 21, 25, 31.



Solution:


Position 0 1 2 3 4 5 6 7
Values 5 6 8 12 15 21 25 31


Binary search algorithm searches for elements in a sorted list. It compares the search
element with the middle element in the list, if the search element is equal to the middle
element, the position of this element is returned. Otherwise, the lower left or the upper
right of the middle element is searched.



Position 0 1 2 3 4 5 6 7
Values 5 6 8 12 15 21 25 31
First = 0 Mid=3 last=7

In the above list, 27 is compared to 12. Surely, 27 should be on the upper right of the list.
The new search list is shaded below.


Position 0 1 2 3 4 5 6 7
Values 5 6 8 12 15 21 25 31
First = 4 Mid= 5 last=7

Again, compare 27 with 21. 27 must be on upper right.


Position 0 1 2 3 4 5 6 7
Values 5 6 8 12 15 21 25 31
First = 6
Mid= 6 last=7

27 should be on the right of 25.




2

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller StudyWellNotes. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R200,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

60434 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R200,00  1x  sold
  • (0)
  Buy now