Cite a developed version of an algorithm (citation chain)?
Space savings aside, your choice in this must be guided by two factors: help the readers understand what your work is built upon, and acknowledge scientific contributions of your predecessors.
With those principles in mind, I would say the choice depends on the relationship between A and B, and whether either (or both) are well-known. Let's take two simple cases to illustrate:

if algorithm B is world-famous, and algorithm A is a not-so-well-known extension (e.g., because it is specially optimized for a specific type of data): you will have to cite both, as you cannot assume that all readers are familiar with algorithm A.

Herein we highlight an extension of the Abersmith algorithm,[ref A] which is itself based on the Borodin sort algorithm with specific improvements for the handling of p-adic input.


if algorithm A is very well known in your field, and algorithm B was an earlier algorithm that was almost completely superseded by A and little used nowadays (except for historical considerations): it is not useful to cite B.