For any string w = w1w2…wn, the reverse of w, written wR , is the string w in reverse order,…