Create/Construct Binary Search Tree (Algorithm/Program/Code)

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • Give a list of numbers. Create a binary Search Tree of the elements in the list.

КОМЕНТАРІ • 60

  • @ishan_kumar
    @ishan_kumar 5 років тому +9

    If anybody wondering where the break should be. It has to be just after the line(s) p->left = q and p-> right=q.
    Thanks

  • @AdeshPaul
    @AdeshPaul 5 років тому

    वेरी नाइस एक्सप्लानेशन... कीप इट अप !

  • @AmitSharma-ke7ft
    @AmitSharma-ke7ft Рік тому

    the inner while loop has to break after assigning the element to the specified position, otherwise it will be an infinite loop without break. but i should say very well explained

  • @biplabsarkar4827
    @biplabsarkar4827 6 років тому

    Great one..very helpful for b.tech students

  • @weijunqian3249
    @weijunqian3249 7 років тому +19

    did you forget to break the while loop?

    • @armeenhossain665
      @armeenhossain665 5 років тому +1

      Hi , can you explain me what is meant by while(1)?

    • @surajch2678
      @surajch2678 5 років тому +3

      there should be a break inside while at null check. He probably forgot

    • @vm1662
      @vm1662 5 років тому +4

      @@armeenhossain665 While(1) means the condition is true and the loop will go on (infinite loop) until there is a break. In while(condition), condition is reduced down to either 0 or 1. 0 means false and 1 means true.

  • @abhijeetgorai242
    @abhijeetgorai242 4 роки тому

    Nice explanation Sir

  • @nikvolkov1409
    @nikvolkov1409 6 років тому +2

    Good explanation as always. Do you have a video about binary tree rotation?

  • @karanshishodia7759
    @karanshishodia7759 5 років тому

    Crystal clear concept👌

  • @punittiwari7557
    @punittiwari7557 5 років тому

    Superb sir

  • @soumyaranjansatpathy8320
    @soumyaranjansatpathy8320 6 років тому

    i wasn't able to recall the trick thanks for valuable video

  • @sushmaraya9440
    @sushmaraya9440 5 років тому

    Ur videos are so helpful thank u

  • @sqlyoutuber8230
    @sqlyoutuber8230 3 роки тому

    Very helpful. thanks man

  • @meenarose9592
    @meenarose9592 2 роки тому

    Sir..thnk u

  • @mhfarhadi4376
    @mhfarhadi4376 4 роки тому

    very helpful thank you so much

  • @Globlefood_nature
    @Globlefood_nature 7 років тому

    super understanding ... sir

  • @niteshagarwal4934
    @niteshagarwal4934 4 роки тому +1

    Whenever we are assigning the pointer in the while loop we need to break

  • @atakanbilgili4373
    @atakanbilgili4373 3 роки тому

    Thank u!

  • @prasannachalgeri7152
    @prasannachalgeri7152 6 років тому

    Dear Sir, should there be a continue after executing statements in else p=p->left; continue and similarly in the other else statements?

  • @thedeepakreddy7
    @thedeepakreddy7 5 років тому +1

    can you make the video of "Construction of a binary tree from in-order, pre-order traversals"?

  • @koober_
    @koober_ 7 років тому

    Hello Vivekanand! Thanks for the helpful video. If you have not already done so, can you make a video on how to construct an AVL tree as well as how to remove from and rebalance it in code? Again thank you very much and keep up the good work!

  • @yanlingyang256
    @yanlingyang256 6 років тому +2

    could you please explain how we could jump out of the while loop, since it is always 1. Thanks

    • @vivekanandkhyade
      @vivekanandkhyade  6 років тому +9

      Once we attach a node to the left or right of its parent , we break from the loop..... It should be as follows:-
      while(1)
      {
      if(q->value value)
      {
      if(p->left == NULL)
      {
      p->left = q;
      break; ----------------------------------------------- // here is the break condition.
      }
      else
      p = p->left;
      }
      else if(q->value > p->value)
      {
      if(p->right == NULL)
      {
      p->right = q;
      break; --------------------------------------------------------------// here is the break condition
      }
      else
      p = p->right;
      }
      }

    • @priyavutukuri1223
      @priyavutukuri1223 6 років тому +1

      can you please modify the video with adding the break; statement. I was also wondering that how do we exit from the while loop then I read this comment ! Thank you !

  • @lavkushtiwari2799
    @lavkushtiwari2799 7 років тому

    Sir, I also want videos regarding avl tree operations and some advanced data structures like tries,suffix trees and sting permutation algorithms

  • @ramzibarki
    @ramzibarki 6 років тому

    Nice man

  • @bobbyarrington5617
    @bobbyarrington5617 3 роки тому

    Is there a way to get a copy of the BST code in Python?

  • @onlineenergy7151
    @onlineenergy7151 5 років тому

    Nice Video Sir. In Laravel Nestedset how can i get total Left count & Right count from a node. please help.

  • @rohitariq5271
    @rohitariq5271 4 роки тому

    Please sir can you upload video for coverage and conductance metrics in graph theory.

  • @fernandoborges3044
    @fernandoborges3044 6 років тому

    How can I construct a binary search tree with the optimized depth to the minimum possible according to the number of nodes?
    I've made a algorithm to optimize this. I've tested with a random binary tree with 5000 nodes and as result I earned a depth of 15, but, by the math, the minimum depth should be 12.

  • @utsavpatra9471
    @utsavpatra9471 5 років тому

    Create BST using linked list as well as in recursive way

  • @i.m.sumedhj8276
    @i.m.sumedhj8276 7 років тому

    thanku sir :)

  • @agentgopal007
    @agentgopal007 6 років тому

    good

  • @thejaswinichitturi3556
    @thejaswinichitturi3556 3 роки тому

    Sir, please look into this.
    It is a program to print preorder, inorder and postorder traversals for t testcases.
    I'm getting wrong output.
    Given i/p:
    1 //num of testcaces
    5 //num of arr elements
    3 2 4 1 5 //arr elements
    Expected o/p:
    3 2 1 4 5 //pre
    1 2 3 4 5 //in
    1 2 5 4 3 //post
    My o/p:
    3 1 4 5 //pre
    1 3 4 5 //in
    1 5 4 3 //post
    #include
    using namespace std;
    struct node {
    int data;
    node *lt,*rt;
    };
    void preorder(node *root) {
    if(root==NULL)
    return;
    coutlt);
    coutrt);
    cout>n;
    for(int i=0;i>p->data;
    p->lt=NULL;
    p->rt=NULL;
    if(i==0)
    root=p;
    else {
    q=root;
    while(1) {
    if(p->data > q->data) {
    if(q->rt==NULL) {
    q->rt=p;
    break;
    }
    else
    q=q->rt;
    }
    else {
    if(p->lt==NULL) {
    q->lt=p;
    break;
    }
    else
    q=q->lt;
    }
    }
    }
    }
    preorder(root);
    cout

  • @goldyswaraj9797
    @goldyswaraj9797 6 років тому

    Sir could u plz teach how to create binary tree ...It's algorithm

  • @meenarose9592
    @meenarose9592 2 роки тому

    Can u work recursive binary search tree

  • @srajensingh4532
    @srajensingh4532 6 років тому

    sir please make video on merge and quick sort with code

  • @i.m.sumedhj8276
    @i.m.sumedhj8276 7 років тому +2

    plz upload vidseo sir if binary search tree contain symbol also like * + -

  • @pradeepreddy1382
    @pradeepreddy1382 4 роки тому

    Sir if two elements having same values given then how to construct

    • @ramyakrohanmohanty9895
      @ramyakrohanmohanty9895 4 роки тому

      Not possible. Duplicate values are not allowed in BST, because you cannot decide whether to make the duplicate value, the left child or the right child of the original value.
      That is why duplicate values are not allowed.

  • @dr.padmajapulicherla5545
    @dr.padmajapulicherla5545 5 років тому

    Could you plz explain binary search tree using linked list

  • @vivekchandraundirwade7059
    @vivekchandraundirwade7059 6 років тому +5

    Marathi manus na bhava tu? 😀

  • @TechnicalBaniya
    @TechnicalBaniya 7 років тому

    sir while(1) is an infinite loop and
    there is no any termination condition I think the inner while loop should have the condition like this
    while(q!=NULL)
    {
    if(q->valuevalue)
    {
    if(p->left==NULL)
    {
    p->left=q;
    q=NULL;
    }
    else{
    p=p->left;
    }
    }
    else
    {
    if(p->right==NULL)
    {
    p->right=q;
    q=NULL;
    }
    else
    {
    p=p->right;
    }
    }
    }

    • @vivekanandkhyade
      @vivekanandkhyade  7 років тому

      yes you are right. and if you replace q=NULL in your code by "break ; " , it will be even better. Hey friend thanks for communicating. May at that time due to space constraint on board , i have not written that. Thanks a lot bro.

    • @TechnicalBaniya
      @TechnicalBaniya 7 років тому

      Vivekanand Khyade - Algorithm Every Day mention not sir !!!

  • @rajareddy9754
    @rajareddy9754 6 років тому

    sir i serach in git hub ur videos not appeared(this video)

  • @tuhinsaha2011
    @tuhinsaha2011 4 роки тому

    Sir you forgot to break the while loop

  • @armeenhossain665
    @armeenhossain665 5 років тому

    Can anyone explain the line p = p->left

    • @vm1662
      @vm1662 5 років тому

      The left node of the node p.
      The node p has two nodes (left and right). p-> left points to the left node of p.

  • @ravindranavale4085
    @ravindranavale4085 5 років тому

    Sir explain the function plz

  • @saqibb919
    @saqibb919 6 років тому

    Tree traversal programs

  • @slientpower_3661
    @slientpower_3661 5 років тому +2

    Wrong code

  • @bipuljha792
    @bipuljha792 5 років тому

    To see the full code I will have to create a id in github.com can't you write the full code here in video?
    Time consuming