Posts

Showing posts from January, 2023

Inversion Count In Array Using Merge Sort

Image
  Inversion count is surely one of the most asked interview topics!  Most of the time interviewers don’t resist themselves in regard to asking questions related to the inversion count.  The concept may seem  challenging, but once learned it can become quite interesting.  Count inversion in any given array indicates how far your array is from being sorted. If your array is already sorted, the inversion count would be 0. Though, if it is sorted in the r everse level order traversal, your inversion count will be maximum.  The spectrum of this concept is quite wide. One topic that will be commonly asked is; inversion count in a given array using merge sort.  Well, if you are on this subject and want to have a better detailing of it, we got you covered!  Here, in this blog, we are going to uncover all the essential information related to inversion count with merge sort.  Without any ado, let’s get started! About inversion in array Number of cou...

Build the binary search tree from a preorder sequence

Image
The Binary Trees are fundamentally one of the most efficient data structures that provides their own methods of traversal for a problem set. What's fun about the Binary Trees is that you can basically use the four different traversal methods such as in-order, level order, preorder and post order traversals for navigating through the structure for finding the right solution. This essentially means that on a surface level, one is not required to find other algorithms and approaches for solving Binary Tree problems. One such algorithm is the preorder traversal method that is the topic of discussion of the blog!  Did you know by revoking the BST in preorder algorithm, you can construct the binary search tree within a program? Which is why, the intent of this blog is to provide more detailed information for Preorder Traversal in the BST and the algorithms related to this approach. What do you mean by Pre-Order Traversal in a Binary Tree? Did you know that there are essentially four dif...

What is the time complexity of the combination sum?

Image
  Do you know? The time complexity varies for different coding problems!  The amount of time an algorithm needs to run as the input size initiates is measured by its time complexity.  The time complexity is denoted by Big ‘O’ notation, it describes the running time's upper bound.  In this blog, you will get to know about a specific coding problem known as combination sum time complexity.  Combination sums is where you have to achieve a target using various given values.  Different approaches have different time complexities, finding the one that is the most efficient is important. So, read till end you will get to know the one which can help you solve the sum combination problem with reduced time complexity.  First, let’s take a brief about combination sum problem. What is the Combination sum? Combination sum is a problem where you are provided with a set of unique positive integers along with a target value. The goal is to identify every single comb...

Reverse Level Order Traversal Of A Binary Tree

Image
  Ask a coding wizard of how amazing and iconic the Data structure and algorithms concept is! Truly, DSA’s aspects are super interesting to learn and are extremely useful for every coder.  Almost everything around us in this world has the essence of some DSA concept.  For eg: The leaves of a particular tree follow the Fibonacci pattern whereas the tree itself is transformed into a concept called Binary tree.  Isn’t it amazing how the world runs on mathematics and codes?  To exemplify your excitement, we’re particularly going to pick out Binary tree as our main study and dive into its sub-aspect called r e verse level order traversal . Let us have a detailed look into the basics before we move to learn about the problem.   What is a binary tree? A binary tree has parent nodes and each of those parent nodes can have two children nodes that are left and right nodes. Similar to the real-life tree, there is a source called “root” which is where the binary tree ...