Tuesday, November 22, 2016

Big-O Notation

By National Institute of Standards and Technology (NIST), the definition of Big-O notation is a "theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. " In essence, an algorithm's big-o notation is determined by how effectively it responds to different input, n. Would the process rate be different if we have 100,000 inputs instead of 10 inputs?

The measure of the execution can be expressed as f(n)=O(g(n)). O function is the order function, f(n) is your algorithm, and g(n) is the function you use to estimate f(n). For example, if you f(x)=n^2+3n-40. As n approaches infinity, the value of (3n-40) does not matter as much as n^2, so we can use n^2 to estimate your f(x). Below are some typical Big-O notations:



  • O(1) is the constant time function, where it takes the same amount of time to process any size of inputs. An example of O(1) algorithm is to determine if the binary input in odd or even. 
  • O(log n) is very efficient to analyze large inputs. The growth peaks at the beginning the marginal time decreases as you increase the number of inputs. For example, the algorithm takes 1 second to analyze the first 100 times, but only take 2 seconds to analyze the first 1000 items.  An example of O(log n) algorithm is to find an item in a sorted array.
  • O(n) is the linear function, where the time is proportional to the size of input. An example of O(n) algorithm is to find an item in a unsorted array.
  • O(n^2) is an quadratic algorithm that processes inner loops. An example would be what we learned in class on Thursday - bubble sort.
  • O(n^n) is an algorithm whose performance is proportional to the square of the size of inputs. To process each element, it will go through the entire set of data. An example would be merge sort.
--------------------------------------------------------------------------------------------------------------------------
Picture References:
1.https://www.google.com/search?q=big+o+notation&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjKg67hsMXQAhXnslQKHQQHBiQQ_AUICigD#imgrc=C161EKuPr8u7CM%3A
Writing References:
1. https://xlinux.nist.gov/dads/HTML/bigOnotation.html
2. https://justin.abrah.ms/computer-science/big-o-notation-explained.html
3. https://en.wikipedia.org/wiki/Big_O_notation
4. https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/
--------------------------------------------------------------------------------------------------------------------------

Tuesday, November 15, 2016

Everything about operators in Java

Remember in the midterm midterm, Professor Jory asked a question about operator as a bonus question? In fact, there are so many more different kinds of operators than what we learnt in class. Addition, subtraction, etc. are only a subset of operators, called arithmetic operators. 

Unary operators can be increment or decrement. (++), (-), (--) are all examples of unary operators. 

Binary operators has six major categories as listed in the picture above. We covered most of the arithmetic operator during the class. Assignment operator is (=) and it is used when you set the values of data, e.g. String name = "Cathy." Logical operators are (&&),(||), and (!). Relational operators are (==),(!=),(>),(<),(<=) or (>=), which we also discussed in the classroom. Compound operator performs operation on the two operands before assigning the result to the first operand. Compound operator works on both arithmetic and bitwise operator. There are 11 different kinds of operators and (+=) is the one we often use throughout this semester. The other compound operators include (-+),(*=),(/=),(%=),(&=),(|=),(^=),(<<=),(>>=),(>>>=).

