I have the following MWE with \listoffigures and \listofalgorithms. In the output, the list of figures are grouped based on the chapter they are in. However, when I add list of algorithms with the algorithms numbered based on the chapters they are defined in (using \usepackage[chapter]{algorithm}), it is not grouped at all. Is there some way to display it grouped as in \listoffigures?
\documentclass{memoir}
\usepackage[chapter]{algorithm}
\begin{document}
\tableofcontents
\listoffigures
\listofalgorithms
\chapter{First chapter}
\begin{figure}[ht]
\caption{A figure}
\end{figure}
\begin{algorithm}[ht]
\caption{Another algorithm}
\end{algorithm}
\section{Next section}
\begin{figure}[ht]
\caption{Another figure}
\end{figure}
\begin{algorithm}[ht]
\caption{An algorithm}
\end{algorithm}
\chapter{Second chapter}
\begin{figure}[ht]
\caption{A figure}
\end{figure}
\begin{algorithm}[ht]
\caption{Another algorithm}
\end{algorithm}
\section{Next section}
\begin{figure}[ht]
\caption{Another figure}
\end{figure}
\begin{algorithm}[ht]
\caption{An algorithm}
\end{algorithm}
\end{document}