index algorithm