Anaylyze following solution ( and fill in boxes, A-I ) thanks. Data structures a
ID: 3837633 • Letter: A
Question
Anaylyze following solution ( and fill in boxes, A-I ) thanks.
Data structures algorithms c++
LAB ASSIGNMENT struct node int data struct node* left struct node right struct node NewNode( int data) struct node node new(struct node "new" is like malloc node data data node left NULL node- right NULL return (node); Estatic int lookup(struct node* node, int target) E 1. Base case empty tree in that case, the target is not found so return false if (node NULL) f return(false); else 2. see if found here if (target node- data) return(true); else 3. otherwise recur down the correct subtree if (target k node- data) return(lookup(node- left, target)); else return(lookup node- right target)); struct node insert(struct node" node, int data) 1. If the tree is empty, return a new, single node if (node NULL) te return (NewNode(data)); else 2. Otherwise, recur down the tree if (data node- data) node- left insert (node- left, data else node-right insert ight. data) return (node); return the (unchanged) node pointerExplanation / Answer
A
Create a struct name as Node
Contain integer data
Contain left and right
B
Create a new node
Node data is data
Node left is NULL
Node right is NULL
C
This method search particular target element present or not in binary tree
If node ==NULL return false
Else
If target element ==node data return true
Else
If target element less then node data call same method in node left
Else
If target element greater then node data call same method in node right
D
This method insert new node in binary tree
If node ==null then return
Else
If data is less then node data
then call node left is insert(node->left,data)
else
call node right is insert(node->right,data)
E
Create a root node whose data is 2
Create a lchild node whose data is 1
Create a rchild node whose data is 3
Root left node is lchild
Root right node is rchild
F
Create a root node whose data is 2
Root, left node contain data 1
Root, right node contain data 3
G
Create a node root as NULL
Insert 2 in root
Insert 1 in root
Insert 3 in root
H
It compute number of node in binary tree
Call size method
If node == NULL then return 0
Else
Call same method
I
This will print binary tree
If node ==NULL return
Else
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.
A
Create a struct name as Node
Contain integer data
Contain left and right
B
Create a new node
Node data is data
Node left is NULL
Node right is NULL
C
This method search particular target element present or not in binary tree
If node ==NULL return false
Else
If target element ==node data return true
Else
If target element less then node data call same method in node left
Else
If target element greater then node data call same method in node right
D
This method insert new node in binary tree
If node ==null then return
Else
If data is less then node data
then call node left is insert(node->left,data)
else
call node right is insert(node->right,data)
E
Create a root node whose data is 2
Create a lchild node whose data is 1
Create a rchild node whose data is 3
Root left node is lchild
Root right node is rchild
F
Create a root node whose data is 2
Root, left node contain data 1
Root, right node contain data 3
G
Create a node root as NULL
Insert 2 in root
Insert 1 in root
Insert 3 in root
H
It compute number of node in binary tree
Call size method
If node == NULL then return 0
Else
Call same method
I
This will print binary tree
If node ==NULL return
Else
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.