/  18
 
Adhit Mukesh Shetadhitms@gmail.comPseudo CodesProgram Number 14Write a recursive C program for searching an element on a given list of integers using binary searchmethod and for solving the tower of Hanoi problemLogicBinary Search FunctionInputSearch ElementOutputPosition of the search element if found, else inform the user that the searchelement was not found.Logic1.Assign the variable 'low' to the position of the first element and also assign thevariable 'high' to the position of the last element (To be done in the Main function)2.Whenever 'low' is greater than 'high' the search fails, i.e. the search element is notfound.3.The position of the middle element is obtained by the statement below and is savedin the variable 'mid'mid=(low+high)/24.If the search element is found at 'mid' position return variable 'mid'5.If the search element is less than middle element then the elements in the left parthave to be compared ranging from 'low' to 'mid-1'6.If not then the elements in the right part of the array has to be compared from 'mid+1' to 'high'Tower of Hanoi FunctionInputNumber of discsOutputSolution to the Tower of Hanoi problemLogic1.In case the number of discs are 1 then output would be 'Move disc n formsource_needle to destination_needle.2.If not then do steps 3-53.Move n-1 discs recursively from source_needle to temp_needle4.Move disc n from source_needle to destination_needle5.Move n-1 discs from temp_needle to destination_needle
 
Adhit Mukesh Shetadhitms@gmail.comWAP to construct a binary search tree of integers , to traverse the tree using all methodsInsert FunctionLogic1.Dynamically create a node and save it as the variable 'temp'2.Update the information part of this node to the input element3.Update the left and right link of this node as NULL4.If the 'root' variable is NULL then assign 'temp' to 'root'.5.Assign 'root' to 'cur', use this variable to traverse the linked list till the informationpart of the node is not equal to input element and till the node is not equal to NULL.Do steps 6-7 (cur points to the current node)6.Assign the 'cur' to the variable 'prev'(prev points to the previous node)7.If the input element is less than the information part of the current node then update'cur' to the left link of the current node else update it to the right link of the currentnode8.If the input element is less than the information part of the previous node, thenupdate the left link of the previous node as NULL else update the right link of theprevious node as NULLInorder TraversalLogic1.If 'root' is NULL then return control to the calling function2.If not then do steps 3-53.Traverse the left subtree in inorder4.Print the root node5.Traverse the right subtree in inorderPreorder TraversalLogic1.If 'root' is NULL then return control to the calling function2.If not then do steps 3-53.Print the root node4.Traverse the left subtree in preorder5.Traverse the right subtree in preorderPostorder TraversalLogic1.If 'root' is NULL then return control to the calling function2.If not then do steps 3-53.Traverse the left subtree in postorder4.Traverse the right subtree in postorder5.Print the root node
 
Adhit Mukesh Shetadhitms@gmail.comWAP to support the following operations on a doubly linked list where each node consists of integers1.Create a doubly linked list be adding each node at the front2.Insert a new node to the left of the node whose key value is read as input3.Delete the node of the given data, if it is found, other wise display appropriate message4.Display the contents of the linked listFunction to insert at the front of the linked listLogic1.Dynamically create a node2.On successful creation of the node do steps 3-6 else go to step 73.Assign 'first' to the right link of this node4.Update the left link of the first node to this node5.Initialize the left link of this node as NULL6.Take the value of the node from the user and save it in the information part of this node7.Return the node first to the calling functionFunction to insert at the left of the specified nodeLogic1.Dynamically create a node2.On successful creation of the node do steps 3-13 else go to step 143.Take the value of the specified node from the user4.If the first node is NULL or if the first node is the specified node then call the insert atthe front of the linked list function5.If not then assign the first node to 'trv'6.While 'trv' is not equal to NULL and the 'trv' is not the specified node assign the value of the right link of 'trv' to trv ( Do this to traverse the linked list and find the specifiednode)7.If 'trv' is not NULL then do steps 8-12 else go to step 138.Take the value of the new node from the user9.Update the left link of the new node to the left link of the node 'trv'10.Update the right link of the new node to 'trv'11.Update trv to the left link of the new node12.Update the right link of 'trv' to the new node. Go to step 1413.Inform the user that the specified node was not found in the linked list14.Return the node first to the calling function.Function to delete the specified nodeLogic1.If first node is NULL then inform the user that the linked list is empty.2.Assign first node to 'trv'3.While 'trv' is not equal to NULL and the 'trv' is not the specified node assign the value of theright link of 'trv' to 'trv'(Do this to traverse the linked list and find the specified node)4.If 'trv' is NULL then inform the user that the specified node was not found.

Share & Embed

More from this user

Add a Comment

Characters: ...