To tsim BST yog preorder lossis xa ntawvtxaus vim tias inorder yeej ib txwm txheeb rau BST.
Qhov kev txiav txim siab twg txaus los tsim BST?
2 Teb. Txhawm rau tsim BST koj tsuas yog xav tau ib (tsis nyob rau hauv-order) traversal. Feem ntau, txhawm rau tsim ib tsob ntoo binary koj yuav xav tau ob txoj kev taug kev, hauv kev txiav txim thiab xaj ua ntej piv txwv.
Yuav ua li cas traversal tsim ib tsob ntoo binary?
Yog ib txoj kev hla dhau yog Inorder ces tsob ntoo tuaj yeem tsim, txwv tsis pub. Yog li ntawd, kev sib xyaw ua ke hauv qab no tuaj yeem txheeb xyuas tus ntoo. Inorder thiab Preorder. Inorder thiab Postorder.
Peb puas tuaj yeem tsim BST siv inorder traversal?
Muab Inorder Traversal ntawm tsob ntoo tshwj xeeb Binary nyob rau hauv uas tus yuam sij ntawm txhua qhov node ntau dua cov yuam sij rau sab laug thiab sab xis cov menyuam yaus, tsim Binary Tsob Ntoo thiab rov qab cag. Lub tswv yim siv hauv Kev Tsim Kho Ntoo los ntawm muab Inorder thiab Preorder traversals tuaj yeem siv ntawm no.
Yuav ua li cas hauv qab no yuav tsum tsim binary search tree?
Rau tsob ntoo binary los ua ib tsob ntoo tshawb nrhiav binary, cov ntaub ntawv ntawm tag nrho cov nodes nyob rau hauv sab laug sub-ntoo ntawm lub hauv paus node yuav tsum yog cov ntaub ntawv ntawm lub hauv paus. Cov ntaub ntawv ntawm tag nrho cov nodes nyob rau hauv txoj cai subtree ntawm lub hauv paus node yuav tsum yog cov ntaub ntawv ntawm lub hauv paus.