Rhythm is the temporal framework of music—the pattern of beats, accents, and durations. It can stand alone, as in drum solos, percussion ensembles, or electronic beats.
Melody is a sequence of pitched notes perceived as a coherent line. It inherently requires rhythm to organize those notes in time; without rhythmic structure, pitches become an unstructured stream, not a melody.
Thus, rhythm is the more fundamental element: music can be purely rhythmic, but melody always rides on a rhythmic foundation.