Algorithm for populating the table with data