Posts

Showing posts with the label computer science

Understanding how a recursion really works (recursion from the ground up)

Image
If you're into programming and really have problem on such algorithm that you wanted to implement, however requires a recursive call (or can be an iterative call --but we'll discuss on recursion for this topic). Take note on recursion that they are, using much more memory than using iteration because it copies or clones the elements in the function that tries to recurse. So it makes new copies of: the code local variables with its initial variables paramaters it's more expensive as it retains clones into the memory which I am pertaining the variables, params, code in the stack it's usually slower due to overhead in maintaining the stack Each copy of the code includes a marker indicating the current position. When a recursive call is made, the marker in the old copy of the code is just after the call; the marker in the "cloned" copy is at the beginning of the method. When the method returns, that clone goes away, but the previous ones are still t...

Taking notes: Complexity of Algorithms (using Java)

Just wanted to take this as my own notes from  http://introcs.cs.princeton.edu/java/41analysis/ . Just take not that from Quadratic algorithm down below, aren't just that perfect algorithms that you would enjoy when handling large data structures. Complexity Description Examples 1 Constant  algorithm does not depend on the input size. Execute one instruction a fixed number of times Arithmetic operations (+, -, *, /, %) Comparison operators (<, >, ==, !=) Variable declaration Assignment statement Invoking a method or function log N Logarithmic  algorithm gets slightly slower as N grows. Whenever N doubles, the running time increases by a constant. Bits in binary representation of N Binary search Insert, delete into heap or BST N Linear  algorithm is optimal if you need to process N inputs. Whenever N doubles, then so does the running time. Iterate over N elements Allocate array of size N Concatenate two string of length N N log N L...