Python Projects for Beginners a ten-Week Bootcamp Approach to Python Programming



Download 2,61 Mb.
bet143/200
Sana20.06.2022
Hajmi2,61 Mb.
#681748
1   ...   139   140   141   142   143   144   145   146   ...   200
Bog'liq
Python Projects for Beginners A Ten Week Bootcamp Approach to Python

Friday: Writing a Binary Search
This week’s project is all about understanding one of the more efficient algorithms in programming… Binary Search. When you need to search a list full of data, you need to do it efficiently. It may not make sense to create an algorithm for a list of ten items but imagine if it was one million items. You don’t want to search through the list item by item to try and find what you’re looking for. Instead, we use algorithms like Binary Search to perform these tasks.
To follow along with this lesson, let’s continue from our previous notebook file
Week_08” and add a markdown cell at the bottom that says, “Friday Project: Writing a Binary Search.

Final Design


Although the program itself will be relatively small, we must understand how the algorithm for Binary Search works. For our design concept this week, we’re going to lay out the steps that we need to follow. Remember that algorithms are nothing more than a set of steps. Binary Search is no different. Each step for this algorithm is as follows:
ChapteR 8 advanCed topICs I: eFFICIenCy

  1. Sort the list.

  2. Find the middle index.

  3. Check the value at the middle index; if it’s the value we’re looking for, return True.

  4. Check the value at the middle index; if it’s greater than the value we’re looking for, cut off the right half of the list.

  5. Check the value at the middle index; if it’s less than the value we’re looking for, cut off the left half of the list.

  6. Repeat steps 2 through 6 until the list is empty.

  7. If the while loop ends, it means there’s no items left, so return False.

Let’s walk through an example together with the following arguments: [ 14, 0, 6, 32, 8 ], and we’ll be looking for the number 14. See Table 8-1 for a step-by-step walk-through.
Table 8-1. Binary Search example description


Download 2,61 Mb.

Do'stlaringiz bilan baham:
1   ...   139   140   141   142   143   144   145   146   ...   200




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish