Characterizations of centralizers and derivations on some algebras