> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/tr/daha-fazla-konu/02-algorithms.md).

# Algoritmalar

## Giriş

*(Program kodu listeleri yazmak için lütfen şuna bakın* [*bu yardım sayfasına*](/latex/tr/bicimlendirme/11-code-listing.md) *onun yerine.)*

LaTeX'te algoritmaları veya sözde kodu dizmek için aşağıdaki seçeneklerden birini kullanabilirsiniz:

* Aşağıdakilerden BİRİNİ seçin (`algpseudocode` VEYA `algcompatible` VEYA `algorithmic`) paketlerini algoritma gövdelerini dizmek için ve `algorithm` paketini algoritmayı başlıklandırmak için.
* Bu `algorithm2e` paketi.

**Yukarıdaki paket gruplarından yalnızca birini seçmeniz ve yalnızca seçtiğiniz paketin sağladığı komutları ve sözdizimini kullanmanız gerektiğini unutmayın.** Bu paketler aynı anda yüklenemez; aksi halde bir sürü hata alırsınız.

## algpseudocode ve algorithm paketleri

Bu `algpseudocode` paketi bir `algorithmic` ortam ve bazı kullanışlı komutlar sağlar. Şunları yapabilirsiniz [Overleaf'te tam bir örneği açın](https://www.overleaf.com/project/new/template/20763?id=71202437\&templateName=algpseudocode+%2B+algorithm+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=) , ve bu bölümde bazı ayrıntılara gireceğiz.

İşte ilk algoritmamız; şu ortamları ve komutları kullanıyor: `algpseudocode` paketi:

```latex
\documentclass{article}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithmic}
\State $i \gets 10$
\If{$i\geq 5$}
    \State $i \gets i-1$
\Else
    \If{$i\leq 3$}
        \State $i \gets i+2$
    \EndIf
\EndIf
\end{algorithmic}

\end{document}
```

[Bu kısa algpseudocode örneğini Overleaf'te açın](https://www.overleaf.com/docs?engine=\&snip_name=algpseudocode+short+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Balgpseudocode%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balgorithmic%7D%0A%5CState+%24i+%5Cgets+10%24%0A%5CIf%7B%24i%5Cgeq+5%24%7D+%0A++++%5CState+%24i+%5Cgets+i-1%24%0A%5CElse%0A++++%5CIf%7B%24i%5Cleq+3%24%7D%0A++++++++%5CState+%24i+%5Cgets+i%2B2%24%0A++++%5CEndIf%0A%5CEndIf+%0A%5Cend%7Balgorithmic%7D%0A%0A%5Cend%7Bdocument%7D)

İşte çıktı sonucu:

![Algpseudocode-0.png](/files/15da513a7b9e1d21a95b97f6aa1c7b7addeb1f86)

*Şunu yüklememelisiniz: `algorithm2e`, `algcompatible`, `algorithmic` paketlerini zaten yüklediyseniz `algpseudocode`.*

Şu tarafından sağlanan komut adlarının `algpseudocode` genellikle Başlık Biçiminde olduğunu, örn. `\State`, `\While`, `\EndWhile`.

Algoritmaya satır numaraları eklemek isterseniz, ilk satır numarasını şu ortama ekleyebilirsiniz: `algorithmic` ortamına şu şekilde: `\begin{algorithmic}[1]` ve şu çıktıyı elde edersiniz:

![Algpseudocode-00.png](/files/6c5d4335f4eaffd8a47a60e26ddf2d26c844fc3a)

Yukarıdaki algoritma örneği başlıklı da numaralı da değildir. Başlıklı bir algoritmaya ihtiyacınız varsa, ayrıca şu paketi de yüklemeniz gerekir: `algorithm` paketini ve şunu ekleyin:

```latex
\begin{algorithm}
\\caption{...}
...
\end{algorithm}
```

çevresine `algorithmic` ortamınızı. Şunu kullanabilirsiniz: `\label{...}` eklemeniz gerekebilir `\\caption{...}`, böylece algoritma numarası `\ref{...}`.

```latex
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Başlıklı bir algoritma}\label{alg:cap}
\begin{algorithmic}
\Require $n \geq 0$
\Ensure $y = x^n$
\State $y \gets 1$
\State $X \gets x$
\State $N \gets n$
\While{$N \neq 0$}
\If{$N$ çift ise}
    \State $X \gets X \times X$
    \State $N \gets \frac{N}{2}$  \Comment{Bu bir yorumdur}
\ElsIf{$N$ tek ise}
    \State $y \gets y \times X$
    \State $N \gets N - 1$
\EndIf
\EndWhile
\end{algorithmic}
\end{algorithm}

\end{document}
```

[Bu algorithm+algpseudocode kısa örneğini Overleaf'te açın](https://www.overleaf.com/docs?engine=\&snip_name=Captioned+algorithm%2Balgpseudocode+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Balgorithm%7D%0A%5Cusepackage%7Balgpseudocode%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balgorithm%7D%0A%5Ccaption%7BAn+algorithm+with+caption%7D%5Clabel%7Balg%3Acap%7D%0A%5Cbegin%7Balgorithmic%7D%0A%5CRequire+%24n+%5Cgeq+0%24%0A%5CEnsure+%24y+%3D+x%5En%24%0A%5CState+%24y+%5Cgets+1%24%0A%5CState+%24X+%5Cgets+x%24%0A%5CState+%24N+%5Cgets+n%24%0A%5CWhile%7B%24N+%5Cneq+0%24%7D%0A%5CIf%7B%24N%24+is+even%7D%0A++++%5CState+%24X+%5Cgets+X+%5Ctimes+X%24%0A++++%5CState+%24N+%5Cgets+%5Cfrac%7BN%7D%7B2%7D%24++%5CComment%7BThis+is+a+comment%7D%0A%5CElsIf%7B%24N%24+is+odd%7D%0A++++%5CState+%24y+%5Cgets+y+%5Ctimes+X%24%0A++++%5CState+%24N+%5Cgets+N+-+1%24%0A%5CEndIf%0A%5CEndWhile%0A%5Cend%7Balgorithmic%7D%0A%5Cend%7Balgorithm%7D%0A%0A%5Cend%7Bdocument%7D)

![Algpseudocode-1.png](/files/01e4ae8beb8e1880f1917063436bfc95af09504f)

Bu `algorithm` ortam bir [float](/latex/tr/sekiller-ve-tablolar/02-positioning-images-and-tables.md) gibi `table` ve `figure`, böylece gerekirse kayan nesne yerleşim değiştiricileri ekleyebilirsiniz `[hbt!]` sonrasına `\begin{algorithm}` gerekirse. Bu aynı zamanda uzun bir `algorithmic` ortam kendi başına sayfalar arasında bölünebilirken, bir `algorithm` ortam bölünemez.

Bu `algorithm` paketi ayrıca bir `\listofalgorithms` komutu sağlar; şu şekilde çalışır `\listoffigures`, ancak başlıklı algoritmalar için, bunun gibi.

![Algpseudocode-2.png](/files/840cbb2387cd3b79d84c00449db24ee4aad14aac)

[Overleaf'te tam bir örneği açın](https://www.overleaf.com/project/new/template/20763?id=71202437\&templateName=algpseudocode+%2B+algorithm+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## algcompatible/algorithmic ve algorithm paketleri

Bu `algorithmic` paketi benzer bir sözdizimi kullanır: `algpseudocode`; **ancak** komut adları büyük harfli yazılır, örn. `\STATE`, `\WHILE`, `\ENDWHILE`.

Öte yandan, `algcompatible` büyük harfli ve Başlık Biçimindeki komut adlarını tanıyacaktır, bu yüzden `\STATE`, `\WHILE`, `\ENDWHILE`, `\State`, `\While`, `\EndWhile` hepsi tanınır. Komut adları dışında, `algcompatible` ve `algorithmic` komutlar, ... ile aynı argüman sözdizimini kullanır `algpseudocode`.

```latex
\documentclass{article}
\usepackage{algcompatible}
% VEYA \usepackage{algorithmic}
\begin{document}
\begin{algorithmic}
\STATE $i\gets 10$
\IF {$i\geq 5$}
  \STATE $i\gets i-1$
\ELSE
  \IF {$i\leq 3$}
    \STATE $i\gets i+2$
  \ENDIF
\ENDIF
\end{algorithmic}

\end{document}
```

[Bu kısa algcompatible örneğini Overleaf'te açın](https://www.overleaf.com/docs?engine=\&snip_name=algcompatible\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Balgcompatible%7D%0A%25+OR+%5Cusepackage%7Balgorithmic%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balgorithmic%7D%0A%5CSTATE+%24i%5Cgets+10%24%0A%5CIF+%7B%24i%5Cgeq+5%24%7D+%0A++%5CSTATE+%24i%5Cgets+i-1%24%0A%5CELSE%0A++%5CIF+%7B%24i%5Cleq+3%24%7D%0A++++%5CSTATE+%24i%5Cgets+i%2B2%24%0A++%5CENDIF%0A%5CENDIF+%0A%5Cend%7Balgorithmic%7D%0A%0A%5Cend%7Bdocument%7D)

Bazı eski şablonlar veya belge sınıfları şunu yüklemiş olabilir: `algorithmic`, bu nedenle sağlanan sözdizimini ve komut adlarını izlemeniz gerekecek. *Şunu yüklememelisiniz: `algorithm2e`, `algpseudocode` paketleri eğer `algorithmic` ya da `algcompatible` paketi zaten yüklüyse.*

Bu `algorithm` paketi kullanılabilir `algorithmic`/`algcompatible` algoritmalara numaralı başlıklar eklemek için.

[Overleaf'te tam bir örneği açın](https://www.overleaf.com/project/new/template/20768?id=71235978\&templateName=algpseudocode+%2B+algorithm+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## algorithm2e paketi

Bu `algorithm2e` paketinin sözdizim yapısı `algpseudocode`, `algcompatible` ve `algorithmic` paketlerinden oldukça farklıdır, bu yüzden hangi paketi kullanmak istediğinize veya şablonunuzun hangi paketi yüklediğine dikkat etmeniz gerekir.

Bu `algorithm2e` paketi bir `algorithm` ortamını kullanmanız gerekir:

```latex
\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
$i\gets 10$\;
\eIf{$i\geq 5$}
{
    $i\gets i-1$\;
}{
    \If{$i\leq 3$}
    {
        $i\gets i+2$\;
    }
}
\end{algorithm}

\end{document}
```

[Bu kısa algorithm2e örneğini Overleaf'te açın](https://www.overleaf.com/docs?engine=\&snip_name=algorithm2e+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Balgorithm2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Balgorithm%7D%0A%24i%5Cgets+10%24%5C%3B%0A%5CeIf%7B%24i%5Cgeq+5%24%7D%0A%7B%0A++++%24i%5Cgets+i-1%24%5C%3B%0A%7D%7B%0A++++%5CIf%7B%24i%5Cleq+3%24%7D%0A++++%7B%0A++++++++%24i%5Cgets+i%2B2%24%5C%3B%0A++++%7D%0A%7D%0A%5Cend%7Balgorithm%7D%0A%0A%5Cend%7Bdocument%7D)

![Algorithm2e-0.png](/files/34327ca26e770fe7f8d209289a85ac702d166bc1)

Kaynak kodunuzdaki her satır *gerekir* ile bitmeli `\;` aksi halde algoritmanız çıktıda aynı metin satırında devam eder. Yalnızca bir bloğu başlatan makroyla başlayan satırlar ile bitmemelidir `\;`.

Kullanırken `algorithm2e` şunu kullanabilirsiniz `\caption{...}\ref{...}` doğrudan bu `algorithm` ortam içinde, başka herhangi bir paket yüklemeden. Ancak algoritmanıza yorumlar eklemek istiyorsanız, önce kullanılacak komut adını bildirmeniz gerekecek:

```latex
%% Bu, bir \Comment komutunu tanımlar
%% Argüman /* ... */ ile çevrelenecektir
\SetKwComment{Comment}{/* }{ */}

\begin{algorithm}
\caption{Başlıklı bir algoritma}\label{alg:two}
\KwData{$n \geq 0$}
\KwResult{$y = x^n$}
$y \gets 1$\;
$X \gets x$\;
$N \gets n$\;
\While{$N \neq 0$}{
  \eIf{$N$ çift ise}{
    $X \gets X \times X$\;
    $N \gets \frac{N}{2}$ \Comment*[r]{Bu bir yorumdur}
  }{\If{$N$ tek ise}{
      $y \gets y \times X$\;
      $N \gets N - 1$\;
    }
  }
}
\end{algorithm}
```

[Bu başlıklı algorithm2e örneğini Overleaf'te açın](https://www.overleaf.com/docs?engine=\&snip_name=Captioned+algorithm2e+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Balgorithm2e%7D%0A%5Cbegin%7Bdocument%7D%0A%25%25+This+declares+a+command+%5CComment%0A%25%25+The+argument+will+be+surrounded+by+%2F%2A+...+%2A%2F%0A%5CSetKwComment%7BComment%7D%7B%2F%2A+%7D%7B+%2A%2F%7D%0A%0A%5Cbegin%7Balgorithm%7D%0A%5Ccaption%7BAn+algorithm+with+caption%7D%5Clabel%7Balg%3Atwo%7D%0A%5CKwData%7B%24n+%5Cgeq+0%24%7D%0A%5CKwResult%7B%24y+%3D+x%5En%24%7D%0A%24y+%5Cgets+1%24%5C%3B%0A%24X+%5Cgets+x%24%5C%3B%0A%24N+%5Cgets+n%24%5C%3B%0A%5CWhile%7B%24N+%5Cneq+0%24%7D%7B%0A++%5CeIf%7B%24N%24+is+even%7D%7B%0A++++%24X+%5Cgets+X+%5Ctimes+X%24%5C%3B%0A++++%24N+%5Cgets+%5Cfrac%7BN%7D%7B2%7D%24+%5CComment%2A%5Br%5D%7BThis+is+a+comment%7D%0A++%7D%7B%5CIf%7B%24N%24+is+odd%7D%7B%0A++++++%24y+%5Cgets+y+%5Ctimes+X%24%5C%3B%0A++++++%24N+%5Cgets+N+-+1%24%5C%3B%0A++++%7D%0A++%7D%0A%7D%0A%5Cend%7Balgorithm%7D%0A%0A%5Cend%7Bdocument%7D)

![Algorithm2e-1.png](/files/d473d41bd1bc444899a92e6fcf16b95ae1e4011a)

Varsayılan olarak, `plain` algoritma stili kullanılır. Ancak algoritma ve başlığın çevresinde çizgiler tercih ediyorsanız, şu `ruled` paket seçeneğini yüklerken `algorithm2e`, ya da şunu yazın `\RestyleAlgo{ruled}` belgenizde. Başlıklı algoritmalarınız o zaman şu şekilde dizilir:

![Algorithm2e-11.png](/files/a8722e7ad0d49a0d1d1dd3636b1ab1fc16804421)

Bu `algorithm2e` paketi birçok özelleştirme seçeneği sunar. Örneğin, while—end while, if—end if bloklarını işaretleyen dikey çizgileri kaldırmak istiyorsanız, şu ekleyebilirsiniz: `noline` paket seçeneğini yüklerken `algorithm2e`, ya da şunu yazın `\SetNoline`. Bir `\listofalgorithms` komutu da `algorithm2e`.

[Overleaf'te tam bir örneği açın](https://www.overleaf.com/project/new/template/20787?id=71277562\&templateName=algpseudocode+%2B+algorithm+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Daha Fazla Okuma

* [`algpseudocode` paket dokümantasyonu](https://texdoc.org/pkg/algorithmicx) (bkz. bölüm 3.1)
* [`algorithmic` ve `algorith` paket dokümantasyonu](https://texdoc.org/pkg/algorithms)
* [`algorithm2e` paket dokümantasyonu](https://texdoc.org/pkg/algorithm2e)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/tr/daha-fazla-konu/02-algorithms.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
