A recovery in the shares of technology companies helped lift the Dow Jones Industrial Average and the S&P 500 to fresh records Tuesday.

The Nasdaq Composite, which had suffered its biggest two-session decline since September during the tech selloff on Friday and Monday, posted its best daily performance in more than a week.

Some investors...