0% found this document useful (0 votes)
23 views6 pages

Data Structure Assignment - 3 BST

Uploaded by

hemanath405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Data Structure Assignment - 3 BST

Uploaded by

hemanath405
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
Binary Search Tree. Binaty earch Tree (@sT),also called an ordered or Sorted binary tee, is a wotedl binay bee data stucture with — key of each internal node being greater than all the Keys ta the ~—-wespective node's let subbee ancl les than the ones in its ight — Subtwce- The Complexity ey operation en the binay search time tree 4» leinaws with roipect tthe height et the bee. A binay search tree Follows — some pacer t auange the elements In a —- Binaty geatch tree, the value 6 apt node = must «= be) smallles than the parent node sand the value > vight — node mutt — be greoket than the Parent node» The wile % applied vecwsively to the Jett and wight Subbrees of Hre wot. Operations of BST: ° Cwate + Theevt © Seewch * Delete + Inoxdey * Poeorler © Postorder Poogram * Hinclude 2Stdio.h> #include Sbuct pode { Int = data; Stuct noole “Yight ; Stuck node *legt; o; Stuck pode * nesnede Got x) t Struct node * temp: temp= malloc (size o (struct node): temp —> data= x} temp > left =NULL; temp —> vight = NULL; rekwn temp ; Struct node* seatch (Struct node * aot sint 2) 5 L if (sv0t >= ule Ilavot > data x) yelutn ook; else if [x Ss ywot - data) retutn — Senech (avet —S vighl, x); | ete | rel Searels (ol slefl, x); 3 Shuct node * insert (stuct pode * mot ,int { Tf (voot = x) NULL) MN pew node (x); Cise if (x > wot +data) wot > vight = insert (soot > Wght » x); else wot > left = insert (wot — left, x); retuen wot, 3 Struct node * delete (Struct pode wot, ink x) | | | t if (eot == NULL) vetuen = NULL if (* >xvot +dotka) wot — right =ddete frvot ssvight , x); else if [x data) wot —> loft = delete (woot —s lest , xy else ig (mol left == NULL R@ wot > Vight == NULL) i free (30k) / ret temp ; a else § Strick node * bemp = minimum (rook >7ight)i wot > data = temp data; woot > Vight = dole te [wot > right, tempdatad ; 4 J volun yok; a Voit inowler (struct node * yvot ) t if (woot | = ULL) t inorder (vot > leyt)s Print ("2d") yok > data); inorder (rook > right ); 3 y int = main 0 { Struct node * aot; Wot = Newnode (20); inset (vot , 5): insert (ook, 1); insert [wots 15); insert (roots 4) insext (yolt, 7); insert (rot, (2); inseyt (ypots 30); insert (wot, 25); imert (2v0Fs Yo); insert (x00t, 45); inser t (yoot 42); inoxder (pot); Point £ ("\n"): wot = delete [wot , 4); oot = delete (wot, uo); wot = delete (woot, us); Wot = delete (wot, 4); inorder (yoot) : Print t (°\n"); vetwn 0!

You might also like