Sort Linked List using Merge Sort.
Given a Linked list, Sort it using Merge Sort Algorithm.
Merge sort is preferred algorithm for sorting a linked list, lets see why,
The way linked list is structured which doesn't allow random access makes some...
Home
»
Archives for 2015
Sort Linked list using Merge sort.
in
Algorithm,
Datastructure,
Interviews,
Java,
Linked List,
Sorting
- on 11:37:00
- No comments
Tower Of Hanoi
in
Algorithm,
Datastructure,
Java
- on 05:23:00
- No comments

Tower Of Hanoi
Lets understand what is the input and the expected output.
So the question is, You have given a 3 Peg (Start peg, Auxiliary/helper peg and End Peg) Start peg contains 3 disks of different sizes as shown. You have to move all the...
Find Nth node from last in a linked list
in
Algorithm,
Datastructure,
Interviews,
Java,
Linked List
- on 12:04:00
- No comments

Find Nth node from last in a linked list
Lets understand what is the input and the expected output.
Find middle element of the Linked list
...
Reverse a Linked list
in
Algorithm,
Datastructure,
Java,
Linked List
- on 20:27:00
- No comments

Reverse a Linked list
Lets understand what is the input and the expected output.
...
Detect loop in linked list.
in
Algorithm,
Datastructure,
Interviews,
Java,
Linked List
- on 10:47:00
- No comments

Detect loop in Linked list. Identify start node of loop in Linked list. Remove loop in Linked list.
What is Loop in Linked list?
Generally, the last node of the linked list points to NULL, which is a indication of end of list.But in Linked list containing...
Number Range Spinner in Angular JS
in
AngularJS
- on 10:29:00
- No comments

Number Range Spinner.
...
Diameter of Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 10:56:00
- No comments

Find diameter of Binary Tree.
What is Diameter of a Binary Tree?A longest path or route between any two nodes in a tree is called as Diameter/Width of binary tree. The diameter of tree may or may not pass through the root.
The diagram below shows...
Find Kth largest element in BST(Binary Search Tree)
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 08:35:00
- No comments

Find Kth largest element in Binary Search Tree.
Lets understand the problem statement correctly, What is the Input and the expected output.
...
Find Kth smallest element in BST(Binary Search Tree)
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 21:02:00
- No comments

Find Kth smallest element in Binary Search Tree.
Lets understand the problem statement correctly, What is the Input and the expected output.
...
Heap Sort Algorithm
in
Algorithm,
Datastructure,
Sorting
- on 10:05:00
- No comments

Heap Sort.
Before looking into Heap Sort, let's understand what is Heap and how it helps in sorting.
What is Complete Binary Tree?
A Complete binary tree is a binary tree in which every node other than the leaves has two children. In complete binary...
Check If two strings are Anagrams.
in
Interviews,
Miscellaneous,
Strings
- on 03:35:00
- No comments

Check 2 strings are anagrams of each other.
What is Anagram?
An anagram is a rearrangement of the letters of one word or phrase to another word or phrase, using all the original letters exactly once.
Example: 1. "evil" and "vile" is anagram...
Find all subsets of a set (Power Set)
in
Algorithm,
Bit Manipulation,
Interviews,
Java
- on 13:26:00
- No comments

Print power set of any given set OR Print all subsets of a set OR Find all subsets of a set OR Print all subset of an array.
Given a set of numbers, print all the possible subsets of it including empty set.
What is Power Set?
In mathematics, the...
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord.
in
Algorithm,
Graph,
Miscellaneous
- on 21:53:00
- No comments

Word Ladder ( Doublets / Word-links / Word golf )
Given two words, startWord and endWord, and a dictionary, find the length of shortest transformation sequence from startWord to endWord.
Rules:
1. Only one letter can be changed at a time.
2. Each...
Print Nodes in Bottom View of Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 05:30:00
- No comments

Print the bottom view of Binary Tree
Given a binary tree, print the nodes that is visible, when the tree is viewed from the bottom.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
Bottom...
Print Nodes in Top View of Binary Tree
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 23:04:00
- No comments

