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 ...
A height balanced search tree is the one in which the difference of height of the left subtree and height of the right subtree is not more than one for each node. Height of a tree node - Length of the longest path from the node to the leaf node. The height of a tree is the height of its root node and the height of a leaf node is 0. Check this article - Calculate the height of a binary tree Now before creating a height balanced search tree let's understand why do we need a height balanced BST ? We know that a Binary Search Tree (BST) is a binary tree in which for each node its left child node is less than the node and right child node is greater than the node itself. This property of the BST makes it suitable for search operations because while searching for a key during tree traversal, on each node we can eliminate the traversal of one entire subtree of the node (left subtree or right subtree) based on the value of search key. For example let's try searching th...
I this problem we have to reverse the nodes of the Linkedlist k at a time and leave the remaining nodes if number of nodes is not a multiple of k. For example If we have a LinkedList having 11 nodes and we are asked to reverse it for k=3 nodes at a time, we will reverse first 3 elements then next 3 elements and then again next 3 elements and leave the last 2 elements as it is. Check below diagram to understand the example - Approach : First we will find the size of the LinkedList and divide it by k to know the number of groups which needs to be reversed. We will write a recursive method which will reverse the group of k nodes and return the last node of the reversed group. We will call this recursive function for all the groups which needs to be revesed. In above example list size is 11 and value of k is 3 so we will get total 11/3 3 groups which needs to be reversed leaving the last 2 ekements unchanged. To revese the pointed of a node we will use simple iterative approach ...
Spring Cloud is a Spring module which provides the features to make the development of distributed cloud-based applications simple and quick. Spring cloud configuration server is also one of the features which help us in the configuration management of distributed applications. In this article, we will discuss how spring cloud configuration can be used to externalize and manage the configurations of different distributed applications for different environments from a single place. We will be using a git repository as a configuration store which is considered an ideal choice. 1. Setting up Configuration Server - We will create a simple spring boot application which with the help of some dependencies will work as our configuration server serving configuration to our client application using a git versioned configuration store. 1.1 Create a spring boot application with below-required dependencies and import it to your IDE. <dependency> <groupId>org.springfra...
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 ...
Comments
Post a Comment