The only operator we have never seen before is bitwise operator. Bitwise operator works on all integer data types including int, long, short, char, and byte. It converts all the integers to bits and perform bit-by-bit operations on integers. An example given on this website (https://www.tutorialspoint.com/java/java_basic_operators.htm) is a = 60 and b = 13. In binary world, a = 0011 1100 and b = 0000 1101. Bitwise operators include (&),( |), (^),(~),(<<),(>>) and (>>>). (&) is binary and, which copies a bit to the result if it exists in both operands, otherwise it will copy 0. (a&b)=0000 1100. (~) flips the bits, so (~a) returns 1100 0011. (<<) is binary shift and moves all the bits to the left. (a<<2) returns 1111 0000. (>>>) is zero fill right operator. The left operand is shifted by the number in the right operands and zero fills all the empty bits. (a>>>2) returns 0000 1111.

Ternary operator takes three operands and conditional operator is a ternary operator. The syntax for ternary operator is (?:) expressionA?expressionB:expressionC. Expression A is implicitly converted to a boolean. If it is true, expression B will be evaluated, otherwise expression C will be evaluated. A good example would be compute the minimum value of x and y. 

minimum = (x < y) ? x : y;
--------------------------------------------------------------------------------------------------------------------------
Picture References:
1.https://www.google.com/search?q=java+operator&biw=1280&bih=583&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjvzZnSoKvQAhXBylQKHcw5CLEQ_AUICygA#imgrc=G73VcUwBb5rsVM%3A
Writing References:
1. http://www.computernotes.in/java/core-java/operators-in-java/
2. https://www.tutorialspoint.com/java/java_basic_operators.htm
3. http://www.c4learn.com/java/java-operators/
4. https://www.tutorialspoint.com/cplusplus/unary_operators_overloading.htm
5. https://msdn.microsoft.com/en-us/library/e4213hs1.aspx
6. http://alvinalexander.com/java/edu/pj/pj010018

--------------------------------------------------------------------------------------------------------------------------

Wednesday, November 9, 2016

Inheritance: Single, Multilevel and Hierarchial

During the lab in Wednesday, we talked about inheritance. As we know, inheritance is one of the four design principles for object-oriented programs and it helps with the organization of large programs and has reusability feature. Inheritance is obtained by building new child classes from the existing parent classes. Through the magic word "extends," we can reuse and add all the methods and properties from the parent class. To reduce the chance of error and increase reusability, we can apply overriding and revise the methods in the parent class, instead of creating a new one. Inheritance represents IS-A relationship, also known as parent-child relationship.  

There are five types of inheritance in Java: single, multilevel, hierarchical, multiple and hybrid.  
However, there are only three types of them(single, multilevel, hierarchical) available in Java programming. 
Not supported directly in Java, multiple and hybrid inheritance are supported through interface. 

1. Single: one class inherits from the other
2. Multilevel: one class inherits from the other class which inherits from another
3. Hierarchical: multiple classes inherit from the same class
4. Multiple: one class inherits from multiple classes
5. Hybrid: a mixture of multilevel, hierarchical and multiple inheritance

The two diagrams below provide graphical representation of these types.
--------------------------------------------------------------------------------------------------------------------------
Picture References:
1.https://www.google.com/search?q=inheritance+java&biw=1280&bih=620&source=lnms&tbm=isch&sa=X&sqi=2&ved=0ahUKEwiZ7-WRjp3QAhXB5yYKHT0JBssQ_AUIBygC#imgrc=NTtuIobiMKjsUM%3AWriting
2. http://www.javatpoint.com/inheritance-in-java
References:
1.http://www.javatpoint.com/inheritance-in-java
2.https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
3.http://docstore.mik.ua/orelly/java-ent/jnut/ch03_04.htm

--------------------------------------------------------------------------------------------------------------------------


Friday, November 4, 2016

How does Netflix make recommendations?

Do you like Netflix?
Have you ever watched netflix and just could not stop watching it?
If you, have you ever wondered why Netflix always make those wonderful recommendations to you?

Your wonderful Netflix experience is based on Machine learning algorithms. The recommendation system on Netflix and other apps/websites use complex algorithm based on linear algebra and matrixes to determine which content you might like. The Algorithm for Netflix was also referred to as "rating prediction" algorithm, which was the most important system in Netflix and was researched in the Netflix Prize in 2006 as the "Netflix Recommendation Algorithm." 

There are two major algorithms that are being used right now: Restricted Boltzman Machines (RBM) and a form of Matrix Factorization, which is also referred as Singular Value Decomposition. These two algorithms take user input, run through to determine their preferences and interests and finally output the recommendation for users. Both of these algorithms contain some error and inaccuracies bur a linear blend of these two methods reduced the error margin significantly.

--------------------------------------------------------------------------------------------------------------------------
Picture References:
1.https://www.google.com/search?q=netflix+recommendation+system&source=lnms&tbm=isch&sa=X&ved=0ahUKEwigrObu3ZDQAhUF6CYKHbMKB9MQ_AUICCgB&biw=1257&bih=620#q=netflix&tbm=isch&tbs=rimg%3ACabzecxy0tsIIjilQUCjVaiql4Fx_1EXSAg32zmNGRo0kTcYaTEzXLj6mhshKArr74Kvr_1JicUsEGaUQTBlSzSePd0SoSCaVBQKNVqKqXEYjgkUhdbbLGKhIJgXH8RdICDfYR6yDoZR-bvTMqEgnOY0ZGjSRNxhE9_1vOiHwDGlioSCRpMTNcuPqaGEWltLkD-9BeoKhIJyEoCuvvgq-sRhbebbti3HIEqEgn8mJxSwQZpRBFOBZV95MKM8ioSCRMGVLNJ493RESAQ6MacSGeD&imgdii=P57_EbfDdSsDZM%3A%3BP57_EbfDdSsDZM%3A%3BcsgyFL_uUe6v3M%3A&imgrc=P57_EbfDdSsDZM%3A
Writing References:
1.http://www.businessinsider.com/how-the-netflix-recommendation-algorithm-works-2016-2
2.http://techblog.netflix.com/2016/02/recommending-for-world.html
3.https://www.quora.com/How-does-the-Netflix-movie-recommendation-algorithm-work#
--------------------------------------------------------------------------------------------------------------------------