Print the top view of Binary Tree
Given a binary tree, print the nodes that is visible, when the tree is viewed from the top.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
Top view means,...
Print a Binary Tree in Vertical Order. Find Vertical Sum of given Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 04:28:00
- 2 comments

Print Binary Tree in Vertical Order ORPrint the Binary Tree in Vertical Order Path ORVertical order traversal of a Binary Tree. Find Vertical Sum of given Binary Tree
Given a binary tree, print it vertically.
Let us first understand what we want...
What is Load factor and Rehashing in Hashmap?
in
Java
- on 03:11:00
- No comments

What is Load factor and Rehashing in Hashmap?
This is the famous interview question for experienced, So Let's see what it is all about.
Hashmap is very popular data structure and found useful for solving many problems due to O(1) time complexity...
How time complexity of Hashmap get() and put() operation is O(1)? Is it O(1) in any condition?
in
Java
- on 23:39:00
- No comments

How time complexity of Hashmap get() and put() operation is O(1)?
This is the famous interview question for the beginners as well as for experienced, So Let's see what it is all about.
Hashmap is very popular data structure and found useful for...
How Hashmap data structure works internally? How hashcode and equals method work in hashmap? Explain with real time example.
in
Java
- on 12:28:00
- No comments

Hashmap data structure works internally?How hashcode and equals method work in hashmap?
This is the famous interview question for the beginners as well as for experienced, So Let's see what it is all about.
Hashmap is very popular data structure...
What is Hashmap data structure? What is the need of Hashmap? How Hashmap data structure API works in Java? What is Hashcode? Can 2 objects have same hashcode?
in
Java
- on 13:15:00
- No comments

What is Hashmap data structure?What is the need of Hashmap?How Hashmap data structure API works in Java?What is Hashcode?Can 2 objects have same hashcode?
This is the famous interview question for the beginners as well as for experienced, So Let's...
How PreparedStatement in Java prevents SQL Injection?
in
Database,
Java
- on 11:53:00
- 2 comments

What is PreparedStatement in java?Why use PreparedStatement in Java JDBC? How prepared statement prevents SQL Injection?Difference between Statement and PreparedStatement in Java?
This is the famous interview question for the beginners, So Let's see...
What is SQL Injection?
in
Database
- on 02:38:00
- 4 comments

Explain SQL Injection along with example?
This is the famous interview question for the beginners, So Let's see what it is all about.
SQL Injection is code injection technique where SQL is injected by user (as part of user input) into the back end...
Boundary Traversal of Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 15:00:00
- No comments

Boundary Traversal of binary tree ORPrint Circumference of Binary Tree ORGiven a Binary Tree, Print its Perimeter ORPrint outside nodes of Binary Tree ORPrint Edge nodes of Binary Tree ORPrint Boundary of Binary Tree.
We have to print the boundary...
Zig Zag Traversal of Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 12:18:00
- No comments

Level order traversal in spiral form ORPrinting a Binary Tree in Zig Zag Level-Order ORPrint a binary tree in Zig Zag way.
Given a binary tree, write a program to print nodes of the tree in spiral order. You can also say it as Spiral order traversal...
N Queens puzzle Optimized.
in
Backtracking
- on 05:12:00
- No comments

The N Queen is the problem of placing N Chess queens on an N×N chessboard so that no two queens attack each other.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
You are given a chess board...
N Queens Puzzle.
in
Backtracking
- on 14:10:00
- No comments

The N Queen is the problem of placing N Chess queens on an N×N chessboard so that no two queens attack each other.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
You are given a chess board...
Find the element that appears once others appears THRICE.
in
Array,
Bit Manipulation,
Java
- on 12:19:00
- No comments

Find the element that appears once others appears THRICE.
Given an array of integers. All numbers occur thrice except one number which occurs once. Find the number in O(n) time & constant extra space.
Let us first understand what we want to achieve?...
Find the element that appears once others appears TWICE.
in
Array,
Bit Manipulation,
Java
- on 04:50:00
- No comments

