print algorithm