An algorithm for a reliable search of switching times