divide and conquer algorithm in java