Monday, June 3, 2019

Research Assignment on Data File Structure

Research Assignment on Data File StructureRaghavendra TyagiTOPIC OF ASSIGNMENTThe letters in English language, make up words. While no word is little or more than anformer(a), one could view a word that appears before another in the dictionary is slight than that word, and a word that appears afterwards is more. By this definition, identical words argon the same.Parsing a cross-file is when you read a file to collect information from the file. In this assignment, you pass on parse a file, and put all of the words in a binary star pursuit steer. You will use the double star Search corner to collect data about the offspring of times a word was found in the file.The first word you encounter will be the get back. If the close word is greater, put it to the right. If it is less, put it to the unexpended. It is possible that the tree you make will be very sparse.Assume all words in the file are lower case or covert them to lower case.After you have loaded the file into your bi nary program Search Tree, the program should display the in-order, pre-order post-order traversal of the Binary Search Tree.The user should be given the chance to type a word. The computer should say the number of times the word was found in the file (zero or more).BINARY SEARCH TREEINTRODUCTIONIncomputer science, a binary search tree (BST), sometimes also called an ordered or sorted binary tree, is anode-basedbinary treedata structure which has the following propertiesThe left paladin treeof a node contains only nodes with observes less than the nodes key.The right sub tree of a node contains only nodes with keys greater than the nodes key.The left and right sub tree each must also be a binary search tree.There must be no duplicate nodesADVANTAGEThe major advantage of binary search trees over otherdata structuresis that the related sortingAlgorithm andsearch algorithmssuch asin-order traversalcan be very efficient.BINARY SEARCH TREE (PROPERTY)Letxbe a node in a binary search tree . Ifyis a node in the left sub tree ofx, and soy. key x. key.OPERATIONSOperations, such asfind, on a binary search tree require comparisons between nodes. These comparisons are made with calls to a comparator, which is asubroutinethat computes the total order (linear order) on all cardinal keys. This comparator can be explicitly or implicitly defined, depending on the language in which the binary search tree was implemented.SEARCHINGSearching a binary search tree for a specific key can be arecursiveor aniterativeprocess.We begin by examining theroot node. If the tree isnull, the key we are searching for does not exist in the tree. Otherwise, if the key equals that of the root, the search is successful and we shine the node. If the key is less than that of the root, we search the left sub tree. Similarly, if the key is greater than that of the root, we search the right sub tree. This process is repeated until the key is found or the remaining sub tree is null. If the searched key is not found before a null sub tree is reached, then the item must not be present in the tree. unveilingInsertion begins as a search would begin if the key is not equal to that of the root, we search the left or right sub trees as before. Eventually, we will reach an external node and add the new key-value pair (here encoded as a record new Node) as its right or left child, depending on the nodes key. In other words, we examine the root and recursively insert the new node to the left sub tree if its key is less than that of the root, or the right sub tree if its key is greater than or equal to the root.DELETIONThere are three possible cases to considerDeleting a leaf (node with no children)Deleting a leaf is easy, as we can simply remove it from the tree.Deleting a node with one childRemove the node and replace it with its child.Deleting a node with two childrenCall the node to be deletedN. Do not deleteN. Instead, choose either itsin-ordersuccessor node or its in-order predecessor node,R. Replace the value ofNwith the value ofR, then deleteR.BST FIGUREPreorder traversal sequence F, B, A, D, C, E, G, I, H(Root, left, right)In order traversal sequence A, B, C, D, E, F, G, H, I(left, root, right)Post order traversal sequence A, C, E, D, B, H, I, G,(left, right, root)ASSIGNMENT formulainclude include struct treeNode charr data10 struct treeNode *left, *right struct treeNode *root = NULLstruct treeNode* createNode(char data) struct treeNode *newNodenewNode = (struct treeNode*)malloc(sizeof(struct treeNode)) newNode-data = data newNode-left = NULL newNode-right = NULL accrue(newNode) void insertion(struct treeNode **node, char data) if (*node == NULL) *node = createNode(data) else if (data data) insertion((*node)-left, data) else if (data (*node)-data) insertion((*node)-right, data) void deletion(struct treeNode **node, struct treeNode **parent, char data) struct treeNode *tmpNode, *tmpParent if (*node == NULL) return if ((*node)-data == data) if ((*node)-l eft (*node)-right) if (parent) if ((*parent)-left == *node) (*parent)-left = NULL else (*parent)-right = NULL free(*node) elsefree(*node)else if ((*node)-right (*node)-left) tmpNode = *node (*parent)-right = (*node)-left free(tmpNode) *node = (*parent)-right else if ((*node)-right (*node)-left) tmpNode = *node (*parent)-left = (*node)-right free(tmpNode)(*node) = (*parent)-left else if ((*node)-right-left)tmpNode = *node(*node)-right-left = (*node)-left(*parent)-left = (*node)-rightfree(tmpNode)*node = (*parent)-leftelsetmpNode = (*node)-rightwhile (tmpNode-left)tmpParent = tmpNodetmpNode = tmpNode-lefttmpParent-left = tmpNode-righttmpNode-left = (*node)-lefttmpNode-right =(*node)-rightfree(*node)*node = tmpNodeelse if (data data)deletion((*node)-left, node, data)else if (data (*node)-data)deletion((*node)-right, node, data)void find gene(struct treeNode *node, chardata)if (node)returnelse if (data data)find member(node-left, data)else if (data node-data)findElement(node-right, data)elseprintf(data found %sn, node-data)returnvoid traverse(struct treeNode *node)if (node = NULL)traverse(node-left)printf(%3d, node-data)traverse(node-right)returnint main()char dataint chwhile (1)printf(1. Insertion in Binary Search Treen)printf(2. Deletion in Binary Search Treen)printf(3. Search Element in Binary Search Treen)printf(4. Inorder traversaln5. Exitn)printf( record your filling)scanf(%d, ch)switch (ch)case 1 while (1)printf( acquiesce your data)scanf(%s, data)insertion(root, data)printf(Continue Insertion(0/1))scanf(%d, ch)if (ch) hoo-hahbreakcase 2 printf( introduce your data)scanf(%s, data)deletion(root, NULL, data)breakcase 3printf( don value for data)scanf(%s, data)findElement(root, data)breakcase 4printf(Inorder Traversaln)traverse(root)printf(n)breakcase 5exit(0)default printf(uve entered wrong optionn)breakreturn 0emailprotected $vi t.cemailprotected $gcc t.cemailprotected $./a.outOUTPUT1. Insertion in Binary Search Tree 2. Deletion in Binary Search Tree 3 . Search Element in Binary Search Tree 4. Inorder traversal5. ExitEnter your choice1 Enter your data aim Continue Insertion(0/1)1 Enter your data age Continue Insertion(0/1)1 Enter your data sustain Continue Insertion(0/1)1 Enter your data agree Continue Insertion(0/1)1Enter your data blueContinue Insertion(0/1)0Resultant Binary Search Tree after insertion operation aim / age blue / admit agree 1. Insertion in Binary Search Tree 2. Deletion in Binary Search Tree 3. Search Element in Binary Search Tree 4. Inorder traversal 5. ExitEnter your choice4 Inorder Traversal admit, age, agree, aim , blue 1. Insertion in Binary Search Tree 2. Deletion in Binary Search Tree 3. Search Element in Binary Search Tree 4. Inorder traversal 5. ExitEnter your choice2 Enter your dataadmit Delete node admitaim / age blue / agree 1. Insertion in Binary Search Tree 2. Deletion in Binary Search Tree 3. Search Element in Binary Search Tree 4. Inorder traversal 5. Exit Enter your choice3Enter value for dataa gedata found ageNo of occurrence1 1. Insertion in Binary Search Tree 2. Deletion in Binary Search Tree 3. Search Element in Binary Search Tree 4. Inorder traversa 5. Exit Enter your choice5emailprotected $COMPLEXITY OF BINARY SEARCH TREEIt could be O(n2) even if the tree is balanced.Suppose youre adding a sorted list of total, all larger than the largest number in the tree. In that case, all numbers will be added to the right child of the rightmost leaf in the tree, Hence O(n2).For example, suppose that you add the numbers 15..115 to the following treeThe numbers will be added as a long chain, each node having a single right hand child. For the i-th portion of the list, youll have to traverse i nodes, which yields O(n2).In general, if youd like to keep the insertion and retrieval at O(nlogn), you need to useSelf Balancing trees

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.