Many times there is a need to externalize the logging configuration file in spring boot, so that without making any code level/ jar level changes we can easily change the logging configuration. For example If we deliver any spring boot application as a jar we dont want the logging file name to be hardcoded and to be present on any specific location, so If we have an opportunity to change the logging configuration file we can easily set the logging file location or name. Or take another example where we want to change the logging level or add logger for a new package we can easily do it if logging configuration file is externalized. Lets see how we can externalize logback loggin configuration file - Spring boot by default uses logback for logging and If we don't provide any configuration file It uses default configuration and prints logs in console. So if we want to make changes to the logback configuration we will have to create a logbacl configuration file. Follow below steps ...
Height of a Binary tree is the length of the path form its root node to its farthest leaf node or we can say the longest path from root node to any of the leaf node (here path means the link between two nodes). For example - height of the binary tree in the figure given below (Fig 1.0) is 3. As we can see that this tree has two leaf nodes 3 and 12 but node leaf 3 is the farthest from the root and length of the path between 10 (root node) and 3 (farthest leaf node) is 3 hence height of the tree is 3. From above example comes our algorithm to calculate the height of the tree, we will calculate the height of the left and right subtree of each node recursively and consider the height of the tree including the root node - adding one to the greater of the two heights (left and right subtree heights). Fig 1.0 Implementation - In below code we have implementaed a custom BST with a public method getHeight() which internaly calls another private method getHeight() passing root of the tree ...
Inorder is one of the ways to traverse a binary tree in depth first fashion. We have already discussed Inorder Traversal (Left, Root, Right) of a binary thee in our previous articles using recursive approach and using stack (without recursion). But in this article we will discuss Morris Traversal which is used to traverse a Binary Tree without using recursion or Stack. If you are interested in Inorder traversal using recursion or iterative approach using Stack, refer below articles - Tree Traversal - Depth First (Iterative/ Non Recursive Approach) Tree Traversals - Depth First (Recursive Approach) Explanation Morris Traversal - Suppose we have a binary tree as shown in the figure below. Now we already know that Inorder traversal follows this order - Left, Root, Right. And this sequence must be followed by all the sub trees as well. In-order traversal of this Tree would be - 2 3 4 5 6 8 10 In this sequence we can clearly see that after visiting the left node or left sub...
In this article we will see how we can write the insert method for a binary tree using recursive approach. We have already covered the iterative approach in this article - Binary Search Tree Insertion Iterative Approach with some basic details about binary search tree data structure. package ds.tree; public class BStree { private Node root; public BStree(int rootData) { this.root = new Node(rootData); } static class Node { int data; Node left; Node right; public Node(int data) { this.data = data; } } public void insertRecursive(int data) { insertRec(this.root, data); } private Node insertRec(Node root, int data) { if(root == null) return new Node(data); if(root.data < data) root.right = insertRec(root.right, data); else root.left = insertRec(root.left, data); return root; } public void printTree() { System.out.print(root.data + ", " + root.left.data + ", " + root.right.data); } } Notice that ...
Comments
Post a Comment