Algorithms For Dummies


Understanding the Need to Sort and Search



Download 7,18 Mb.
Pdf ko'rish
bet253/651
Sana15.07.2021
Hajmi7,18 Mb.
#120357
1   ...   249   250   251   252   253   254   255   256   ...   651
Bog'liq
Algorithms

 Understanding the Need to Sort and Search

Right side:  [2, 4, 7]

Merged  [2, 4, 5, 7, 9]

Left side:  [8]

Right side:  [1]

Merged  [1, 8]

Left side:  [6]

Right side:  [3]

Merged  [3, 6]

Left side:  [10]

Right side:  [3, 6]

Merged  [3, 6, 10]

Left side:  [1, 8]

Right side:  [3, 6, 10]

Merged  [1, 3, 6, 8, 10]

Left side:  [2, 4, 5, 7, 9]

Right side:  [1, 3, 6, 8, 10]

Merged  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]



Solving sorting issues the best  

way using Quicksort

The Quicksort is one of the fastest methods of sorting data. In reading about 

Mergesort  and  Quicksort  online,  you  find  that  some  people  prefer  to  use  one 

over the other in a given situation. For example, most people feel that a Quick-

sort works best for sorting arrays, and Mergesort works best for sorting linked 

lists (see the discussion at 

http://www.geeksforgeeks.org/why-quick-sort- 

preferred-for-arrays-and-merge-sort-for-linked-lists/

). Tony Hoare 

wrote the first version of Quicksort in 1959, but since that time, developers have 

written many other versions of Quicksort. The average sort time of a Quicksort 

is O(n log n), but the worst-case sort time is O(n

2

).

The first part of the task is to partition the data. The code chooses a pivot point 



that determines the left and right side of the sort. Here is the partitioning code for 

this example:

data = [9, 5, 7, 4, 2, 8, 1, 10, 6, 3]

  

def partition(data, left, right):



    pivot = data[left]

    lIndex = left 

+ 1

    rIndex = right



  


CHAPTER 7


Download 7,18 Mb.

Do'stlaringiz bilan baham:
1   ...   249   250   251   252   253   254   255   256   ...   651




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
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