Dab tsi yog qhov teeb meem phem tshaj plaws thiab qhov teeb meem nruab nrab nyuaj ntawm binary nrhiav ntoo?
Dab tsi yog qhov teeb meem phem tshaj plaws thiab qhov teeb meem nruab nrab nyuaj ntawm binary nrhiav ntoo?

Video: Dab tsi yog qhov teeb meem phem tshaj plaws thiab qhov teeb meem nruab nrab nyuaj ntawm binary nrhiav ntoo?

Video: Dab tsi yog qhov teeb meem phem tshaj plaws thiab qhov teeb meem nruab nrab nyuaj ntawm binary nrhiav ntoo?
Video: Data Science with Python! Analyzing File Types from Avro to Stata 2024, Hlis ntuj nqeg
Anonim

Binary nrhiav tsob ntoo

Algorithm Nruab nrab Qhov phem tshaj plaws
Qhov chaw O(n) O(n)
Nrhiav O (log n) O(n)
Ntxig O (log n) O(n)
Rho tawm O (log n) O(n)

Dhau li ntawd, dab tsi yog qhov loj O phem tshaj lub sij hawm nyuaj ntawm ib tsob ntoo nrhiav binary?

Tus qauv recursive ntawm a BST yields ib tug recursive algorithm. Nrhiav hauv a BST muaj O (h) phem tshaj - cas lub sijhawm ua haujlwm nyuaj , qhov twg h yog qhov siab ntawm lub tsob ntoo . Txij li thaum s binary nrhiav tsob ntoo nrog n nodes muaj yam tsawg kawg nkaus O (log n) theem, nws yuav siv sij hawm tsawg kawg O (log n) kev sib piv los nrhiav ib qho chaw tshwj xeeb.

Qhov thib ob, dab tsi yog lub sijhawm nyuaj ntawm kev tshawb nrhiav binary nrog iteration? Kev ua tau zoo ntawm Binary Nrhiav Algorithm : Yog li ntawd, lub sij hawm complexity ntawm binary nrhiav algorithm yog O (log2n) uas ua tau zoo heev. Qhov chaw pabcuam siv los ntawm nws yog O (1) rau rov hais dua kev siv thiab O (log2n) rau recursive siv vim hu pawg.

Tsis tas li lo lus nug yog, dab tsi yuav yog qhov phem tshaj lub sij hawm nyuaj ntawm kev tshawb nrhiav ib qho hauv ib tsob ntoo nrhiav binary?

Lub sij hawm nyuaj : Cov phem tshaj lub sij hawm complexity ntawm nrhiav thiab ntxig cov haujlwm yog O(h) qhov twg h yog qhov siab ntawm Binary Nrhiav tsob ntoo . Hauv qhov phem tshaj plaws , peb muaj muaj rau taug kev los ntawm cag rau nplooj nplooj tob. Qhov siab ntawm ib tug skewed tsob ntoo muaj ua n og lub sij hawm complexity ntawm nrhiav thiab ntxig kev ua haujlwm muaj ua O(n).

Puas yog Big O qhov xwm txheej phem tshaj?

Yog li, Hauv kev tshawb nrhiav binary, qhov zoo tshaj plaws cas yog O (1), nruab nrab thiab qhov phem tshaj plaws yog O (logn). Hauv luv luv, tsis muaj kev sib raug zoo ntawm hom loj O yog siv rau qhov phem tshaj plaws , Theta rau nruab nrab cas ”. Txhua hom kev sau ntawv tuaj yeem siv tau (thiab qee zaum) siv thaum tham txog qhov zoo tshaj plaws, nruab nrab, lossis qhov phem tshaj plaws ntawm ib qho algorithm.

Pom zoo: