The "Shave and a haircut — two bits" rhythm...
X: 1
T: Shave and a Haircut – Two Bits
T: Rhythm
K: clef=perc stafflines=1 middle=B
M: 4/4
L: 1/4
B B/2B/2 B B | z B B z |]
w: shave and a hair- cut, two bits!
...goes back at least to Charles Hale in 1899 according to Where does this famous rhythm pattern come from (oftenly used to knock on a door)?, which references Wikipedia: Shave and a Haircut.
The history is well described in the linked MusicFans.SE post; so, this being MusicPerformanceAndTheory.SE...
All three of the notations in the OP are correct; there is no canonical notation, just a set of rhythmic relationships, all of which are expressed. The eighth notes (or sixteenth notes: i.e., "and a") can be played straight or swung.
The traditional/characteristic "melody" is...
X: 1
T: Shave and a Haircut – Two Bits
T: Melody (standard)
K: none
M: 4/4
L: 1/4
c G/2G/2 A G | z B .c z |]
w: shave and a hair- cut, two bits!
...or sometimes...
X: 1
T: Shave and a Haircut – Two Bits
T: Melody (variant)
K: none
M: 4/4
L: 1/4
c G/2G/2 _A G | z B .c z |]
w: shave and a hair- cut, two bits!
...and also...
X: 1
T: Shave and a Haircut – Two Bits
T: Melody (variant 2)
K: none
M: 4/4
L: 1/4
c (3G/2^F/2G/2 _A G | z B .c z |]
w: shave and -a hair- cut, two bits!
The final rest is sometimes replaced with a "stinger" — an instrumental accent to end a piece.
X: 1
T: Shave and a Haircut – Two Bits
T: With "stinger"
K: none
M: 4/4
L: 1/4
c G/2G/2 A G | z B .c .!>!C |]
w: shave and a hair- cut, two bits!