Sunday, September 10, 2017

Today we start reviewing U-SQL.It unifies the benefits of SQL with the expressive power of your own code. This is said to work very well with all kind of data stores – file, object and relational. U-SQL works on the Azure ecosystem which involves the Azure data lake storage as the foundation and the analytics layer over it. The Azure analytics layer consists of both HD Insight and Azure data Lake analytics (HDLA) which target data differently. The HDInsight works on managed Hadoop clusters and allows developers to write map-reduce with open source. The ADLA is native to Azure and enables C#, SQL over job services. We will also recall that Hadoop was inherently batch processing while Microsoft stack allowed streaming as well. The benefit of the Azure storage is that it spans several kinds of data formats and stores. The ADLA has several other advantages over the managed Hadoop clusters in addition to working with a store for the universe. It enables limitless scale and enterprise grade with easy data preparation. The ADLA is built on Apache yarn, scales dynamically and supports a pay by query model. It supports Azure AD for access control and the U-SQL allows programmability like C#.
U-SQL supports big data analytics which generally have the characteristics that they require processing of any kind of data, allow use of custom algorithms, and scale to any size and be efficient.
This lets queries to be written for a variety of big data analytics. In addition, it supports SQL for Big Data which allows querying over structured data Also it enables scaling and parallelization. While Hive supported HiveSQL and Microsoft Scoop connector enabled SQL over big data and Apache Calcite became a SQL Adapter, U-SQL seems to improve the query language itself. It can unify querying over structured and unstructured data. It has declarative SQL and can execute local and remote queries. It increases productivity and agility  It brings in features from T-SQL, Hive SQL, and SCOPE which has been Microsoft's internal Big Data language.U-SQL is extensible and it can be extended with C# and .Net
Courtesy : U-SQL slideshare
#codingexercise
Count binary strings with k times appearing adjacent set bits:
Given a string of bits with length n and to find the the number of times k adjacent set bits appear, we solve it recursively:
1) if n == 1 then there is no count
2) if k == 0 or k >n  return no count
3) if string ends with 0 add the recursive count for string ending at n-1 and for k adjacent bits
4) else
          if the substring upto n-1 endswith 0
             add the recursive count for string ending at n-1 and for k adjacent bits
          if the substring ends with 1
             add the recursive count for string ending at n-1 and k-1 adjacent bits plus one
5) return the count

Saturday, September 9, 2017

We were reviewing Bing Maps API.
Bing Maps helps you visualize spatial data. Users love to know where a store is or how to get there. And the data does not always need to come from Bing. It can be overlaid over the map. As long as the data has geographical coordinates, it can be used with the maps. Previously this data was sent over as xml, now there is support for more succint format as GeoJson 
Recently Bing Maps announced support for drag and drop of GeoJson format data over maps. When an application is written to use Bing Maps, it can load the maps and the geojson module. It will listen for drag and drop events. with file reader APIs, each geojson file dropped on the map is  read and overlaid.
The steps involved for the application include :
Using HTML5 to load the local files
Select the files from a form input
Each file contains a collection of features where each feature is a location.
The location list is then overlaid on the map.
Load the GeoJson module:
Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {
            //Setup the drag & drop listeners on the map.
            var dropZone = document.getElementById('myMap');
            dropZone.addEventListener('dragover', handleDragOver, false);
            dropZone.addEventListener('drop', handleFileSelect, false);

        });
var shapes = Microsoft.Maps.GeoJson.read(geoJsonText);
myMap.entities.push(shapes);
#codingexercise
Prune a binary tree with root to leaf paths whose sum is less than k
we use a recursive post order traversal and eliminate the leaves whose sum is greater than k. Nodes higher up become leaves.
Traverse the left of the root and get left
Traverse the right of the root and get right
if the root is a leaf, and the max of left and right together with the current sum is lesser than k, delete the root and return null

return root.

Friday, September 8, 2017

Today we continue reviewing Bing Maps API
These APIs include map control and services that can be used to make maps part of your application. These APIs are an authoritative source for geospatial features. They offer static and interactive maps, geocoding, route and traffic data.Any spatial data such as store locations can be queried and stored with these APIs. Typically an account and a key is needed to use the APIs. The key is used as a license to utilize their services. They are classified as used for public website, private website and enterprise assets.
The Bing Maps dev center provides account management functionality. An account is needed to cut a key and to manage data sources.
Bing Maps helps you visualize spatial data. Users love to know where a store is or how to get there. And the data does not always need to come from Bing. It can be overlaid over the map. As long as the data has geographical coordinates, it can be used with the maps. Previously this data was sent over as xml, now there is support for more succint format as GeoJson 
Recently Bing Maps announced support for drag and drop of GeoJson format data over maps.


#codingexercise
Prune a binary tree with root to leaf paths whose sum is greater than k
we use a recursive post order traversal and eliminate the leaves whose sum is greater than k. Nodes higher up become leaves.
Traverse the left of the root and get left
Traverse the right of the root and get right
if the root is a leaf, and the sum is greater than k, delete the root and return null
reduce the sum and return root.



Thursday, September 7, 2017

Today we continue reviewing Bing Maps API
These APIs include map control and services that can be used to make maps part of your application. These APIs are an authoritative source for geospatial features. They offer static and interactive maps, geocoding, route and traffic data.Any spatial data such as store locations can be queried and stored with these APIs. Typically an account and a key is needed to use the APIs. The key is used as a license to utilize their services. They are classified as used for public website, private website and enterprise assets.
The Bing Maps dev center provides account management functionality. An account is needed to cut a key and to manage data sources..
The API options from Bing Maps platform can be listed as follows: 
1) The V8 Web Control: This is one of the most universal mapping control available on Bing Maps platform with support for almost every type of browser and web application.
2) The Windows 10 universal platform that helps us build map apps for a variety of windows devices
3) The Windows Presentation Foundation that enables rich user experience on desktop applications including touch controls
4) The REST based services that facilitate tasks such as geocoding, reverse geocoding, routing and static imagery
5) The spatial data services that offer three key functionalities batch geocoding, point of interest data and the ability to store and expose spatial data. Imagine the geographical data columns added to almost all points of interest on the world map.
6) The developer resources such as documentation on APIs and SDKs.

#codingexercise
Rearrange the characters of a string such that the adjacent characters are not same.
Solution: Any data structure that can store the different alphabets and their frequencies can help here. if the alphabets could be ordered based on the decreasing order of frequencies, it will help. Consequently a priority queue or heap might help
Build a priority queue of letters and their counts
Take the most occuring letter write it down decrement its count and temporarily remove it until next iteration completes
Repeat as above and if there is no alphabet that can be written without violation, return as invalid input. If it can be written, add back the skip level alphabet and its count to the priority queue

Wednesday, September 6, 2017

Today we continue reviewing Bing Maps API
These APIs include map control and services that can be used to make maps part of your application. These APIs are an authoritative source for geospatial features. They offer static and interactive maps, geocoding, route and traffic data.Any spatial data such as store locations can be queried and stored with these APIs. Typically an account and a key is needed to use the APIs. The key is used as a license to utilize their services. They are classified as used for public website, private website and enterprise assets.
The Bing Maps dev center provides account management functionality. An account is needed to cut a key and to manage data sources.
The Bing Maps Services include REST services and spatial data services. The REST services provide geocoding, routing, elevation, imagery etc. and traffic incident information. The data services provide batch geocoding and spatial data source query and management.
The Web controls available by Bing Maps include support for both WPF and native libraries for Android and perhaps iOS. The geocoding API helps geocode a large batch of addresses. The FindBy APIs help with the querying.
The REST services automatically come  with transaction accounting that helps determine billable and non-billable transactions.
The API options from Bing Maps platform can be listed as follows: 
1) The V8 Web Control: This is one of the most universal mapping control available on Bing Maps platform with support for almost every type of browser and web application.
2) The Windows 10 universal platform that helps us build map apps for a variety of windows devices
3) The Windows Presentation Foundation that enables rich user experience on desktop applications including touch controls
4) The REST based services that facilitate tasks such as geocoding, reverse geocoding, routing and static imagery
5) The spatial data services that offer three key functionalities batch geocoding, point of interest data and the ability to store and expose spatial data. Imagine the geographical data columns added to almost all points of interest on the world map.
6) The developer resources such as documentation on APIs and SDKs.

#codingexercise
Given a range [L,R] find the count of numbers having prime number of set bits in their binary representation. 
Solution:
Initialize an array of prime numbers we can use as divisors against the count of set bits
Iterate through the elements from L to R inclusive
count the bits for others and use the divisors
Since the numbers are contiguous, we can use the previous count and positions to determine current count as the counts typically wrap around in small ranges.



