Skip to main content

Posts

DS PROBLEM :Find a pair with given sum in a BST(Binary Search Tree)

Problem :  Given a Balanced Binary Search Tree and a target sum, write a function that returns true if there is a pair with sum equals to target sum, otherwise return false. Expected time complexity is O(n) and only O(Logn) extra space can be used. Any modification to Binary Search Tree is not allowed. Note that height of a Balanced BST is always O(Logn). Solution: There are two approaches to solve the problem The  Brute Force Solution  is to consider each pair in BST and check whether the sum equals to X. The time complexity of this solution will be O(n^2).
Recent posts

Design Discussion over Microservices Adaption

 Terms that are most commonly used in any microservices architecture Don't worry after watching so many new terms as below : Saga Pattern Bounded context Eventual consistency Event Command Execution  Event broker CDC (change data capture) event managment Domain driven design Event driven design CQRS (Command query responsibility segregation) Rollback operation  Asynchronous Callback operation Fault tolerance :Bulk Head & Circuit breaker Open API configurations Centralized logging ELK Stats aggregation Aggregates in Domain Driven Design FAT Domain VS Anemic Domain Ubiquitous Language  Event sourcing Event replay Scatter-Gather Pattern Saga Pattern:      A pattern which is the heart soul of any microservice architecture ,it is used to manage data consistency across multiple microservices in distributed transaction .It performs a sequence of local transactions which perform updation operation in services & publish a message or trigger the event. There are below three type of t

Before Starting MicroServices just walk through Orchestration !! Matters a lot

What is this Orchestration : Orchestration is the traditional way of handling interactions between different services in Service-Oriented Architecture (SOA). With orchestration process, there is typically one controller that acts as the “orchestrator” of the overall service interactions. This typically follows a request/response type pattern. For example, if three services needed to be called in a particular order, the orchestrator makes a call to each one, waiting for a response before calling the next. 

Filtering for your restful webServices

Filters are one of the important features provided by the JAX-RS framework. It is used in various contexts. It may be applied on either request to a resource or the response from a resource, or both.Consider a scenario in which we do not want to show some class members in the response. This process is called filtering. Jackson has two annotations that are used in filtering are:  @JsonIgnore  and  @JsonIgnoreProperties . @JsonIgnore  is used at field level to mark a property or list of properties to be ignored. import java . io . IOException ; import com . fasterxml . jackson . annotation . JsonIgnore ; import com . fasterxml . jackson . databind . ObjectMapper ; public class JacksonSampleTest { public static void main ( String args []){ ObjectMapper mapper = new ObjectMapper (); try { Student student = new Student ( 1 , 11 , "LABORATORY" , "SAMUEL" ); String jsonString = mapper

10 points to know about volatile variable in JAVA?

Volatile variable have some specific uses.It's better to know all the major reason  why java adopt such variables .Please found the below 10 points which need to be noticed: 1.Volatile variable always get allocated in the main memory.To allocate any variable in main memory volatile keyword is used. 2.Precisely volatile variable are always read and write directly from main memory.It doesn't perform any operation from CPU 's cache. 3.Volatile variable after JAVA 5 guranatees the visibilty of changes to variable across multiple threads. 4.Volatile also provide atomicity in some cases e.g .while reading double and long data types. 5.In case of volatile long and  volatile double data types which are of 64 bytes the read operation is atomic. 6. If you know that a long field is accessed by more than one thread e.g. a counter or anything, you better make it volatile. Why? because reading to a long variable is not atomic in Java and done in two steps, If one thread is w

LOVE THE WAY SINGLETON PATTERN CAN BE DESIGNED ! WOWW...

To implement Singleton pattern, we have different approaches : 1.Eager initialization: In this method the instance of clss is created at loading time .As whenever in java there is a requirement of species at loading time we first remember of Static keyword. package com.questprogram.singleton; public class EagerInitializedSingleton { private static final EagerInitializedSingleton instance = new EagerInitializedSingleton(); //private constructor to avoid client applications to use constructor private EagerInitializedSingleton(){} public static EagerInitializedSingleton getInstance(){ return instance; } } 2. Static block initialization Static Block initialization implementation is similar to eager initialization, except that instance of class is created in the static block that provides option for exception handling. package com.questprogram.singleton; public class StaticBlockSingleton { private static StaticBlockSingleton in

Immutability!!.How to achieve over classes/methods/variables?

The only way to achieve immutability of class is as followed