100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

COS2611 Assignment 3 Solution 2022

Rating
-
Sold
1
Pages
7
Uploaded on
08-08-2022
Written in
2022/2023

Assignment Solution for COS2611 Assignment 3 - 2022

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Course

Document information

Uploaded on
August 8, 2022
Number of pages
7
Written in
2022/2023
Type
Other
Person
Unknown

Subjects

Content preview

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

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
StudyWellNotes University of South Africa (Unisa)
Follow You need to be logged in order to follow users or courses
Sold
41
Member since
5 year
Number of followers
31
Documents
0
Last sold
6 months ago
StudyWell

Student Resources for Unisa Students.

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions