Lunes, Enero 30, 2012

MERGE SORT

 

Merge sort is an O(n log n) comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945.[1] A detailed description and analysis of bottom-up merge sort appeared in a report by Goldstine and Neumann as early as 1948.

 

Merge sort



Merge-sort-example-300px.gif
An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent list. Finally all the elements are sorted and merged.
Class Sorting algorithm
Data structure Array
Worst case performance O(n log n)
Best case performance O(n log n) typical,
O(n) natural variant
Average case performance O(n log n)
Worst case space complexity O(n) auxiliary

 

 

Analysis

A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down).
In sorting n objects, merge sort has an average and worst-case performance of O(n log n). If the running time of merge sort for a list of length n is T(n), then the recurrence T(n) = 2T(n/2) + n follows from the definition of the algorithm (apply the algorithm to two lists of half the size of the original list, and add the n steps taken to merge the resulting two lists). The closed form follows from the master theorem.
In the worst case, the number of comparisons merge sort makes is equal to or slightly smaller than (n ⌈lg n⌉ - 2⌈lg n⌉ + 1), which is between (n lg n - n + 1) and (n lg n + n + O(lg n)).[3]
For large n and a randomly ordered input list, merge sort's expected (average) number of comparisons approaches α·n fewer than the worst case where \alpha = -1 + \sum_{k=0}^\infty \frac1{2^k+1} \approx 0.2645.
In the worst case, merge sort does about 39% fewer comparisons than quicksort does in the average case; merge sort always makes fewer comparisons than quicksort, except in extremely rare cases, when they tie, where merge sort's worst case is found simultaneously with quicksort's best case. In terms of moves, merge sort's worst case complexity is O(n log n)—the same complexity as quicksort's best case, and merge sort's best case takes about half as many iterations as the worst case.[citation needed]
Recursive implementations of merge sort make 2n − 1 method calls in the worst case, compared to quicksort's n, thus merge sort has roughly twice as much recursive overhead as quicksort. However, iterative, non-recursive implementations of merge sort, avoiding method call overhead, are not difficult to code. Merge sort's most common implementation does not sort in place; therefore, the memory size of the input must be allocated for the sorted output to be stored in (see below for versions that need only n/2 extra spaces).
Stable sorting in-place is possible but is more complicated, and usually a bit slower, even if the algorithm also runs in O(n log n) time (Katajainen, Pasanen & Teuhola 1996). One way to sort in-place is to merge the blocks recursively.[4] Like the standard merge sort, in-place merge sort is also a stable sort. Stable sorting of linked lists is simpler. In this case the algorithm does not use more space than that the already used by the list representation, but the O(log(k)) used for the recursion trace.
Merge sort is more efficient than quick sort for some types of lists if the data to be sorted can only be efficiently accessed sequentially, and is thus popular in languages such as Lisp, where sequentially accessed data structures are very common. Unlike some (efficient) implementations of quicksort, merge sort is a stable sort as long as the merge operation is implemented properly.
Merge sort also has some demerits. One is its use of 2n locations; the additional n locations are commonly used because merging two sorted sets in place is more complicated and would need more comparisons and move operations. But despite the use of this space the algorithm still does a lot of work: The contents of m are first copied into left and right and later into the list result on each invocation of merge_sort (variable names according to the pseudocode above). An alternative to this copying is to associate a new field of information with each key (the elements in m are called keys). This field will be used to link the keys and any associated information together in a sorted list (a key and its related information is called a record). Then the merging of the sorted lists proceeds by changing the link values; no records need to be moved at all. A field which contains only a link will generally be smaller than an entire record so less space will also be used.
Another alternative for reducing the space overhead to n/2 is to maintain left and right as a combined structure, copy only the left part of m into temporary space, and to direct the merge routine to place the merged output into m. With this version it is better to allocate the temporary space outside the merge routine, so that only one allocation is needed. The excessive copying mentioned in the previous paragraph is also mitigated, since the last pair of lines before the return result statement (function merge in the pseudo code above) become superfluous.
Merge sort can also be done with merging more than two sublists at a time, using the n-way merge algorithm. However, the number of operations is approximately the same. Consider merging k sublists at a time, where for simplicity k is a power of 2. The recurrence relation becomes T(n) = k T(n/k) + O(n log k). (The last part comes from the merge algorithm, which when implemented optimally using a heap or self-balancing binary search tree, takes O (log k) time per element.) If you take the recurrence relation for regular merge sort (T(n) = 2T(n/2) + O(n)) and expand it out log2k times, you get the same recurrence relation. This is true even if k is not a constant.

Biyernes, Enero 27, 2012

i love SAMSUNG :)

i  love SAMSUNG GALAXY NOTE :) HAHAHAHA
amazing ganda nang mga application sa loob hahahahaha
na egnorante ako pinakalit ... soon magkakaroon din ako...




Lunes, Enero 16, 2012

case study 5

HASHING
Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms.






HASH COLLISON

 

case study 4

1. What is hash collision?
It is desirable that Venti employ a cryptographic hash function. For such a function, it is computationally infeasible to find two distinct inputs that hash to the same value. This property is important because it prevents a malicious client from intentionally creating blocks that violate the assumption that each block has a unique fingerprint. As an additional benefit, using a cryptographic hash function strengthens a client's integrity check, preventing a malicious server from fulfilling a read request with fraudulent data. If the fingerprint of the returned block matches the requested fingerprint, the client can be confident the server returned the original data.

2. What really happens during a hash collision? Include an image.

hash collision is a measurement whose purpose is to detect very slight changes to data, or to determine whether or not two pieces of data are identical. Cryptographically useful hashing functions have some specific characteristics.




















3. What are the ways and methods to resolve hash collision? Explain Each



In a well-dimensioned hash table, the average cost (number of instructions) for each look up is independent of the number of elements stored in the table. Many hash table designs also allow arbitrary insertions and deletions of key-value pairs, at constant average.
Hash collisions are practically unavoidable when hashing a random subset of a large set of possible keys.

Lunes, Enero 9, 2012

Reflection in case study 2

This is a bit sad. I may have a naive point of view, but NASA is probably the last organization that deserves this. The young generation of Romania strongly believes that if they somehow manage to hack some remote NASA server, the second day they will be hired by NASA for a huge wage. This started by the time the first news about Romanians hacking NASA servers appeared in the media. The problem here is that all the kids dream of doing this, and there is nothing that can make them understand that this is not the way of getting hired by NASA (or anyone, really). The only thing that this can guarantee is a huge fine and/or extensive jail time.It really gives you confidence that NASA or any part of the rest of government computers and computer networks are very secure.

The damages are calculated based off of the PR work needed to be done, the actual securing of the holes exploited, and altogether soothing their own egos because their It security was shown to be incompetent, right? 



 we should be more careful and sensitive about what happen in the industry of computer.

reflection in case study 1

In my own idea
Yes, it is a little confusing about what is free or not, but the fact is companies need to make money else they can't support the software and they use all kinds of ways do to that.  Microsoft patches the culprit will download the patch and counteract it. Wrong, the whole idea of a patch is to fix the problem that allowed the hacker in. Once the PC is patched no more hole for the hacker to use, so you are wrong after a patch a hacker cannot quickly alter his worm, he would have to start searching for another vulnerability to exploit. Computer security companies find viruses and look inside them to find out what they do. Sometimes these worms are programmed to attack on a certain date. So they do announce the date that the attack will take place. 
Federal Agencies monitor general internet infrastructure to make sure it's not under attack, but I'm pretty sure it would be public knowledge not some underground hidden agency.Who ever is responsible for this so called "worm" is going to announce the date that it will take place.