This is a copy-paste-answer originating at http://www.latex-community.org/forum/viewtopic.php?f=46&t=20075:
by myself on Fri Apr 20th, 2012
The correct load order of algorithm and hyperref is:
\usepackage{float} % load float package first!
...
\usepackage{hyperref} % let hyperref patch the float package stuff
...
\usepackage{algorithm} % let algorithm use the patched version of the float package
See hyperref README for details.
by myself on Thu Apr 26th, 2012
I have examined this case a little further. Why is the (wrong) behavior with caption package different to the (wrong, too) behavior without caption package?
The answer:
If hyperref is loaded after the float package, it patches two macros offered (or patched) by the float package: \@caption and \float@makebox. If hyperref is loaded before the float package, these two patches are missing.
If the caption package is loaded additionally, the caption package patches \@caption, too. (And the code offered by the caption package is adapted to both, float and hyperref package.) So when the load order is caption-hyperref-float, only one patch is missing in this case, the one hyperref does for \float@makebox:
\documentclass[a4paper]{book}
\usepackage[centerlast,small,sc]{caption} % Loaded by Thesis.cls
\usepackage{hyperref} % Loaded by Thesis.cls
\usepackage{algpseudocode}
\usepackage{algorithm}
\makeatletter
% Patch of \float@makebox, taken from hyperref.sty [2012/02/28 v6.82p]
%% DO NOT TRY THIS AT HOME, USE CORRECT LOAD ORDER OF PACKAGES INSTEAD!
\let\HyOrg@float@makebox\float@makebox
\renewcommand{\float@makebox}[1]{%
... (Code removed)
}%
\makeatother
\begin{document}
\tableofcontents
\chapter{One}
\begin{algorithm}
\caption{Iris Detection Algorithm}\label{alg:myaaa}
...
\end{algorithm}
\chapter{Two}
See Algorithm~\ref{alg:myaaa}.
\end{document}
So without caption package we have two missing patches (usually done by the hyperref package if the package load order would be correct), with caption package we have one missing patch. This leads to the different behavior, wrong in both cases, but wrong in a different way.
by myself on Wed Jan 9th, 2013
Update:
Heiko Oberdiek (Maintainer of the hyperref package) and me decided to implement a workaround for this incorrect load order hyperref-float within our packages since this is a very common mistake.
So when using at least version 6.82q of the hyperref package and version 3.3 of the caption package the wrong load order should not make any harm anymore.
Please note that this will not correct other incorrect load orders regarding the hyperref package (see README provided by hyperref), just the only one "hyperref before float", and it will only correct it if the caption package is used additionally.
NOTE These are only excerpts of http://www.latex-community.org/forum/viewtopic.php?f=46&t=20075 and I have only copied postings of mine, not the ones from other people. So if you are interested in the whole story (and how my cat is looking), follow the link.
hyperrefafter the other packages? I'd avoidsubfigand usesubcaption– cmhughes Feb 01 '13 at 16:32algorithmshould be loaded afterhyperref. – mafp Feb 01 '13 at 16:56hyperrefafteralgorithmis still the wrong load order. However, with up-to-date TeX systems it should compile fine anyway, but only because Heiko (Oberdiek) and I have implemented extra code inhyperrefandcaptionto handle such wrong load orders. See also: http://www.latex-community.org/forum/viewtopic.php?f=46&t=20075 – Feb 02 '13 at 08:31caption3.2, andhyperref6.83. With newer versions the problem should go away. – mafp Feb 02 '13 at 17:26