monwinchimalang / Expose-on-tree-data-structures

1 stars 0 forks source link

EXPOSEE ON TREE DATA STRUCTURES #1

Open monwinchimalang opened 7 months ago

monwinchimalang commented 7 months ago

https://github.com/monwinchimalang

monwinchimalang commented 7 months ago

TREE DATA STRUCTURES Tree data structures are hierarchical data structures that consist of nodes connected by edges. Each node in a tree has a parent node and zero or more child nodes. The topmost node in a tree is called the root node, and nodes with no children are called leaf nodes. Tree data structures are used in computer science for implementing various algorithms and data storage structures, such as binary search trees, AVL trees, and B-trees. Trees are efficient for organizing and searching data, as well as for representing and solving complex problems. Some examples of tree data structures are: Binary tree in which each node has at most two children, referred to as the left and the right child, AVL tree in which the heights of the two child sub trees of any node differ by at most one, B-tree which is optimized for systems that read and write large blocks of data, such as databases and file systems. Practical implementation of tree data structures in some programming languages Tree data structures can be implemented in various programming languages, including but not limited to C, C++, Java, Python, and more. For example, in Java, the built-in Java util, Tree Map and Java util. Tree Set classes are implementations of binary search trees. In Python, the collections module provides an ordered dict class which can be used to create a tree-like structure. Overall, the implementation of tree data structures in a programming language will depend on the specific requirements and use cases, as well as the available tools and libraries for that language. Tree transversal algorithms and their applications to real life problems Tree transversal algorithms are used to visit each node in a tree data structure in a specific order. There are several different transversal algorithms, including in-order, pre-order, post-order, and level-order transversal.
In order transversal visits the left sub tree, then the root and finally the right sub tree. This can be useful for tasks such as printing the nodes of a binary search tree in sorted order. Pre-order transversal visits the root first, then the left sub tree, and finally the right sub tree. This can be used for tasks such as creating a deep copy of a tree evaluating mathematical expressions in prefix notation. Post-order transversal visits the left sub tree, then the right sub tree, and finally the root. This can be helpful for tasks such as deleting a tree from memory or evaluating mathematical expressions in postfix notation. Level-order-transversal visits nodes level by level, starting from the root. This can be used for tasks such as finding the height of a tree or printing the nodes of a tree level by level.

These transversal algorithms have applications in various real life problems such as:s Decision making process: Decision trees are often used in decision-making processes, such as in business or finance. Transversal algorithms can be used to analyze and make decisions based on the structure of the decision tree. Expression evaluation: Transversal algorithms can be used to evaluate mathematical expressions represented as expression trees, by visiting nodes in the appropriate order and performing arithmetic operations. Directory structure navigation: In computer file systems, directory structures can be represented as trees. Transversal algorithms can be used to navigate through directories and perform operations on files and folders. Overall, tree transversal algorithms are fundamental to working with tree data structures and have a wide range of applications in real life problems across various domains.

monwinchimalang commented 7 months ago

https://1drv.ms/p/s!ArvrCfAnEC91gQaxK9vt2OX4f6a9?e=GPtpVC

monwinchimalang commented 7 months ago

https://1drv.ms/p/s!ArvrCfAnEC91gQaxK9vt2OX4f6a9?e=GPtpVC#include

include

Typedef struct Node { Int data; Struct Node left; Struct Node right; } Node;

Node createNode(int data) { Node newNode = (Node*)malloc(sizeof(Node)); newNode->data = data; newNode->left = NULL; newNode->right = NULL; return newNode; }

Void insert(Node* root, int data) { If (root == NULL) { root = createNode(data); } else { If (data <= (root)->data) { Insert(&(root)->left, data); } else { Insert(&(root)->right, data); } } }

Void inOrderTraversal(Node* root) { If (root != NULL) { inOrderTraversal(root->left); printf(“%d “, root->data); inOrderTraversal(root->right); } }

Int main() { Node* root = NULL; Insert(&root, 10); Insert(&root, 5); Insert(&root, 15); Insert(&root, 8); Insert(&root, 3);

Printf(“Inorder traversal of the binary tree: “);
inOrderTraversal(root);

return 0;

}