Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 2 out of 7 pages
Other

COS2611 Assignment 3 Solution 2022

Document preview thumbnail
Preview 2 out of 7 pages

Assignment Solution for COS2611 Assignment 3 - 2022

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

Connected book
 image
D. Malik, D. S. Malik Data Structures Using C
Publisher: Unknown ISBN: 9780324782011 Edition: 2

Document information

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

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

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
5.0
(1)
Sold
42
Followers
31
Items
0
Last sold
3 months ago



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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions