How to calculate First Common Ancestor of two Nodes in Binary Tree
First try to understand question. Its a binary tree, not a binary search tree…
May 15, 2019
It is one of a simple algorithm to study for a beginner to understanding sorting algorithms.
In this algorithm, we start with 0th index value. We compare it in whole array to find if any other number is smaller than this. So effectively, we find the minimum number through rest of the array from our starting index.
And, we swap the numbers of the initial number and the smalles number found in array.
See the code here:
public void sort(int[] arr) {
int l = arr.length;
for (int i=0; i<l-1; i++) {
int smallestNumIndex = i;
for (int j=i+1; j<l; j++) {
if (arr[smallestNumIndex] > arr[j]) {
smallestNumIndex = j;
}
}
if (i != smallestNumIndex) {
//swap
int temp = arr[i];
arr[i] = arr[smallestNumIndex];
arr[smallestNumIndex] = temp;
}
}
}
The algorithm runs on O(n^2) in worst/average case.
First try to understand question. Its a binary tree, not a binary search tree…
This algorithm is very efficient one, and is classic example of Divide and…
Introduction You are given an array of integers with size N, and a number K…
Sorting Problems Merge Sort Quick Sort Heap Sort Bubble Sort Selection Sort…
Problem Statement You are given an array prices where prices[i] is the price of…
A Binary tree is a data structure which has two children nodes attached to it…
Introduction This post has the complete code to send email through smtp server…
Introduction In a normal email sending code from python, I’m getting following…
Introduction In one of my app, I was using to talk to . I have used some event…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…