algorithm f