Comparing Arrays and LinkedList, we know it is easy for Array to access element(takes O(1)), but hard to insert or delete(takes O(n)), LinkedList is opposite, access element takes O(n), but deletion and insertion is easy(takes O(1)).

What about comparing elements and find a sepecfic elemnt in a sorted array?

Well, we can do linear search (O(n)). Loop through the elements in array and find out the value that is exact same as target value.

We can also use binary search: repeatedly dividing the search interval in harf to narrow down the search. Binary search only takes O(logn) time complexity.

Continue reading

Recently I found when I use a boolean value in multiple threads, it is not thread-safe enough. For example, in one thread you are writing values for a boolean value, in another thread you are checking the boolean in order to process the thread. How does the program know the value when you check? This suitation also happens in other values not limited to boolean.

We should aviod checking and writing a value in multiple thread in the same time. Here is a simple solution I found: use java.util.concurrent.atomic package. Atomic Collections support lock-free thread-safe programming on single variables.

Continue reading
  • page 1 of 1
Author's picture

Amy Zhu

To learn without thinking is blindness, to think without learning is idleness.


Mapsted Software Engineer


Toronto, ON