This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Euclid(m, n) | |
//Euclid algoritmasını kullanarak ebob(m, n) değerini hesaplar | |
//Input: m ve n isminde negatif olmayan, ikisi beraber sıfırdan farklı tam sayılar | |
//Output: m ve n'nin ebob değeri | |
while n != 0 do | |
r ← m mod n | |
m ← n | |
n ← r | |
return m |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsecutiveIntegerChecking { | |
static int GCD(int m, int n) { | |
int t = n; | |
if (m < n) | |
t = m; | |
while (t > 1) { | |
if (m % t == 0 && n % t == 0) | |
return t; | |
t--; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t ← min{m, n} | |
while(t > 0) do | |
if(m mod t = 0 and n mod t = 0) | |
return t | |
t ← t - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*@author : tolpp | |
*/ | |
public class LCS { | |
public static void main(String[] args) { | |
String x = "ZTR123AAAAB"; | |
String y = "KLMN12BAB"; | |
int M = x.length(); | |
int N = y.length(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuickSort { | |
public int[] sort(int[] numbers){ | |
quickSort(numbers,0,numbers.length - 1); | |
return numbers; | |
} | |
private void quickSort(int numbers[], int left, int right) { | |
int index = partition(numbers, left, right); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Quicksort(A[l..r]) | |
//Alt dizilerin quicksort ile sıralanması | |
//Input: Dizinin alt dizisi A[0..n − 1]eved | |
// indices l and r | |
//Output: Alt dizi A[l..r] artan şekilde sıralı | |
if l < r | |
s ← Partition(A[l..r]) //s : bölme pozisyonu | |
Quicksort(A[l..s − 1]) | |
Quicksort(A[s + 1..r]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myList : List(1, 2, 3, 4, 5, 6, 7, 8, 9) | |
Sum : 45 | |
Odd Sum : 25 | |
Odd Sum2 : 25 | |
Even Sum : 20 | |
Even Sum2 : 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object run { | |
def main(args: Array[String]): Unit = { | |
var myList : List[Int] = List.range(1,10) // 1 to 9 liste yaratılır. | |
println("myList : " + myList) | |
println("Sum : " + sumList(myList) ) | |
println("Odd Sum : " + sumList(myList, i => if (i%2 != 0) i else 0 )) | |
println("Odd Sum2 : " + sumList(myList, oddSumBlock )) | |
println("Even Sum : " + sumList(myList, i => if (i%2 == 0) i else 0 )) | |
println("Even Sum2 : " + sumList(myList, evenSumBlock )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Eratosthenes { | |
static int[] Sieve(int n) { | |
int[] A = new int[n + 1]; | |
int[] L = new int[n + 1]; | |
for (int p = 2; p < n; p++) A[p] = p; // ilk veriler atanıyor | |
for (int p = 2; p < (int) Math.sqrt(n); p++) { | |
if (A[p] != 0) { | |
int j = p * p; | |
while (j < n) { // asal sayının katları eleniyor | |
A[j] = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sieve(n) | |
//Eratosthenes'in Eleği'nin implementasyonu | |
//Input: n > 1 olan n tamsayısı | |
//Output: n'den küçük veya n e eşit asal sayılar dizisi | |
for p←2 to n do A[p]←p | |
for p←2 to floor(sqrt(n)) do | |
if A[p] != 0 //daha önceki döngü içerisinde p elenmemişse | |
j ← p ∗ p | |
while j ≤ n do | |
A[j]←0 //j. elemanı elenmiş olarak işaretle |