Find the element that appears once others appears TWICE.
Given an array of integers. All numbers occur twice except one number which occurs once. Find the number in O(n) time & constant extra space.
Let us first understand what we want to achieve?...
Construct a Binary Tree from In-order and Pre-order traversals.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 02:17:00
- 2 comments

How to construct a Binary Tree from given In order and Pre order traversals.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
Question:
Two traversals are given as input,
int inorder[] =...
Construct a Binary Tree from In-order and Level-order traversals.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 15:43:00
- No comments

How to construct a Binary Tree from given In order and Level order traversals.
Let us first understand what we want to achieve? what is the input and what will be the expected output?
Question:
Two traversals are given as input,
int[] inOrder...
Connect nodes at same level in a binary tree using constant extra space.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 11:23:00
- No comments

How to connect nodes at same level using constant extra space? ORPopulate next right pointers for each Tree Node? ORConnect nodes of a binary tree at same Level?
Let us first understand what we want to achieve? what is the input and what will be the...
Connect nodes at same level in a Binary Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 14:15:00
- No comments

How to connect nodes at same level using Queue? ORPopulate next right pointers for each Tree Node? ORConnect nodes of a binary tree at same Level?
Let us first understand what we want to achieve? what is the input and what will be the expected output?
Question:...
Check if two trees are mirror images of each other
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 05:23:00
- 2 comments

How to check if two binary trees are mirror images of each other?
In this post we will look at algorithm to check if two trees are mirror images of each other with Java program.
See below image for better understanding of which Trees are called...
Check if two binary trees are identical
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure
- on 23:29:00
- 2 comments

Check if two binary trees are identical or not?
In this post we will check if given binary trees are identical or not using recursive approach.
See below image for better understanding of which Trees are called Identical and which not.
Check...
Binary Search Tree Operations ( Add a node in Binary Search Tree, Search a node in Binary Search Tree ).
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 02:18:00
- No comments

How to Add a Node and Search a Node in Binary Search Tree?
Let's see how to insert a node in binary search tree (BST) and search a node in binary search tree.
What is Binary Search Tree?
In computer science, Binary Search Trees (BST), sometimes...
Maximum Sum Contiguous Subarray using Kadane's algorithm.
in
Algorithm,
Array,
Datastructure,
Java
- on 03:44:00
- No comments

Find the maximum-sum subarray of an array. ORExplain Kadane's Algorithm to solve the Maximum Sum Subarray ORFind Largest Sum Contiguous Subarray.
The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional...
Delete a node in Binary Search Tree in Java
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 09:43:00
- No comments

How to delete a Node in Binary Search Tree in Java?
Let's see how to delete a node in binary search tree with example and java program.
There are 3 cases that need to be considered while deleting a node from Binary Search Tree.
Node to delete...
Binary Tree Traversals - Inorder, Preorder, Postorder, Levelorder
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 14:25:00
- No comments
What is Binary Tree Traversal?
Binary tree traversal is a way to read a tree by visiting each node in a particular manner.
We will look into three popular binary tree traversal, Inorder, Preorder and Postorder along with example.
Note: Tree...
Add a node in Binary Tree and not a Binary Search Tree.
in
Algorithm,
Binary Search Tree,
Binary Tree,
Datastructure,
Java
- on 12:46:00
- No comments

How to add a Node in Binary Tree and not a Binary Search Tree?
To add a Node in a Binary Tree, Let us first fix our protocol of how we are going a insert a node in Binary Tree.
Before going further, I would like to clear the difference between...
Print all possible strings of length K that can be formed from a set of N characters in Java
in
Algorithm,
Datastructure,
Java
- on 00:06:00
- No comments

Find all n length Permutation of a given String. OR Print all combinations/permutations of a string of length k that can be formed from a set of n characters. OR.Print all possible combinations of k elements from a given string of size n
Print all...