IP Address from hostname in Windows and Linux
How many times in a day you have a hostname and you want to know the IP address? Host name to IP address and IP address to hostname conversion is one of frequent thing which we need to do for many things when dealing with networking command in unix. For one command we need IP address for other we need hostname even from bash script some time we require hostname and some time we look for IP address.
[Read More]
Skiplist vs Binary tree
Here are some of the differences
Skiplist
Binary tree
Concurrency - Skip lists are more amenable to concurrent access/modification. Inserting a node into a skip list is far more localized, only nodes directly linked to the affected node need to be locked. pressure.
The most frequently used implementation of a binary search tree is a red-black tree. The concurrent problems come in when the tree is modified it often needs to rebalance.
[Read More]
Skiplists
Goal
To understand skiplist.
Definition
Skiplist is a dynamic search structure, as it is dynamic when it comes to insertion and deletion, which supports search).
Other dynamic search structure:
Treaps Red black tree B-Trees (2-3 trees etc) Operations on skiplist
Search - O(log n) Insert - O(log n) Delete - O(log n) These operations are with high probability, 1/polynomial depending on polynomial number of operation.
[Read More]
Max submatrix sum in a matrix
Problem
Given an NxN matrix of positive and negative integers, write code to find the sub- matrix with the largest possible sum.
Solution
This is DP problem. Here is the good solution.
References
Find max subsquare whose border values are all 1
Problem Imagine you have a square matrix, where each cell is filled with either black or white. Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.
Solution We are going to scan column by column, checking to see if this column can be the left-border of the desired subsquare. Along each column, we build “sliding windows”, from large size to small size.
[Read More]
Transform one word into another by changing only one letter at a time
Problem Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step must be in the dictionary.
EXAMPLE
Input: DAMP, LIKE
Output: DAMP -> LAMP -> LIMP -> LIME -> LIKE
Solution Try thinking this problem in terms of graphs: Consider all words in a dictionary as vertices, and insert an edge between each two vertices that differ by only one letter.
[Read More]
Search a long string for small strings in an array
Problem Given a string s and an array of smaller strings T, design a method to search s for each small string in T.
Solution Method 1 - Using suffix tree
We can first get all the suffices of s and check for each element t in T to see if t is the beginning part of any suffices. To make this more efficient, we can build a suffix tree and do the operations.
[Read More]