algorithm and virtual function