How to draw this graph in tikz?

I am trying to draw the following diagram in tikz.

The code I am working on is:

\documentclass {article}

% example taken from
% http://www.guitex.org/home/images/doc/GuideGuIT/introingtikz.pdf

\usepackage {tikz}
\usetikzlibrary {positioning}
%\usepackage {xcolor}
\definecolor {processblue}{cmyk}{0.96,0,0,0}
\begin {document}
\begin {center}
\begin {tikzpicture}[-latex ,auto ,node distance =4 cm and 5cm ,on grid ,
semithick ,
state/.style ={ very thick, circle ,top color =white ,  ,
draw , text=blue , minimum width =2 cm}]
%\node[state] (C)
%{$1$};
\draw[very thick] (0,0) circle (.8cm);
\node[state] (A)  {$q_0$};
\draw[very thick] (0,0) circle (.8cm);
\node[state] (B) [ right =of A] {$q_1$};
\path (A) edge [loop above] node[above] {$b$} (A);
\path (B) edge [loop above] node[above] {$b$} (B);
%\path (C) edge [bend left =25] node[below =0.15 cm] {$1/2$} (A);
%\path (A) edge [bend right = -15] node[below =0.15 cm] {$1/2$} (C);
\path (A) edge [bend left =25] node[above] {$a$} (B);
\path (B) edge [bend left =15] node[below =0.15 cm] {$a$} (A);
%\path (C) edge [bend left =15] node[below =0.15 cm] {$1/2$} (B);
%\path (B) edge [bend right = -25] node[below =0.15 cm] {$1/2$} (C);
\end{tikzpicture}
\end{center}
\end{document}


How to make the curved arrow head on the left and draw the rightarrow to q_0?

• For future question, please pick a more suitable title. "How do I draw this?" is a poor choice. – Werner Feb 25 at 18:53

Here is my attempt:

\documentclass[border=0.2cm]{standalone}

% required packages and libraries
\usepackage{tikz}
\usetikzlibrary{automata, positioning}

\begin{document}

\begin{tikzpicture} [draw=cyan!70!black,
node distance = 3cm,
on grid,
auto,
every initial by arrow/.style = {thick}]

% State q0
\node (q0) [state,
initial,
accepting,
initial text = {}] {$q_0$};
% State q1
\node (q1) [state,
right = of q0] {$q_1$};

% Arrows
\path [-stealth, thick]
(q0) edge[bend left] node {$a$}   (q1)
(q1) edge[bend left] node {$b$}   (q0)
(q0) edge [loop above]  node {b}()
(q1) edge [loop above]  node {b}();
\end{tikzpicture}

\end{document}


which yields the following result: For more details, you can check this step by step tutorial: Automata diagrams in LaTeX

• Thanks. How to make 'initial' arrow thick? Also, how change the arrowhead from end to other for loops? – Praveen Feb 25 at 13:29
• I have modified the above code and illustration to meet your requirements. You can change initial arrow thickness by adding "every initial by arrow/.style = {thick}" to the tikzpicture environment To change arrowhead from end to the other, just remove "every loop/.style={stealth-}" or use -stealth instead of stealth- – LaTeXdraw-com Feb 25 at 13:52
• Is it possible to increase the gap between accepting circles? – Praveen Feb 25 at 14:22
• Yes, add this to the tikzpicture environment options: accepting/.style={double distance=1.5pt,outer sep=0.75pt+\pgflinewidth} Check this post: tex.stackexchange.com/questions/49544/… – LaTeXdraw-com Feb 25 at 14:31

With use of the arrows.meta, automata, positioning and quotes library:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata,
positioning,
quotes}

\begin{document}
\begin{tikzpicture}[auto,
> = Stealth,
every edge quotes/.style = {font=\footnotesize}, % if you like to have smaller edge labels
every edge/.append style = {->, draw=cyan, thick},
every loop/.append style = {<-, looseness = 12},
node distance = 22mm,
state/.style = {circle, semithick, draw=cyan, text=cyan, minimum size=1.2em},
initial text = ,
]
\node (A) [state, initial, accepting]   {$q_0$};
\node (B) [state, right=of A]           {$q_1$};
\path   (A) edge [loop above, "$b$"]   ()
(A) edge [bend left,"$a$"]     (B)
(B) edge [bend left,"$a$"]     (A)
(B) edge [loop above, "$b$"]   ();
\end{tikzpicture}
\end{document}


• Thanks. How to change the position of arrowheads in loops? – Praveen Feb 25 at 13:33
• @Praveen, you like to have inverted direction. Corrected now! – Zarko Feb 25 at 13:44