Sunday, March 7, 2021

code for searching binary search tree (BST)

 bool  search (node *tree, int number)

{

//always check for NULL when dealing with pointers

//this is also the base case

        if (tree==NULL)

        {

                return false;

        }

//

        elseif (number < tree->number)

        {

                return search (tree->left, number);

        }

        elseif (number > tree->number)

        {

                return search (tree->right, number);

        }

        elseif (number == tree->number)

        {

                true;

        }


}



video location: lecture 5.  1:20:00 ~ 1:30:00

source: harvard cs50, david malan


]

code for creating node for binary search tree (BST)

 typedef struct node

{

        int number;

        struct node *left;

        struct node *right;

}node;



source: harvard cs50, david malan



code for creating a node for a linked list

 typedef struct node

{

        int number;

        struct node *next;

}node;



source: harvard cs50, david malan

binary search tree (BST)

 requires array in sorted order

requires random access of arrays

very powerful because big O of logn


location in week 5 video: 1:20:00

source: harvard cs50, david malan