Category: Algorithms

Tree Traversal code implementation in Recursive and Iterative Ways

1. Description Recursive way is based on computer program, the function calling stack. While iterative way is programmer use stack to simulate it. 2. Solution

Read More

Base 7

1. Description Given an integer, return its base 7 string representation. 2. Example 3. Solution 4. Complexity Time: O(n) Space: O(1)

Read More

Best time to buy and sell stock – one time transaction

1. Description Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock […]

Read More

Word Pattern

1. Description Give a pattern and a string, and check if the string follows the pattern. 2. Example 3. Solution 3.1 Wrong solution First, I was thinking, if I can use the AscII code to represent the pattern. For example: hello -> ‘a’, and hello -> ‘a’, world -> ‘b’, world->’b’. Use the data structure […]

Read More

Collections & Arrays Class in Java SE

Java Utils Class, Arrays and Collections, including the commonly used methods.

Read More

Game Simulation

How to play dice game? Try this challenging, you will learn a lot of using ArrayList and Loop.

Read More

Binary Search Tree (BST)

A BST is a rooted binary tree, whose internal nodes each store a key, and each have two distinguished subtrees, commonly denoted left and right.

Read More

Binary search – locate target fast in O(logn)

Binary search is an efficient algorithm for finding an item from a sorted list of items. Here you will find several morphs with the source code.

Read More

Remove Duplicates from sorted LinkedList

Give a list of sorted numbers, delete all duplicates such that each element appear only once. Time complexity must be in O(n).

Read More

Bucket Sort, Bubble Sort, Selection Sort, and Quick Sort

Sorting is really important in software development. This article brings the four sort algorithms, which are Bucket Sort, Bubble sort, selection sort and quick sort.

Read More