Cov txheej txheem:

Qhov twg sorting algorithm yog qhov zoo tshaj plaws hauv qhov phem tshaj?
Qhov twg sorting algorithm yog qhov zoo tshaj plaws hauv qhov phem tshaj?

Video: Qhov twg sorting algorithm yog qhov zoo tshaj plaws hauv qhov phem tshaj?

Video: Qhov twg sorting algorithm yog qhov zoo tshaj plaws hauv qhov phem tshaj?
Video: Koj twb xav zoo lawm los nkauj hmoob 4/17/2020 2024, Hlis ntuj nqeg
Anonim

Soj ntsuam algorithms

Algorithm Cov ntaub ntawv qauv Sijhawm nyuaj : phem tshaj
Ceev ceev Array O(n2)
Sib koom ua ke Array O(n log(n))
Heap kev Array O(n log(n))
Yooj yim Array O(n log(n))

Yog li ntawd, hom twg yog qhov zoo tshaj plaws hauv qhov phem tshaj?

Quicksort feem ntau yog qhov ceev tshaj plaws, tab sis yog tias koj xav tau lub sijhawm phem tshaj plaws, sim Heapsort lossis Mergesort . Ob leeg no muaj O (n log n) ua haujlwm tsis zoo.

Ib yam li ntawd, qhov kev txheeb xyuas algorithm twg muaj qhov teeb meem tsawg tshaj plaws phem tshaj plaws? Sib koom ua ke

Hais txog qhov no, qhov twg algorithm yog qhov zoo tshaj plaws rau kev txheeb xyuas?

Quicksort

Yuav ua li cas koj pom qhov phem tshaj plaws thiab cov ntaub ntawv zoo tshaj plaws ntawm ib qho algorithm?

Hauv cov ntsiab lus yooj yim tshaj plaws, rau qhov teeb meem uas qhov loj me yog n:

  1. Cov ntaub ntawv zoo tshaj plaws = lub sijhawm ceev tshaj plaws kom tiav, nrog rau kev pom zoo xaiv. Piv txwv li, rooj plaub zoo tshaj plaws rau kev txheeb xyuas algorithm yuav yog cov ntaub ntawv uas twb tau txheeb xyuas lawm.
  2. Cov ntaub ntawv phem tshaj = lub sijhawm qeeb tshaj plaws los ua kom tiav, nrog cov khoom siv pessimal xaiv.
  3. Average case = tus lej lej.

Pom zoo: