Here's what I have created, but how could I access the loop variable \n outside the foreach loop so that I could write sth like this:
\n = \n + 1 % this is definitely not right, and it seems I couldn't reference \n outside foreach loop
\node[element,fill=white,xshift=\n*1cm](l_N\n){...};
instead of hardcoding the value.
This is the complete code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[remember picture,
element/.style={rectangle,draw,fill=red!20,minimum width=1cm,minimum height=1cm},
outer/.style={circle,draw=green,fill=green!20,thick,inner sep=10pt,minimum size=7cm}
]
\node[outer,draw=green] (A) {
\begin{tikzpicture}
\foreach \i [count=\n] in {0, 1, ..., 3}
\node[element,xshift=\n*1cm](l_N\n){\i};
\node[element,fill=white,xshift=5*1cm](l_N5){...};
\node[element,xshift=6cm](l_N9){9};
\end{tikzpicture}
};
\node[outer,draw=green,right=of A] (B) {
\begin{tikzpicture}
\foreach \i [count=\n] in {0, 1, ..., 3}
\node[element,xshift=\n*1cm](r_N\n){\i};
\node[element,fill=white,xshift=5*1cm](r_N5){...};
\node[element,xshift=6cm](r_N9){9};
\end{tikzpicture}
};
\draw[thick,dashed] (l_N9) -- (r_N1);
\end{tikzpicture}
\end{document}
The result:


