100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Case uitwerking

Computational Thinking Assignment 3

Beoordeling
-
Verkocht
-
Pagina's
8
Cijfer
9-10
Geüpload op
14-06-2022
Geschreven in
2019/2020

Computational Thinking Assignment 3










Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Geüpload op
14 juni 2022
Aantal pagina's
8
Geschreven in
2019/2020
Type
Case uitwerking
Docent(en)
Bhulai
Cijfer
9-10

Voorbeeld van de inhoud

Computational Thinking – Assignment 3 (Artificial Intelligence Year 1)


1. Comparison of keys


Keys 4 13 25 33 38 41 55 71 73 84 86 92 97
Index 0 1 2 3 4 5 6 7 8 9 10 11 12


We need to use binary search: worst case performance, because that will lead to the largest
possible number of key comparisons. In this list, we have 13 indices, because we need to start
counting the keys from k = 0. The formula we need to use is ⎡ log2(n + 1) ⎤.


⎡ log2(n + 1) ⎤ = log2 (13 + 1) = 3.80735492206 ≈ 4

Conclusion: when you look up a key with binary search, the largest possible number of key
comparisons in this list is 4.

2. Estimating performance
A.
Binary search
Average case of successful search: ~ log2 (n)
Average case of successful search in a sorted array of 100,000 elements:
~log2 (100,000) = 16.609640474436812 ≈ 16.6

Sequential/linear search
Average case of successful search: (n + 1) / 2
Average case of successful search in a sorted array of 100,000 elements:
(100,000 + 1) / 2 = 50000.5
As you can see the 1 in (n + 1) / 2 is neglectable, because it’s a really small number compared to
100,000. You will get: (100,000) / 2 = 50000.

An average successful search by binary search is .6 ≈ 3010 times faster than an
average successful search by sequential search.

B.
We have a sorted array of 100,000 elements. To draw a single graph for both
linear (= sequential) and binary search, we need to use the “Big O” notation. The big O notation is
used to classify algorithms. It is a function characterization according to rates of growth and it is
useful for analysing efficiency. In this case, we consider worst cases. The worst cases for the
binary and linear search algorithms are:
- Binary = O(log(n))
- Linear = O(n)

I drew a
single graph
in Python as
follows:

, Computational Thinking – Assignment 3 (Artificial Intelligence Year 1)


This is the result I got, after I clicked “run”.




We can see that the number of operations (for 100,000 elements) with the binary search
algorithm, is a lot less than with linear search, if you consider worst case scenario’s. In this case, if
you want to find a key, it is better and way faster to use the binary search algorithm.


3. Binary search in flowchart

This in my flowchart for binary search, made in excel.
€5,49
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
TR19

Ook beschikbaar in voordeelbundel

Thumbnail
Voordeelbundel
Computational Thinking
-
5 2022
€ 29,77 Meer info

Maak kennis met de verkoper

Seller avatar
TR19 Vrije Universiteit Amsterdam
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
0
Lid sinds
9 jaar
Aantal volgers
0
Documenten
7
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen