Posts

Showing posts from May, 2015

What the Heck is the Big O Notation?

Image
The Idiots Guide to Big O I hate big O notation. For as long as I can remember it’s been my biggest achilles heel (of which I have many). It’s just something I’ve never managed to successfully motivate myself to learn about despite knowing it’s going to come up in every single interview. I’ll get asked to implement an algorithm which I’ll do via brute force to start with: “What is the Big O of that?”. “I don’t know Big O but I know it’s slow”. This is the wrong attitude and the wrong approach, and I have finally decided it is time to face my demons. All the resources I’ve found online I’ve sent me quickly to sleep, so I am determined to create an accessible Big O mastery page. What on earth is Big O? Big O is the way of measuring the efficiency of an algorithm and how well it scales based on the size of the dataset.  Imagine you have a list of 10 objects, and you want to sort them in order.  There’s a whole bunch of algorithms you can use to make that happen, but not all

Java XML Parsing Made Easy

Unlike with many other modern languages, parsing XML in Java requires more than one line of code. XML traversing using XPath takes even more code, and I find this is unfair and annoying. I'm a big fan of XML and use it it in almost every Java application. Some time ago, I decided to put all of that XML-to-DOM parsing code into a small library —jcabi-xml. Put simply, the library is a convenient wrapper for JDK-native DOM manipulations. That's why it is small and dependency-free. With the following example, you can see just how simple XML parsing can be: import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; XML xml = new XMLDocument(   "<root><a>hello</a><b>world!</b></root>" ); Now, we have an object of interface XML that can traverse the XML tree and convert it back to text. For example: // outputs "hello" System.out.println(xml.xpath("/root/a/text()").get(0)); // outputs the entire XML d