2014년 3월 30일 일요일

Week 11: Sorting and Efficiency

Efficiency in general, describes the extent to which time, effort or cost is well used for the intended task or purpose.  – definition from Wikipedia

When we talk about efficiency in Computer Science and programming, we see how much time is needed for a result of the code to be executed; that is usually calculated by how may “lines of code” are ran during the execution.
Ex) Which algorithm is better? - Algorithm A takes n^2 37 time units or Algorithm B takes n+45 time units, when n presents the input number(or size). OF COURSE algorithm B!
These matter much more when n gets larger, and usually there is not much difference when n is small. Which means efficiency only matters when n is a large number.

Big-O Notation - the time complexity(efficiency) of an algorithm is commonly expressed using big O notation, which suppresses multiplicative constants and lower order terms (of course since this deals with “efficiency”, we need to think n as a BIG number, as we discussed from the above)

Relationships between orders (for the basic Big-O’s)
O(1) < O(log n)
O(log n) < O(n)
O(n) < O(n log n)
O(n log n) < O(n^2)
O(n^2) < O(n^3)
O(n^x) < O(x^n), for all x and n

Than now, let’s look at sorting…
Many common sorts consists of nested loops (n^2)
Ex) Selection sort, Insertion sort, Bubble sort

Or you can sort recursively by dividing set into two pieces and sorting each piece recursively.
Ex) Merge sort, Quick sort




As we progress in learning in CS, we will be dealing with much more complicated algorithm; without thinking about efficiency, the program that is created will be less helpful and less appealing to the user. What we can see from the above is that there are several approaches to find best algorithm to sort, which means that there is no fixed answer for a problem(usually in real life situation as they are much more complex than just a plain sorting problem). Now our job as a programmer is to come up with new and better algorithm and compare with others to develop with what we already have to make the existing code efficient.

2014년 1월 21일 화요일

Week 3: Object-Oriented Programming

Object-Oriented Programming(OOP) is a programming paradigm that is used to design new software, just like procedure programming. However, unlike procedure programming, OOP is "Object" based rather than "action", which means that the program will operate to analyze and sort data according to the written classes and not operate case by case through logical procedure.

OOP's basic components:
- Class
-Object
- Method

By defining class, we can write a code that can be reused again and again for similar type of data (no need for repeated code). Also, it can give flexibility for the programmer in coding as the class and its methods can be used in many different ways, depending on the case. Furthermore, with OOP it is much easier to fix and maintain the code as it is all divided up (in most cases, you do not need to rewrite entire code).

As computers are developing at a very fast pace, the programming paradigm progressed to produce software that suits them. With great range of data and functions that the computer requires to work with, Object-Oriented Programming is a very important and necessary method for programming.