Tuesday, September 5, 2017

Today we start reviewing Bing Maps API
These APIs include map control and services that can be used to make maps part of your application. These APIs are an authoritative source for geospatial features. They offer static and interactive maps, geocoding, route and traffic data.Any spatial data such as store locations can be queried and stored with these APIs. Typically an account and a key is needed to use the APIs. The key is used as a license to utilize their services. They are classified as used for public website, private website and enterprise assets.
The Bing Maps dev center provides account management functionality. An account is needed to cut a key and to manage data sources.
The Bing Maps Services include REST services and spatial data services. The REST services provide geocoding, routing, elevation, imagery etc. and traffic incident information. The data services provide batch geocoding and spatial data source query and management.
The Web controls available by Bing Maps include support for both WPF and native libraries for Android and perhaps iOS. The geocoding API helps geocode a large batch of addresses. The FindBy APIs help with the querying.
The REST services automatically come  with transaction accounting that helps determine billable and non-billable transactions.
#codingexercise
Find the next smaller element which is smaller than twice itself for all in an integer array
Int[] GetNextSmaller2XElements(List<int> A)
{
var result = new int[A.length];
for (int i =0; i < A.Length; i++)
{
int next = -1;
for (int j = i+1; j < A.Length; j++)
      if (A[j] < 2 x A[i]){
          next  = A[j];
          break;
      }
result[i] = next;
}
return result;

}
We could also  do this with the help of a stack which we keep for all the elements that do not have a next 2X smaller element.
we push the first element in the stack. we pick the next item in the array if the next is smaller than the element in the stack, we print the tuple and pop the element otherwise we push it back on to the stack for retaining the elements we have not found an answer yet. we also push the next element on to the stack so it can participate for matches going forward. This is still O(N^2) but instead of looking ahead through all the elements we are looking back at the collection of unmatched so far. In the worst case, this stack will grow to be the length of the array. The order of the stack is the reverse order of the portion of the array we have covered.

Monday, September 4, 2017

Implementing shared collaborative maps
Introduction: Maps such as Bing Maps or Google Maps helps us visualize our driving route and locations. when the same map is used to share relative locations of two or more cars plying on the road, it becomes a shared collaobartive map. This is like  a multiplayer boardgame where participants update their location against the same background in near real time while working their way to their destinations. if the destination is common to the multiple players, they can each see the distances and travel time for others.
Implementation: Such a shared collaborative map can be easily maintained with a shared database that can be updated individually by each participant. The scope and duration of the data persistence is only for the lifetime of the map. The data saved in the database only includes static information such as the origin destination tuple, the route information, the URI to query the location information for each participant based on their route map. In a sense it is nothing different from a shared collaborative online document such as Google docs or spreadsheets except that the updates happen automatically from each participant. Collaborative chat message board servers are great examples of the TCP ( though not absolutely necessary ) based implementations that show how collaboration is achieved in a multiple participant mode. The key differences are that the updates do not affect each other and are therefore already lock-free and the shared map shows arrows or pins for the locations of the cars against the same map. The dynamic location updates come from querying the location REST API from the individual participants. Layers can be drawn over the map to render one or more participants against the same backdrop just the same way as landmarks and traffic are annotated on the map.  Moreover, if an intial URI can be set up for all the shared metadata and static data for all the participants, then it becomes easy to even do away with the database and use a service only implementation.
Conclusion: Users may not always find this feature as a menu option on their maps application but the implementation is do-able with their programmatic APIs.


#codingexercise
Find the next larger element greater than twice itself for all in an integer array
Int[] GetNextLarger2XElements(List<int> A)
{
var result = new int[A.length];
for (int i =0; i < A.Length; i++)
{
int next = -1;
for (int j = i+1; j < A.Length; j++)
      if (A[j] > 2 x A[i]){
          next  = A[j];
          break;
      }
result[i] = next;
}
return result;

}
We could also  do this with the help of a stack which we keep for all the elements that do not have a next 2X larger element.
we push the first element in the stack. we pick the next item in the array if the next is smaller than the element in the stack, we print the tuple and pop the element otherwise we push it back on to the stack for retaining the elements we have not found an answer yet. we also push the next element on to the stack so it can participate for matches going forward. This is still O(N^2) but instead of looking ahead through all the elements we are looking back at the collection of unmatched so far. In the worst case, this stack will grow to be the length of the array. The order of the stack is the reverse order of the portion of the array we have covered.