Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is Google Calculator implemented?

When you search in Google "100F to C" how does it know to convert from Fahrenheit to Celsius? Similarly, conversion from different currencies and simple calculation.

What is the data structure used, or is it simple pattern matching the strings?

like image 973
AlgoMan Avatar asked Mar 28 '10 17:03

AlgoMan


1 Answers

It's not exactly simple pattern matching. Evaluating the mathematical expressions you can enter is not trivial. For example, here's an algorithm that evaluates a math expression. That's just the evaluation, there's probably a lot of code to detect if it's even valid.

For the currencies conversion and other units, that's simple pattern matching.

like image 147
IVlad Avatar answered Sep 28 '22 11:09

IVlad