I found the approach outlined here to be an interesting approach to reducing the cost of hash table resizing: Hash_table#Monotonic_keys:
"If it is known that key values will always increase (or decrease) monotonically, then a variation of consistent hashing can be achieved by keeping a list of the single most recent key value at each hash table resize operation. Upon lookup, keys that fall in the ranges defined by these list entries are directed to the appropriate hash function—and indeed hash table—both of which can be different for each range. Since it is common to grow the overall number of entries by doubling, there will only be O(lg(N)) ranges to check, and binary search time for the redirection would be O(lg(lg(N))). As with consistent hashing, this approach guarantees that any key's hash, once issued, will never change, even when the hash table is later grown."
Consistent hashing appears to be used widely in dealing with this cost. I can imagine something similar of the sorts must be used to keep consistent large sets of data by search engines.
Saturday, September 29, 2012
Wednesday, September 26, 2012
Notable comment on article documenting progress of GrassHopper VTVL
I found this comment to be worth saving and sharing. I don't know the author. It touches on the development of flight, its impact, and the future of space flight and the potential it holds for the human species.
Source link: http://www.engadget.com/2012/09/22/spacexs-grasshopper-vertical-takeoff-vertical-landing-rocke/
Author: "lagrangia"
"It is true that others- notably Delta Clipper - have preceded GrassHopper. The point however is that these precursors were and were intended to be research vehicles. Grasshopper is intended from the start to convert an already active commerical space programme into a mass market operation, driven by rising order books. Also, the task of retrofitting already proven hardware to VTVL multiple usage is revolutionary. If the eventual performance is as Musk projects we are looking at a 10-100 fold reduction in costs of space missions. Maybe today's short hop was a "small fart" , but the Wright Borthers' Flyer in 1903 was no big deal in commercial aviation. In a decade, this could be seen as a game changing step in the aspirations of thousands of Space advocates over many generations- the birth of a true cosmic Diaspora.As Musk, Professor Stephen Hawking and many others have realised, our civilisation requires an expansion beyond our womb planet for its survival and further evolution.The alternatives on offer by opponents of space expansion - namely De Growth and De-Peopling of our civilisation to "Save the Planet" are only worth consideration by committed misanthropes who wish to diffuse hopelessness and acceptance of authoritarian regimes, which are widely expected to grow on a planet with diminishing food, resources and energy .
History shows us that ALL Authoritrian regimes are lethal, unscrupulous, careless of all except their own lust for power and domination, fail, and alwasys cause more suffering than the dangers they claim to be trying to solve In recent years, the calls for suppression of hardwon liberties, righs and living standards to "Save the Planet" are becoming more open, and smell of a modern form of Aztec human sacrifice, which was justly rewarded by the arrival of Hernan Cortez.
One of the few certainties is that, however plausible, antihuman "Green" dictatorships will do no good, and will be worse than any conceivable alternative. Access to vast resources of solar energy raw materials, and opportunity beyond Earth can cut off future ideological aspiring despotisms at the knees. For our descendants this is essential, and we would never be forgiven if we fail to take full advantage of the future the New Space pioneers are pointing to.For the sake of unborn billions, we must wish Elon Musk, Robert Bigelow, and Alan Bond et al God speed. They, not the fatuous celebrities of popular media, are the true heroes of our time."
Friday, September 21, 2012
Optimized Trial Division Prime Number Checking
Wikipedia definition of a prime number: "A prime number (or a prime) is a natural number greater than 1 that has no positive divisorsother than 1 and itself." On that page, if you scroll down a bit, you'll see "Testing Primality...". The following is a little 'Trial Division' method of determining if an entered int is a prime. It is obviously limited to small numbers (java int), and it is not as efficient as the 'deterministic' algorithms mentioned on that page (which are O(logi(n) [iterative logarithmic], better than the presented code's ~ O(n1/2)). It does, however, skip over all even and numbers divisible by 3 (other than 2 and 3, which are valid input).
import java.util.Scanner; |
Wednesday, September 19, 2012
Yet another bubble sort comparison
Bubble sort isn't a very efficient algorithm, with O(n2) average and worse-case performance. Anyway, here are some of the algorithm's original and optimized implementations in Java that I've googled up. This computer club blog has a nice impl in java, python, and c++. The Algorithmist wiki, which appears to be a nice and concise resource for prep work, also has a couple of optimizations.
/** |
Tuesday, September 18, 2012
Final != Immutable
Just learned that in Java 1.6 (or anything after 1.3, from what I recall from the blog that I read), the final modifier on a primitive int array does not imply immutability (non-modifiable); found this when playing with a couple of sorting algorithms. In the code below, if we want to use the same static array 'array' to be printed before sending it to various successive sorting methods, then we should send clones of it:
-->
public class InsertionSort {
|
Labels:
bubble sort,
final modifier,
immutable,
insertion sort,
java
Friday, September 7, 2012
Prep
The company I previously worked for downsized significantly recently, and I've found myself preparing for interviews as I did when I was looking for an internship back in early 2008. To track this little journey publicly, I'll post what I find to be interesting and useful articles and books.
I have professional experience with Java. So, other than just brushing up on its syntax, I've decided to learn more about other programming paradigms and languages to see where I could steer my career. Here is what I've discovered so far (it may not be much or cutting edge, but I've got to start somewhere, so don't flame me)...
Functional programming appears to be taking off. The dominant functional languages seem to be Haskell, Scala, and F#. For Java, C#, and other OOP folks, Scala would be more familiar as it is also Object Oriented.
The C# language seems to be ahead of the current Java language (7) in many aspects, with concepts such as Delegates and Lambda Expressions. I'm not mentioning LINQ there because there are many great JPA providers out there. If these concepts provide an edge to developers and business priorities alike, then perhaps C# is worth pursuing. I've had exposure to Java EE and Web Services in Java (with Jersey, Ext JS, and Spring), so the .NET equivalent offering Windows Communication Framework (WCF) would be something worth picking up.
I don't think Java is going away anytime soon - OpenJDK is gaining lots of support. Java 8 will be adding Lambda Expressions. Also, trends seem to show that Java is still the most dominant language (1, 2). In the second link, it's interesting to note the fall of book sales for many languages, and a steep increase for Objective C, JavaScript, and Java from 2009 onward, likely due to iOS development, and perhaps even a decline in demand from finance houses.
Subscribe to:
Posts (Atom)