From time to time, bitwise operation could be useful or just for fun … 1) Tell if a number is odd/even Let’s take integer 19 for example. In binary 19 is 00010011, so, 00010011 00000001 (00000001 is 1 in binary)…

# Use Bitwise Operations in Java/C# and C/C++

# Huffman EnCoding – Greedy Compressing Algorithm

(I came across an interesting problem from Hackerank.com. Say you are given a string of “101010…00101” with fixed length and a binary tree of nodes, each node has its own left and right child, data and frequency. You are expected…

# Using sorted() in Python 3.X

0. First we need to talk about the difference between sort() and sorted(). sort() will change the order of list itself. While built-in sorted() returns another sorted list 1. Simple sorted() sorting a list: >>> l = [3, 2, 5…

# Synchronization, Lock and Semaphore in JAVA – MultiThreading 1.0

Advantages of Synchronization over Lock Synchronization is cleaner when just locking an object, because //if doSomethingCauseNFP() throws an exception, the Lock will NEVER be released ! //Then you need to put Lock.releaes() everywhere in try{}finally{{} to force Lock.release() is called…

# 2-D Matrix Rotation Problem – Try Without Feeling Desperate

Another might be diffcult Hackranker problem could have you put a bullet in your head for the first look … (PS, this is also one of Amazon coding interview questions) You are given a 2D matrix, a, of dimension MxN…

# Use “Heap” to improve performance of finding MEDIANS of a self growing list

Here, I will illustrate some great use of Heap (data structure) to improve your time complexity tremendously to find medians of a self growing integer list Approach #1: Use Collections.sort() //Because of Collections.sort(), time complexity is O(Nlog(N)) * O(N) private…

# 5 Practical Bash Commands for Logs Diagnosing & Text Transforming

I start this series for log diagnosing and text transforming. During my daily work, I need to constantly look for some proof of bugs/issues from all different log files recorded for troubleshooting the issues. And sometimes, I need to parse…

# Collections – Python 3.X

1. Collections.namedtuple() >>> from collections import namedtuple Car = namedtuple(‘Car’,’Price Mileage Colour Class’) xyz = Car(Price = 100000, Mileage = 30, Colour = ‘Cyan’, Class = ‘Y’) print xyz Car(Price=100000, Mileage=30, Colour=’Cyan’, Class=’Y’) print xyz.Class One example in practice :…

# BeautifulSoup + Python = Web Data Scrapping

Beautiful Soup is a Python library designed for quick turnaround projects like screen-scraping. Background and Goal: since I buy and sell antiques online, as most of other sellers, I sell on Etsy. I was interested at having a bigger picture…

# Helpful built-in functions – C++

1) Find min/max element in array using Algorithm built-in functions Complexicty: O(N) Date races: The objects in the range [first,last) are accessed.