Puas yog binary search recursion?
Puas yog binary search recursion?

Video: Puas yog binary search recursion?

Video: Puas yog binary search recursion?
Video: Lecture33: Recursion and Binary Search | Day-3 | 10 Days Recursion Challenge 2024, Kaum ib hlis
Anonim

Binary Nrhiav yog kev faib thiab kov yeej algorithm. Zoo li txhua qhov sib faib thiab kov yeej algorithms, Nrhiav Binary thawj faib ib tug loj array rau hauv ob me sub-arrays thiab ces recursively (lossis rov ua dua) ua haujlwm sub-arrays. Yog li Nrhiav Binary yooj yim txo cov nrhiav qhov chaw mus rau ib nrab ntawm txhua kauj ruam.

Ib yam li ntawd, nws yog nug, dab tsi yog binary recursion?

Binary recursion tshwm sim thaum twg muaj ob recursive hu rau txhua rooj plaub uas tsis yog hauv paus. Piv txwv yog qhov teeb meem ntxiv tag nrho cov lej hauv ib qho integer array A.

Ib yam li ntawd, kev tshawb nrhiav binary hauv DAA yog dab tsi? Binary nrhiav yog ceev nrhiav algorithm nrog run-time complexity ntawm Ο (log n). Rau qhov algorithm no ua haujlwm zoo, lub cov ntaub ntawv kev sau yuav tsum yog nyob rau hauv daim ntawv txheeb. Binary nrhiav saib rau ib yam khoom tshwj xeeb los ntawm kev sib piv cov khoom nruab nrab feem ntau ntawm cov khoom sau.

Ib yam li ntawd, puas yog kev tshawb nrhiav binary faib thiab kov yeej?

Cov Nrhiav Binary yog a faib thiab kov yeej algorithm: 1) Ib Faib thiab kov yeej algorithms, peb sim daws qhov teeb meem los ntawm kev daws qhov teeb meem me me ( Faib ib feem) thiab siv cov kev daws teeb meem los tsim kev daws teeb meem rau peb qhov teeb meem loj ( kov yeej ). Peb tuaj yeem daws qhov no los ntawm kev daws qhov teeb meem zoo sib xws.

Dab tsi yog qhov nres ntawm qhov kev tshawb nrhiav binary recursive?

Cov binary nrhiav algorithm tuaj yeem hais meej meej siv rov ua dua . Cov nres Cov xwm txheej yog: Cov array yuav tsis muaj cov ntsiab lus (Slice'First>Slice'Last lossis Slice'Length = 0). Tus nqi nruab nrab yog lub hom phiaj tus nqi.

Pom zoo: