24/03/2016

Differences between data structures and algorithms?

Algorithms are like verbs and data structures are like nouns. An algorithm is just a method for doing something on a computer; a data structure is a layout for memory that represents some sort of data.

If you wanted to store thousands of English words along with their meanings in a way that you could later look them up whenever you needed, you could do that in multiple ways. Consider two:

  1. Write them down in any order.
  2. Write them down alphabetically.

You can see  how it is advantageous to do it as 2. Not surprisingly, that's how dictionaries are arranged. So a dictionary is a data structure: it has both data AND a structure especially suitable for performing some action on that data (in this case, looking up words).

Now once you have the dictionary, how do you look a word up? Possibly like this:

  1. Open the dictionary roughly at the page where you think your word would be.
  2. Flip a few(or maybe many) pages back or forth depending on where you've landed in step 1.
  3. Scan page to find your word.
  4. Read the entry next to the word.

This sequence of actions you take to look up a word is an algorithm: a general description of how to do something (in this case, looking up words), usually with the data from your data structure. This algorithm (let's call it LOOKUP) does not need to have the exact 4 steps I listed above. It could be anything as long as there is a sequence of steps that lead you unambiguously to the desired result. Because that is the primary purpose of algorithms: to make actionable knowledge portable. You are now free to compile your own dictionary of words from any language and send it over to me. If you've compiled it alphabetically and I know the alphabet order for that language (necessary for step 1 of algorithm), I can use your dictionary to look up words all day long without your help. 

So data structures and algorithms work together to let you do stuff with your data. Data structure is where the structured data is, algorithm is how you do with it whatever it is you want to do. Notice that the design of the algorithm is guided by the data structure it will work on. The algorithm can only have actions licensed by the data structure it operates upon. Step 1 from our algorithm LOOKUP works only because the dictionary is arranged alphabetically - were it not, you wouldn't know where to open it. You would have to go through it page by page to look a word up. In fact, this is also an algorithm (Brute-force search) but it is not a very good one, is it? The fact that our data structure has a, well, structure helps us use a much faster algorithm (LOOKUP) to look for a word.

Now that I've mentioned speed, it might be interesting to think of how we can make our algorithm LOOKUP work faster (since that's what you almost always want). I believe by now you can see there are two things we could tweak to gain speed - the algorithm itself, as well as the data structure. Look at step 1 again. Can this be done faster? Yes. The letter S has the most words, followed by P, C, D, M etc. If you have some idea of the relative number of words per alphabet you can make a better guess about where to open a dictionary. This in turn will make step 2 faster (on average) because if you land in the vicinity of a target word more accurately, you need to flip fewer pages correcting for it later. Similarly, step 3 can become faster if you use the guide words at the top margin of every page. 

The other way is to modify the data structure itself. You've probably seen dictionaries like this:

   
The notches, or tabs, let you immediately open the dictionary in the general area of a letter. This makes step 1 of our algorithm faster without us having to explicitly modify the algorithm. In essence, the basic idea is to inform either the algorithm or the data structure better to make the entire operation faster.

12/03/2016

Amazon Prime Air - drone delivery


Amazon already offers delivery in some markets in as little as one hour with Amazon Prime Now, but that still relies upon humans driving cars. How quaint. Amazon’s next big idea is the deploy an army of drones to deliver packages over a wide area in as little as 30 minutes. Prime Air was unveiled as a concept several years ago, but Amazon is still developing it. Amazon exec Paul Misener has revealed more details about how Prime Air will work in an interview with Yahoo Tech.

Amazon thinks that in order to get delivery times to half an hour, the drones will need to have a range of about 10 miles. That probably means areas with Prime Now warehouses will serve as hubs for the drones. The drones themselves will weight about 55 pounds and have a maximum payload of five pounds. So, that giant TV you ordered will probably still make its way to you on a truck. Still, most things Amazon sells weight less than five pounds. Misener doesn’t know if it’s going to cost anything extra, though.

Amazon has yet to come up with a good way to deliver to those in apartments, but if you live in a house, the drone will just drop the package on your doorstep. If your yard has lots of obstacles, that’s no problem, according to Misener. He compares Amazon’s drones to horses as opposed to cars, which makes more sense than you’d expect. A car will go wherever you steer it, even if you steer it into the tree in your front yard. A horse, on the other hand, will go around the tree because it prefers not to run into things. The drones will be the same — they can avoid obstacles even if an operator steers it into one.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Host