Collatz[n_]:=Prepend[
Which[
n==1,{},
EvenQ[n],Collatz[n/2],
OddQ[n], Collatz[3n+1]
],
n
]

Collatz[27]

Collatz[97]

Table[n->Length@Collatz[n],{n,100}]

m[1]=4;
m[n_]/;EvenQ[n]:=m[n]=Max[n,m[n/2]];
m[n_]/;OddQ[n]:=m[n]=Max[n,m[3n+1]];
m[27]

MaximalBy[Range[1000],((m[#])/(#))&]

Collatz[703]

MaximalBy[Range[1000000],((m[#])/(#))&]

Collatz[159487]