Abnormal internet connection

I am experiencing some abnormal internet connection issues now.

-Using default DNS server(DNS server from NUS)

It appears that I can open some websites in the browser without any issue, such as Bing, wordpress, quora.

However, pinging these websites does not give good response:

ping1

For other websites like Facebook and Google, Google News, they open rather slow in web browsers and sometimes does not even load.

Pinging them also yields poor result:

ping2

After changing DNS server into Google’s 8.8.8.8, the problem remains.

This should be an issue with NUS network as websites such as Facebook and Google loads on my phone(with 3G connection) in usual speed.

Tip and tricks on using the eclipse

I have learnt from CS2020 a few useful tricks to make my life easier and an enjoyable one when using the eclipse.

This is a feature, not a tip, but I really like the automatic indentations in eclipse. When copying and pasting codes, they are automatically indented in the context, saving the trouble of indenting them manually.

Here are some useful short-cuts and tips I learnt so far.  This list may be expanded in the future.

Multiple edits (of the same variable name)

Alt + Shift + R

Very useful for changing the name of variable halfway

Auto-complete

Crtl + Space

This is like tab in linux and sublime text. eg. sysout in java will be auto-completed as System.out.println();

Auto format

Ctrl + Shift + F

Automatically add or delete extra spacings to make code neat and clear, also fixes the over-lengthy lines

Auto fix import

Ctrl + Shift + O

Automatically add the necessary imports and delete unnecessary imports for the class

Auto-add getters and setters

Source – Generate Getters and Setters

This automatically add these two classic methods to the class body

Extract method

Select the code and right click and choose Refactor, extract method

This helps to break down a long method to several sub-methods to make the code more organized, also helps to maintain layers of abstraction by establishing hierarchy in methods.

CS2020 Learning Sorting

Sorting was one of the first things that I learnt for programming, and inevitably we had to go through this as part of this algorithm module.

The truth is I never really paid much attention to sorting until now, since I  knew that I can just use the buit-in qsort function in most cases. However, this is certainly not we learnt during this module, and we are dealing with more problematic sorting, involving analysis of different types of sorting algorithm in terms of running time and space usage(and I realised what we have learnt from past few weeks is very similar to the first two chapters of book Introduction to Algorithms)

The different sorting methods covered so far are:

  • Bubble sort Stable

A total of n iterations for n inputs, for each iteration, swap the two neighbouring elements if they are not sorted.

Bubble sort has a loop invariant – at the end of jth iteration, the biggest j elements are correctly sorted in the final j positions in the array

Running time is O(n²), best case is O(n) if array is already sorted, Space usage is O(n).

  • Selection sort  Unstable

A total of n iterations for n inputs, for each iteration, find the smallest element from unsorted part and put it(by swapping) at the end of sorted part.

Selection sort also has a loop invariant – at the end of jth iteration, the smallest j elements are correctly sorted in the first j positions in the array

Running time is O(n²), best case is O(n) if array is already sorted, Space usage is O(n).

  • Insertion sort  Stable

A total of n iterations for n inputs, for each iteration, put the first unsorted element  to the correct position of the sorted part.

Insertion sort has a loop invariant, which is slightly different from selection sort – at the end of jth iteration, the first j positions in the array is sorted, however, they may be subjected to “insertion” on the subsequent iterations.

Running time is O(n²), best case is O(n) if array is already sorted, Space usage is O(n).

  • Merge sort  Stable

It uses the idea of divide and conquer, divide the array into two halves on each iteration and sort them during the merging process. It is relatively easier to sort the array during merging as we assume that the arrays to be merged are already sorted in the first place.

Invariant – the arrays to be merged are sorted before the start of merging.

Running time is O(n log n), best case is still O(n log n) if array is already sorted, space usage is O(n log n) for a simple approach, which can be improved to  2n+O(1).

  • Quick sort Unstable(Classic)

For each iteration, a pivot is chosen and the array is partitioned into two parts, one part with all elements smaller than(or equal to) the pivot, the other part with all elements bigger than the pivot.

The invariant is the same as the mechanism of quick sort.

For the process of partition, running time is O(n), space usage is n+O(1), where O(1) accounts for the process of swapping. The running time for the whole process can be improved by optimizations(dealing with duplicates by three-way-partition and etc.). The worst case is O(n²).

The pivot can be chosen deterministically or randomly.

  • BogoSort Unstable

This sorting method involves choosing a random permutation of the array A and return it if it is sorted. A related joke(or maybe not) is QuantumBogoSort which uses quantum computing concept and many-worlds interpretation

[Good Article] Taking a “War of Words” Too Literally

I want to share an article that has influenced me a lot. This piece was given to me during one of the GP lesson when I was in junior college.

The following is adapted from Deborah Tannen’s Taking a “War of Words” Too Literally, (March, 1998), Washington Post

Everywhere we turn, there is evidence that, in public discourse, we prize contentiousness and aggression more than cooperation and conciliation. Headlines blare about the Star Wars, the Mommy Wars, the Baby Wars, the Mamography Wars; everything is posed in terms of battles and duels, winners and losers, conflicts and disputes. Biographies have metamorphosed into demonographies whose authors don’t just portray their subjects warts and all, but set out to dig up as much dirt as possible, as if the story of a person’s life is contained in the warts, only the warts, and nothing but the warts.

Continue reading

About everything and nothing

I have been thinking about this issue of being everything and being nothing for a while.

In CS1231 lecture, the lecture mentioned a quote that is something like”A friend of everybody is a friend of nobody.”

I also realized during sem1 that “greedy algorithm does not work in university.”, trying to do a lot of things simply makes me incapable of achieving anything.

This is true for my CCAs, when I took up too many duties and responsibilities, I just simply cannot accommodate all of them into my schedule. When I have friends from totally different cliques that are very exclusive in nature, I found myself hanging in the air, not belonging to anywhere.

So it is ture that we must abandon something in order to achieve others?