LaTeX forum ⇒ Math & ScienceWriting Pseudo-code in Latex

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
nenu28
Posts: 28
Joined: Mon Jun 27, 2011 11:24 am

Writing Pseudo-code in Latex

Postby nenu28 » Sat Jul 16, 2011 3:27 pm

Hi there!
I am just a beginner on writing pseudo-code in latex.
I need to write a pseudo-code (probably using algorithm and/or algorithmic packages) in latex, but could not get what I want.

I hereby attached the pseudo-code that I want to write.
Would you help me do that please?


Thank you and best regards!
Attachments
pseudo code.pdf
(137.06 KiB) Downloaded 753 times

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sat Jul 16, 2011 3:46 pm

Hi,

nenu28 wrote:I am just a beginner on writing pseudo-code in latex.
I need to write a pseudo-code (probably using algorithm and/or algorithmic packages) in latex, but could not get what I want.

what's the problem? What did you get?

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

nenu28
Posts: 28
Joined: Mon Jun 27, 2011 11:24 am

Postby nenu28 » Sun Jul 17, 2011 7:30 pm

Hi Stefan_K and thanks for your message.

The problem is I want to write the pseudo-code (developed by C++ language) mentioned above.But I don't known how to type "{" or "}" on the lines 2, 8 and 10 of the algorithm.
Using algorithm and algorithmic packages, on the line 4 of the algorithm "for" is coming with "do".
So, is there a specific package to solve this problem ?

P.S: This Algorithm is developed bu C++ language /.

nenu

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jul 17, 2011 7:34 pm

It would be easier if you would show sample code besides the description. Btw. { and } need often t be written \{ and \} because { and } are special characters in LaTeX.

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

nenu28
Posts: 28
Joined: Mon Jun 27, 2011 11:24 am

Postby nenu28 » Tue Jul 19, 2011 8:30 am

Hey Stephan,

I tried to manage to make the above algorithm by using both algorithm and algorithmic packages, but i got a problem with " line numbers " (See the code tex).
  1. \listfiles
  2. \documentclass[10pt]{report}
  3. \usepackage {algorithm}
  4. \usepackage {algorithmic}
  5.  
  6. \begin{document}
  7.  
  8. \begin{algorithm}
  9. \caption{Apriori}
  10.  
  11. \vspace{2mm}
  12.  
  13. \textbf{Input:}\\
  14. D: transaction database;\\
  15. Min\_sup: the minimum support threshold\\
  16. \textbf{Output:} frequent itemsets\\
  17.  
  18. \textbf{Description:}
  19. \begin{algorithmic}[1]
  20. \STATE $L_1$= find\_frequent\_1-itemsets(DB);
  21. \STATE \textbf{for} (k=2; $L_{k-1}=\varphi; k++$) $\{$
  22. \STATE $C_{k}$= Apriori\_gen($L_{k-1}$);
  23. \STATE \textbf{for each} transaction $t\in DB$ $\{$ \quad //scan DB for
  24. counts
  25. \STATE $C_t=$ subset$(C_k,t)$;\quad //get the subsets of $t$ that
  26. are candidates
  27. \STATE \textbf{for each} candidate $c\in C_t$
  28. \STATE $c.count++$;
  29. \STATE $\}$
  30. \STATE $L_k=\{c\in C_k | c.count\geq min\_sup\}$
  31. \STATE $\}$
  32. \STATE return $L=\bigcup_kL_k$;
  33. \STATE Procedure Apriori gen($L_{k-1}$: frequent$(k-1)$-itemsets)
  34.  
  35.  
  36. \end{algorithmic}
  37. \end{algorithm}
  38. \end{document}


On the line 12, I don't want the number "12" appears. What should I do ? is there some technique to solve this ?

regards,

P.S: I just want to make this algorithm as shown the above attached pdf file

nenu

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests