Vedic Math - Cube Roots

Note: Vedic Math Blog has been moved to http://vedicmath.vedantatree.com/. Please bookmark the new address for new and existing blogs.

Today, we are taking a next level of topic i.e. finding the cube root. With normal approach, finding cube root is bit complex. However, using Vedic Math techniques, it becomes interesting and fast too. This amazing technique will help you to find out the cube root of a  4 or 5 or 6 digits number quickly and all using mind power only. Technique specified in this article will work for perfect cubes only, not for other numbers (that we shall discuss in forthcoming articles). Lets start learning.

We know that, cube of a 2-digit number will have at max 6 digits (99³ = 970,299). This implies that if you are given with a 6 digit number, its cube root will have 2 digits. Further, following are the points to remember for speedy calculation of cube roots (of perfect cubes).
  1. The lowest cubes (i.e. the cubes of the fist nine natural numbers) are 1, 8, 27, 64, 125, 216, 343, 512 and 729.
  2. They all have their own distinct endings; with no possibility of over-lapping (as in the case of squares).
  3. The last digit of the cube root of an exact cube is obvious:
    • 1³ = 1    > If the last digit of the perfect cube = 1, the last digit of the cube root = 1
    • 2³ = 8    > If the last digit of the perfect cube = 8, the last digit of the cube root = 2
    • 3³ = 27  > If the last digit of the perfect cube = 7, the last digit of the cube root = 3
    • 4³ = 64  > If the last digit of the perfect cube = 4, the last digit of the cube root = 4
    • 5³ = 125 > If the last digit of the perfect cube = 5, the last digit of the cube root = 5
    • 6³ = 216 > If the last digit of the perfect cube = 6, the last digit of the cube root = 6
    • 7³ = 343 > If the last digit of the perfect cube = 3, the last digit of the cube root = 7
    • 8³ = 512 > If the last digit of the perfect cube = 2, the last digit of the cube root = 8
    • 9³ = 729 > If the last digit of the perfect cube = 9, the last digit of the cube root = 9
  4. In other words,
    • 1, 4, 5, 6, 9 and 0 repeat themselves as last digit of cube.
    • Cube of 2, 3, 7 and 8 have complements from 10 (e.g. 10's complement of 3 is 7 i.e. 3+7=10) as last digit.
  5. Also consider, that 
    • 8's cube ends with 2 and 2's cube ends with 8 
    • 7's cube ends with 3 and 3's cube ends with 7
If we observe the properties of numbers, Mathematics becomes very interesting subject and fun to learn. Following same, let’s now see how we can actually find the cube roots of perfect cubes very fast.

Example 1:  Find Cube Root of 13824

Step 1:
Identify the last three digits and make groups of three digits from right side. That is 13824 can be written as          
   13  ,   824
 
Step 2: 
Take the last group which is 824.  The last digit of 824 is 4.
Remember point 3, If the last digit of the perfect cube = 4, the last digit of the cube root = 4
Hence the right most digit of the cube root  = 4

Step 3:
Take the next group which is 13.
From point 3, we see that 13 lies between 8 and 27 which are cubes of 2 and 3 respectively. So we will take the cube root of the smaller number i.e. 8 which is 2.
So 2 is the tens digit of the answer.

We are done and the answer is '24'

Isn't that easy and fun..

Design for Server Side Pagination

In previous article, we have discussed about various type of pagination and that how these work. We have seen that in most of the scenarios, server side pagination is better than client side pagination. Client side pagination can be used only if data, i.e. the number of records, are limited. In that case, we can consider to load all data on client side and may divide the data in pages while showing on screen. However, if data is large, we would prefer the server side pagination.

In this article, we shall discuss how we can design the server side pagination component. At first, let us summarize the requirements for server side pagination.

Requirements
  • Data is large enough to support the needs of server side pagination implementation, as discussed in previous article.
  • Only current page of data (or may be 1-2 more pages) should be loaded from data repository (DB), so we want to reduce the need to load large amount of data from data repository. The same or lesser amount of data should be loaded on client side.
  • User can navigate  through the pages using next, previous, first or last page kind of actions. 
  • User can also perform 'sort' and 'search' kind of operation on the data.  
With above requirements, let us design the Pagination Component now. 

Analysis and HLD

After analysis of above requirements, following are the main design requirements:
  1. Client - Any software program which needs to retrieve the large amount of data, but want to present this to end user (or application) in pages. Client can be a UI which is showing listing of data to end user, or may be a command line tool to show the data. 
  2. We need a component which 
    1. Can maintain the state for each client. Various states needs to be maintained are: 
      1. Current Page for which data is returned last time to client
      2. Number of records to be returned for one page
      3. Various data retrieval attributes required for fetching the page data from Data Repository, using data access component. These can be 
        1. Criteria to select the desired data 
        2. Sort criteria
        3. Search criteria
        4. etc
    1. Can work as a channel to retrieve the data from repository using data access components
    2. Can provide utility methods to client for accessing the data pages based on user requests like, next | previous | first | last | specific page number
    3. Can provide methods to client using which client can change various data retrieval attributes. This is to support the scenario, when end user change the search or sort criteria at UI.
  1. We need an abstract data access layer (can call it pagination data provider), which can understand the  language of pages and can return the filtered, and sorted data for specified page. 
  2. This component can be named as 'Pagination Manager'