1

I am adding one image using \includegraphic command, but it is coming in the top of page not in the right position.

See my code give below:

\documentclass{amsart}

\usepackage{a4wide}
\newtheorem{mydef}{Definition}

\usepackage[T1]{fontenc}
\newtheorem{thm}{Theorem}
\renewcommand{\baselinestretch}{1.5} 

\usepackage{tabularx}
\usepackage{algorithm,algpseudocode}
\usepackage{tabularx}
\usepackage{amsthm}
\newtheorem{definition}{Definition}[section] 
\usepackage{graphicx}
\usepackage{tabularx,lipsum,environ,amsmath,amssymb}
\usepackage{tabularx}

\makeatletter
\newcommand{\problemtitle}[1]{\gdef\@problemtitle{#1}}% Store problem title
\newcommand{\probleminput}[1]{\gdef\@probleminput{#1}}% Store problem input
\newcommand{\problemquestion}[1]{\gdef\@problemquestion{#1}}% Store problem question
\NewEnviron{problem}{
  \problemtitle{}\probleminput{}\problemquestion{}% Default input is empty
  \BODY% Parse input
  \par\addvspace{.5\baselineskip}
  \noindent
  \begin{tabularx}{\textwidth}{@{\hspace{\parindent}} l X c}
    \multicolumn{2}{@{\hspace{\parindent}}l}{\@problemtitle} \\% Title
    \textbf{Input:} & \@probleminput \\% Input
    \textbf{Question:} & \@problemquestion% Question
  \end{tabularx}
  \par\addvspace{.5\baselineskip}
}

\newcommand{\avsum}{\mathop{\mathpalette\avsuminner\relax}\displaylimits}

\makeatletter
\newcommand\avsuminner[2]{%
  {\sbox0{$\m@th#1\sum$}%
   \vphantom{\usebox0}%
   \ooalign{%
     \hidewidth
     \smash{\vrule height\dimexpr\ht0+1pt\relax depth\dimexpr\dp0+1pt\relax}%
     \hidewidth\cr
     $\m@th#1\sum$\cr
   }%
  }%
}
\makeatother

\title{Computing Prime Set in \mathcal{O}(n) Running Time}
\author{Sh \\~\\ IIT[![enter image description here][1]][1] Ga}

\begin{document}

\section{Computing Primes beween 2 and $k-1$}

\begin{problem}
  \problemtitle{$$\textsc{Prime Set}}
  \probleminput{ An array $N$ is given such that $N[i] = i,2\le  i \le k-1$ .}
  \problemquestion{ Compute set $Q_{k-1}$ which contains primes between 2 and $k-1$} 
\end{problem}

 We want to compute the primes beween 2 and $k-1$. A simple algorithm is to start with 2 and mark the elements that are multiple of two and in the second iteration mark the multiples of 3 and so on. Let $N$ be an array containing numbers from 2 to $k-1$ such that $N[i] = i$.

\begin{itemize}
\item For $i =2$ to $k$
\begin{itemize}
\item Mark the multiples of $i$ in array $N$. 
\end{itemize}
\item End For
\end{itemize}

It is easy to see that above algorithm takes $\mathcal{O}(k \log k)$ .  

 We want to improve the running time of the above algorithm from time  $O(k \log \log k)$ to $O(k)$ time.  The problem with the above algorithm is that there will be many elements in $N$ which get marked multiple times like 6, 12 etc.  To avoid that an element get marked multiple times, we will use a doubly linked list with pointers to array $N$.  See the image below for more detail.

\begin{figure}
\includegraphics[scale=0.1]{Downloads/img.jpg} 
\end{figure}

From the above diagram it is clear that we are maintaing a one pointer from node $i$ of the list $L$ to index $i$ of array $N$ and one pointer from index $i$ of $N$ to $i$th node of list $L$. Now algorithm to compute the prime set$Q_{k-1}$ is given below:

\begin{itemize}
\item Pick the smallest unmarked element $i \ge 2$ in $N$ and add $i$ to $Q_{k-1}$.
\item Starting from the first node, walk up the list $L$ in increasing order until we find the smallest number $r$ in it such that $r.i \ge k-1$. 
\item Walk down the list $L$ ( crucially, in decreasing order ) from the node $r$, and for each $l$ in $L$, seen, mark the element $N[i.l]$ and delete the node containing $i.l$ from $L$ ( this node in $L$ is accessed through the pointer from the $(i.l)$th location in $N$ ).
\item If $N$ has any unmarked element $\ge 2$, go back to first step
\end{itemize}

In the first round all the multiple of 2 will get marked. It is easy to verify that each element in the array will get marked just once.  The overall running time of above algorithm is $O(k)$ ( verify this ). 


\end{document}

Question : How to modify so that author name and image comes in right position (where I have added image)?

See my complied pdf :

enter image description here

  • Figures float, in order to use the space in an optimal way. With floats is is always a bad idea to assume they come in a specific place (though consider using [htbp] as an option to the figure env, the h, making "here if possible" s not a part of the default value), alway have captions on them and refer to the number given by the caption. Otherwise don't use a float (here figure),, you could replace it with the center env, but if the image is large, and is close to a page break, it will be moved to the next page leaving a big hole behind. – daleif Feb 11 '18 at 14:28
  • Try using \begin{figure}[!h], or better, don't let it float: use \begin{center}\includegraphics{...}\end{center}. Unrelated: don't use a4wide anymore. You can replace it with package geometry and set \geometry{a4paper}. – Bernard Feb 11 '18 at 14:30
  • and for authorname and title – new_born Feb 11 '18 at 14:57
2

edit: from your comments follows, that you also have problems to add title and author on beginning of document. this is simple to achieve with:

...
\author{my name}
\title{Computing Prime Set in $\mathcal{O}(n)$ Running Time}% <--- added math environment

\begin{document}
\maketitle% <--- added 
...

considerin above code snippet and my answer and adding options for placement of figure float, i obtain:

enter image description here

\documentclass{amsart}
\usepackage{geometry}%

\usepackage{tikz}\usetikzlibrary{arrows.meta,
                matrix,
                positioning,
                }
\usepackage{amsmath}

\renewcommand{\baselinestretch}{1.5}
\usepackage{lipsum}


\author{my name}
\title{Computing Prime Set in $\mathcal{O}(n)$ Running Time}

\begin{document}
\maketitle % <---

\lipsum[1]
\begin{figure}[ht]% <---
    \centering
    \begin{tikzpicture}[
    node distance = 21mm and 7mm,
    box/.style = {draw, minimum size=6mm, inner sep=0pt, outer sep=0pt, anchor=center},
      pin edge = {Straight Barb-, shorten <=1mm,semithick}
                        ]
\matrix (m) [matrix of nodes,
             nodes={box},
             column sep=-\pgflinewidth,
             inner sep=0pt,
             pin=120:Array]
{
  1 & 2 & 3 &  \quad$\dotsm$\quad\vphantom{4}  & k     \\
};
\node (h2) [box,below=of m-1-2] {2};
\node (h1) [box, left=of h2,
            pin=240:head]       {1};
\node (h3) [box,right=of h2]    {3};
\node (hk) [box,below right=of m-1-5] {$k$};
%
\draw[dashed,-Straight Barb, shorten <=1mm, shorten >=1mm]
    (m-1-1.south) edge [bend right]   (h1.north)
    (h1.north)    edge [bend right]   (m-1-1.south)
    (m-1-2.south) edge [bend right]   (h2.north)
    (h2.north)    edge [bend right]   (m-1-2.south)
    (m-1-3.south) edge [bend right]   (h3.north)
    (h3.north)    edge [bend right]   (m-1-3.south)
    (m-1-5.south) edge [bend right]   (hk.north)
    (hk.north)     to  [bend right]   (m-1-5.south);
%
\draw[-Straight Barb, transform canvas={yshift= 1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
\draw[Straight Barb-, transform canvas={yshift=-1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
%
\draw[loosely dotted, ultra thick, shorten <=3mm, shorten >=3mm]
    (h3) -- (hk);
    \end{tikzpicture}
\caption{Computing primes between $2$ and $k-1$}
    \label{fig:primes}
\end{figure}
\lipsum[2]
\end{document}

is this what you looking for???

note: please review your preamble again. some packages are (unnecessary) loaded twice ...

  • and for authorname and title – new_born Feb 11 '18 at 15:29
  • hm, this i don't understand. please elaborate ... – Zarko Feb 11 '18 at 15:32
  • With the code I have given above in the question author name is comming in the compiled pdf – new_born Feb 11 '18 at 15:33
  • still not understand. you like to have image in author field? leas edit your question and add hand drawn illustration what you like to obtain. – Zarko Feb 11 '18 at 15:56
  • No I want to add my name, emailid in the title of this document. just above the title " computing the primes between 1 and k-1" – new_born Feb 11 '18 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.