Second Pass : ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) ( 1 2 4 5 8 ) , Swap since 4 ) 2 ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) Now , the array is already sorted , but our algorithm does not know if it is completed .
For example : First pass : ( 4 , 3 , 1 , 2 ) → ( 3 , 4 , 1 , 2 ) ( 3 , 4 , 1 , 2 ) → ( 3 , 1 , 4 , 2 ) ( 3 , 1 , 4 , 2 ) → ( 3 , 1 , 2 , 4 ) Second pass : ( 3 , 1 , 2 , 4 ) → ( 1 , 3 , 2 , 4 ) ( 1 , 3 , 2 , 4 ) → ( 1 , 2 , 3 , 4 ) ( 1 , 2 , 3 , 4 ) → ( 1 , 2 , 3 , 4 ) Third pass : ( 1 , 2 , 3 , 4 ) → ( 1 , 2 , 3 , 4 ) ( 1 , 2 , 3 , 4 ) → ( 1 , 2 , 3 , 4 ) ( 1 , 2 , 3 , 4 ) → ( 1 , 2 , 3 , 4 ) This is not an optimized implementation of the algorithm .