├── README.md ├── apriori_algorithm ├── aprioriAlgorithm.iml ├── out │ └── production │ │ └── aprioriAlgorithm │ │ ├── AprioriFrequentItemsetGenerator$1.class │ │ ├── AprioriFrequentItemsetGenerator.class │ │ ├── FrequentItemsetData.class │ │ └── Main.class └── src │ ├── AprioriFrequentItemsetGenerator.java │ ├── FrequentItemsetData.java │ └── Main.java ├── bayes ├── bayes.iml ├── data.txt ├── out │ └── production │ │ └── bayes │ │ ├── Main.class │ │ ├── pojo │ │ └── Training.class │ │ └── utils │ │ └── FileUtil.class └── src │ ├── Main.java │ ├── pojo │ └── Training.java │ └── utils │ └── FileUtil.java ├── binary_search ├── binary_search.iml ├── out │ └── production │ │ └── binary_search │ │ └── Main.class └── src │ └── Main.java ├── daily_moving_avarage └── moving_avarage.m ├── knapsack ├── knapsack.iml ├── out │ └── production │ │ └── knapsack │ │ ├── Main.class │ │ └── pojo │ │ └── Goods.class └── src │ ├── Main.java │ └── pojo │ └── Goods.java ├── knn ├── knn.iml ├── out │ └── production │ │ └── knn │ │ ├── Main$1.class │ │ ├── Main.class │ │ └── pojo │ │ ├── Coordinate.class │ │ ├── Data.class │ │ └── Result.class └── src │ ├── Main.java │ └── pojo │ ├── Coordinate.java │ ├── Data.java │ └── Result.java ├── lcs ├── lcs.iml ├── out │ └── production │ │ └── lcs │ │ └── Main.class └── src │ └── Main.java ├── linear encryption └── linear_encryption.java └── selection_sort ├── out └── production │ └── selection │ └── Main.class ├── selection.iml └── src └── Main.java /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms and Solutions 2 | 3 | It was designed to create basic documents and problem solving approaches in a document and sample projects that I know or I am learning. 4 | 5 | ### Available Titles 6 | 7 | * Affine Cipher(Linear Encryption) Algorithm 8 | * Selection Sort 9 | * Apriori Algorithm 10 | * K-NN Algorithm 11 | * Bayes Classifier Algorithm 12 | * Knapsack Algorithm 13 | * Daily Moving Avarage 14 | * Binary Search 15 | * Longest Common Subsequence 16 | * Mark and Sweep Algorithm (Garbage Collection Approach) 17 | 18 | ### Preparing Titles 19 | 20 | * Trie Approach 21 | 22 | [Detailed Document](https://yusufcakal.gitbooks.io/algoritmalar-ve-yaklasimlar/content/) - (Turkish) 23 | -------------------------------------------------------------------------------- /apriori_algorithm/aprioriAlgorithm.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /apriori_algorithm/out/production/aprioriAlgorithm/AprioriFrequentItemsetGenerator$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/apriori_algorithm/out/production/aprioriAlgorithm/AprioriFrequentItemsetGenerator$1.class -------------------------------------------------------------------------------- /apriori_algorithm/out/production/aprioriAlgorithm/AprioriFrequentItemsetGenerator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/apriori_algorithm/out/production/aprioriAlgorithm/AprioriFrequentItemsetGenerator.class -------------------------------------------------------------------------------- /apriori_algorithm/out/production/aprioriAlgorithm/FrequentItemsetData.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/apriori_algorithm/out/production/aprioriAlgorithm/FrequentItemsetData.class -------------------------------------------------------------------------------- /apriori_algorithm/out/production/aprioriAlgorithm/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/apriori_algorithm/out/production/aprioriAlgorithm/Main.class -------------------------------------------------------------------------------- /apriori_algorithm/src/AprioriFrequentItemsetGenerator.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.Comparator; 4 | import java.util.HashMap; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | import java.util.Set; 10 | 11 | public class AprioriFrequentItemsetGenerator { 12 | 13 | public FrequentItemsetData generate(List> transactionList, 14 | double minimumSupport) { 15 | Objects.requireNonNull(transactionList, "Liste Boş"); 16 | checkSupport(minimumSupport); 17 | 18 | if (transactionList.isEmpty()) { 19 | return null; 20 | } 21 | 22 | Map, Integer> supportCountMap = new HashMap<>(); 23 | 24 | List> frequentItemList = findFrequentItems(transactionList, 25 | supportCountMap, 26 | minimumSupport); 27 | 28 | Map>> map = new HashMap<>(); 29 | map.put(1, frequentItemList); 30 | 31 | int k = 1; 32 | 33 | do { 34 | ++k; 35 | 36 | List> candidateList = 37 | generateCandidates(map.get(k - 1)); 38 | 39 | for (Set transaction : transactionList) { 40 | List> candidateList2 = subset(candidateList, 41 | transaction); 42 | 43 | for (Set itemset : candidateList2) { 44 | supportCountMap.put(itemset, 45 | supportCountMap.getOrDefault(itemset, 46 | 0) + 1); 47 | } 48 | } 49 | 50 | map.put(k, getNextItemsets(candidateList, 51 | supportCountMap, 52 | minimumSupport, 53 | transactionList.size())); 54 | 55 | } while (!map.get(k).isEmpty()); 56 | 57 | return new FrequentItemsetData<>(extractFrequentItemsets(map), 58 | supportCountMap, 59 | minimumSupport, 60 | transactionList.size()); 61 | } 62 | 63 | 64 | private List> 65 | extractFrequentItemsets(Map>> map) { 66 | List> ret = new ArrayList<>(); 67 | 68 | for (List> itemsetList : map.values()) { 69 | ret.addAll(itemsetList); 70 | } 71 | 72 | return ret; 73 | } 74 | 75 | private List> getNextItemsets(List> candidateList, 76 | Map, Integer> supportCountMap, 77 | double minimumSupport, 78 | int transactions) { 79 | List> ret = new ArrayList<>(candidateList.size()); 80 | 81 | for (Set itemset : candidateList) { 82 | if (supportCountMap.containsKey(itemset)) { 83 | int supportCount = supportCountMap.get(itemset); 84 | double support = 1.0 * supportCount / transactions; 85 | 86 | if (support >= minimumSupport) { 87 | ret.add(itemset); 88 | } 89 | } 90 | } 91 | 92 | return ret; 93 | } 94 | 95 | private List> subset(List> candidateList, 96 | Set transaction) { 97 | List> ret = new ArrayList<>(candidateList.size()); 98 | 99 | for (Set candidate : candidateList) { 100 | if (transaction.containsAll(candidate)) { 101 | ret.add(candidate); 102 | } 103 | } 104 | 105 | return ret; 106 | } 107 | 108 | private List> generateCandidates(List> itemsetList) { 109 | List> list = new ArrayList<>(itemsetList.size()); 110 | 111 | for (Set itemset : itemsetList) { 112 | List l = new ArrayList<>(itemset); 113 | Collections.sort(l, ITEM_COMPARATOR); 114 | list.add(l); 115 | } 116 | 117 | int listSize = list.size(); 118 | 119 | List> ret = new ArrayList<>(listSize); 120 | 121 | for (int i = 0; i < listSize; ++i) { 122 | for (int j = i + 1; j < listSize; ++j) { 123 | Set candidate = tryMergeItemsets(list.get(i), list.get(j)); 124 | 125 | if (candidate != null) { 126 | ret.add(candidate); 127 | } 128 | } 129 | } 130 | 131 | return ret; 132 | } 133 | 134 | private Set tryMergeItemsets(List itemset1, List itemset2) { 135 | int length = itemset1.size(); 136 | 137 | for (int i = 0; i < length - 1; ++i) { 138 | if (!itemset1.get(i).equals(itemset2.get(i))) { 139 | return null; 140 | } 141 | } 142 | 143 | if (itemset1.get(length - 1).equals(itemset2.get(length - 1))) { 144 | return null; 145 | } 146 | 147 | Set ret = new HashSet<>(length + 1); 148 | 149 | for (int i = 0; i < length - 1; ++i) { 150 | ret.add(itemset1.get(i)); 151 | } 152 | 153 | ret.add(itemset1.get(length - 1)); 154 | ret.add(itemset2.get(length - 1)); 155 | return ret; 156 | } 157 | 158 | private static final Comparator ITEM_COMPARATOR = new Comparator() { 159 | 160 | @Override 161 | public int compare(Object o1, Object o2) { 162 | return ((Comparable) o1).compareTo(o2); 163 | } 164 | 165 | }; 166 | 167 | private List> findFrequentItems(List> itemsetList, 168 | Map, Integer> supportCountMap, 169 | double minimumSupport) { 170 | Map map = new HashMap<>(); 171 | 172 | for (Set itemset : itemsetList) { 173 | for (I item : itemset) { 174 | Set tmp = new HashSet<>(1); 175 | tmp.add(item); 176 | 177 | if (supportCountMap.containsKey(tmp)) { 178 | supportCountMap.put(tmp, supportCountMap.get(tmp) + 1); 179 | } else { 180 | supportCountMap.put(tmp, 1); 181 | } 182 | 183 | map.put(item, map.getOrDefault(item, 0) + 1); 184 | } 185 | } 186 | 187 | List> frequentItemsetList = new ArrayList<>(); 188 | 189 | for (Map.Entry entry : map.entrySet()) { 190 | if (1.0 * entry.getValue() / map.size() >= minimumSupport) { 191 | Set itemset = new HashSet<>(1); 192 | itemset.add(entry.getKey()); 193 | frequentItemsetList.add(itemset); 194 | } 195 | } 196 | 197 | return frequentItemsetList; 198 | } 199 | 200 | private void checkSupport(double support) { 201 | if (Double.isNaN(support)) { 202 | throw new IllegalArgumentException("Lütfen support değerini integer giriniz."); 203 | } 204 | 205 | if (support > 1.0) { 206 | throw new IllegalArgumentException( 207 | "Support Değeriniz çok büyük: " + support + ", " + 208 | "En fazla 1.0 olmalıdır."); 209 | } 210 | 211 | if (support < 0.0) { 212 | throw new IllegalArgumentException( 213 | "Support Değeriniz çok küçük: " + support + ", " + 214 | "En az 0.0 olmalıdır."); 215 | } 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /apriori_algorithm/src/FrequentItemsetData.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.Map; 3 | import java.util.Set; 4 | 5 | 6 | public class FrequentItemsetData { 7 | 8 | private final List> frequentItemsetList; 9 | private final Map, Integer> supportCountMap; 10 | private final double minimumSupport; 11 | private final int numberOfTransactions; 12 | 13 | FrequentItemsetData(List> frequentItemsetList, 14 | Map, Integer> supportCountMap, 15 | double minimumSupport, 16 | int transactionNumber) { 17 | this.frequentItemsetList = frequentItemsetList; 18 | this.supportCountMap = supportCountMap; 19 | this.minimumSupport = minimumSupport; 20 | this.numberOfTransactions = transactionNumber; 21 | } 22 | 23 | public List> getFrequentItemsetList() { 24 | return frequentItemsetList; 25 | } 26 | 27 | public Map, Integer> getSupportCountMap() { 28 | return supportCountMap; 29 | } 30 | 31 | public double getMinimumSupport() { 32 | return minimumSupport; 33 | } 34 | 35 | public int getTransactionNumber() { 36 | return numberOfTransactions; 37 | } 38 | 39 | public double getSupport(Set itemset) { 40 | return 1.0 * supportCountMap.get(itemset) / numberOfTransactions; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /apriori_algorithm/src/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | AprioriFrequentItemsetGenerator generator = 7 | new AprioriFrequentItemsetGenerator<>(); 8 | 9 | List> itemsetList = new ArrayList<>(); 10 | 11 | itemsetList.add(new HashSet<>(Arrays.asList("a", "b"))); 12 | itemsetList.add(new HashSet<>(Arrays.asList("b", "c", "d"))); 13 | itemsetList.add(new HashSet<>(Arrays.asList("a", "c", "d", "e"))); 14 | itemsetList.add(new HashSet<>(Arrays.asList("a", "d", "e"))); 15 | itemsetList.add(new HashSet<>(Arrays.asList("a", "b", "c"))); 16 | 17 | itemsetList.add(new HashSet<>(Arrays.asList("a", "b", "c", "d"))); 18 | itemsetList.add(new HashSet<>(Arrays.asList("a"))); 19 | itemsetList.add(new HashSet<>(Arrays.asList("a", "b", "c"))); 20 | itemsetList.add(new HashSet<>(Arrays.asList("a", "b", "d"))); 21 | itemsetList.add(new HashSet<>(Arrays.asList("b", "c", "e"))); 22 | 23 | FrequentItemsetData data = generator.generate(itemsetList, 0.3); 24 | int i = 1; 25 | 26 | for (Set itemset : data.getFrequentItemsetList()) { 27 | System.out.printf("%2d: %9s, support: %1.1f\n", 28 | i++, 29 | itemset, 30 | data.getSupport(itemset)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bayes/bayes.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /bayes/data.txt: -------------------------------------------------------------------------------- 1 | true false false false man 2 | true false false true woman 3 | false false true false man 4 | true true false true man 5 | true false true false woman 6 | false false true true woman 7 | true false false true man 8 | false false false true man 9 | true false false false man 10 | true true true false woman 11 | -------------------------------------------------------------------------------- /bayes/out/production/bayes/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/bayes/out/production/bayes/Main.class -------------------------------------------------------------------------------- /bayes/out/production/bayes/pojo/Training.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/bayes/out/production/bayes/pojo/Training.class -------------------------------------------------------------------------------- /bayes/out/production/bayes/utils/FileUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/bayes/out/production/bayes/utils/FileUtil.class -------------------------------------------------------------------------------- /bayes/src/Main.java: -------------------------------------------------------------------------------- 1 | import pojo.Training; 2 | import utils.FileUtil; 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | 10 | Training sampleData = Training.getSampleData(); 11 | List trainingList = FileUtil.readFile(); 12 | 13 | List trainingListMan = new ArrayList<>(); 14 | List trainingListWoman = new ArrayList<>(); 15 | 16 | // MAN 17 | 18 | for (int i=0; i countListMan = new ArrayList<>(sampleData.getBooleanList().size()); 27 | countListMan.add(0); 28 | countListMan.add(0); 29 | countListMan.add(0); 30 | countListMan.add(0); 31 | 32 | for (int j=0; j countListWoman = new ArrayList<>(4); 51 | countListWoman.add(0); 52 | countListWoman.add(0); 53 | countListWoman.add(0); 54 | countListWoman.add(0); 55 | 56 | for (int j=0; j womanResult){ 73 | sampleData.setType("man"); 74 | }else{ 75 | sampleData.setType("woman"); 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /bayes/src/pojo/Training.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Training { 7 | 8 | private List booleanList = new ArrayList<>(); 9 | private String type; 10 | 11 | public Training() {} 12 | 13 | public List getBooleanList() { 14 | return booleanList; 15 | } 16 | 17 | public void setBooleanList(List booleanList) { 18 | this.booleanList = booleanList; 19 | } 20 | 21 | public String getType() { 22 | return type; 23 | } 24 | 25 | public void setType(String type) { 26 | this.type = type; 27 | } 28 | 29 | public static Training getSampleData(){ 30 | Training training = new Training(); 31 | List booleanList = new ArrayList<>(); 32 | booleanList.add(true); 33 | booleanList.add(true); 34 | booleanList.add(false); 35 | booleanList.add(false); 36 | training.setBooleanList(booleanList); 37 | return training; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bayes/src/utils/FileUtil.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import pojo.Training; 4 | import java.io.BufferedReader; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class FileUtil { 11 | 12 | public static List readFile(){ 13 | 14 | List booleanList = null; 15 | Training training = null; 16 | List trainingList = new ArrayList<>(); 17 | 18 | try(BufferedReader br = new BufferedReader(new FileReader("data.txt"))) { 19 | while (br.ready()){ 20 | String[] strings = br.readLine().split(" "); 21 | int size = strings.length; 22 | booleanList = new ArrayList<>(); 23 | training = new Training(); 24 | for (int i=0; i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /binary_search/out/production/binary_search/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/binary_search/out/production/binary_search/Main.class -------------------------------------------------------------------------------- /binary_search/src/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collections; 3 | import java.util.List; 4 | 5 | public class Main { 6 | 7 | private static String result = ""; 8 | 9 | public static void main(String[] args) { 10 | 11 | List integerList = new ArrayList<>(); 12 | integerList.add(11); 13 | integerList.add(8); 14 | integerList.add(1); 15 | integerList.add(4); 16 | integerList.add(17); 17 | integerList.add(21); 18 | integerList.add(14); 19 | integerList.add(30); 20 | integerList.add(22); 21 | 22 | List integerListTest = new ArrayList<>(); 23 | integerListTest.add(15); 24 | integerListTest.add(4); 25 | integerListTest.add(8); 26 | integerListTest.add(21); 27 | integerListTest.add(10); 28 | integerListTest.add(7); 29 | 30 | for (int i=0; i list, int value){ 48 | boolean flag = false; 49 | for (int i=0; i list, int value){ 67 | int middleIndex = ((list.size()+1) / 2) - 1; 68 | if (list.size() == 0){ 69 | result = "YOK"; 70 | }else{ 71 | if (value == list.get(middleIndex)){ 72 | result = "VAR"; 73 | }else if (value > list.get(middleIndex)){ 74 | list = list.subList(middleIndex+1, list.size()); 75 | binarySearch(list, value); 76 | }else{ 77 | list = list.subList(0, middleIndex); 78 | binarySearch(list, value); 79 | } 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /daily_moving_avarage/moving_avarage.m: -------------------------------------------------------------------------------- 1 | t = [-1*pi:0.1:1*pi] 2 | v = sin(4*t); 3 | figure; plot(t,v); hold on; 4 | daily = 25; 5 | h = dailyMovingAvarage(daily, v); 6 | plot(t,h); 7 | hold off; 8 | 9 | function h = dailyMovingAvarage(daily, v) 10 | size = length(v); 11 | h = zeros(1, size); 12 | for i=1:size-daily+1 13 | sum = 0; 14 | for j=i:i+daily-1 15 | sum = sum + v(j); 16 | end 17 | h(i + (daily-1)) = sum / daily; 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /knapsack/knapsack.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /knapsack/out/production/knapsack/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knapsack/out/production/knapsack/Main.class -------------------------------------------------------------------------------- /knapsack/out/production/knapsack/pojo/Goods.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knapsack/out/production/knapsack/pojo/Goods.class -------------------------------------------------------------------------------- /knapsack/src/Main.java: -------------------------------------------------------------------------------- 1 | import pojo.Goods; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | 11 | double weight = 6.0; 12 | List goodsList = Goods.getDatas(); 13 | System.out.println(knapsack(goodsList, weight)); 14 | 15 | } 16 | 17 | private static double knapsack(List goodsList, double weight){ 18 | 19 | double value = 0.0; 20 | List list = new ArrayList<>(); 21 | 22 | for (Goods goods : goodsList) { 23 | list.add(goods.getValue() / goods.getWeight()); 24 | } 25 | 26 | double tempWeight = 0.0; 27 | while (tempWeight < weight){ 28 | 29 | double subWeight = weight - tempWeight; 30 | 31 | double maxValue = Collections.max(list); 32 | int maxIndex = list.indexOf(maxValue); 33 | 34 | if (goodsList.get(maxIndex).getWeight() <= subWeight){ 35 | tempWeight += goodsList.get(maxIndex).getWeight(); 36 | value += goodsList.get(maxIndex).getValue(); 37 | }else{ 38 | double WEIGHT = goodsList.get(maxIndex).getWeight(); // 2 39 | if (WEIGHT % subWeight == 0){ 40 | double div = WEIGHT / subWeight; 41 | value += goodsList.get(maxIndex).getWeight() / div; 42 | tempWeight += subWeight; 43 | } 44 | } 45 | 46 | goodsList.remove(maxIndex); 47 | list.remove(maxIndex); 48 | 49 | if (tempWeight == weight){ 50 | break; 51 | } 52 | } 53 | return value; 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /knapsack/src/pojo/Goods.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Goods { 7 | 8 | private double value, weight; 9 | 10 | public Goods() {} 11 | 12 | public Goods(double weight, double value) { 13 | this.value = value; 14 | this.weight = weight; 15 | } 16 | 17 | public double getValue() { 18 | return value; 19 | } 20 | 21 | public void setValue(double value) { 22 | this.value = value; 23 | } 24 | 25 | public double getWeight() { 26 | return weight; 27 | } 28 | 29 | public void setWeight(double weight) { 30 | this.weight = weight; 31 | } 32 | 33 | public static List getDatas(){ 34 | Goods goods1 = new Goods(4.0, 2.0); 35 | Goods goods2 = new Goods(2.0, 3.0); 36 | Goods goods3 = new Goods(3.0, 6.0); 37 | Goods goods4 = new Goods(2.0, 2.0); 38 | 39 | List goodsList = new ArrayList<>(); 40 | goodsList.add(goods1); 41 | goodsList.add(goods2); 42 | goodsList.add(goods3); 43 | goodsList.add(goods4); 44 | return goodsList; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /knn/knn.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /knn/out/production/knn/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knn/out/production/knn/Main$1.class -------------------------------------------------------------------------------- /knn/out/production/knn/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knn/out/production/knn/Main.class -------------------------------------------------------------------------------- /knn/out/production/knn/pojo/Coordinate.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knn/out/production/knn/pojo/Coordinate.class -------------------------------------------------------------------------------- /knn/out/production/knn/pojo/Data.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knn/out/production/knn/pojo/Data.class -------------------------------------------------------------------------------- /knn/out/production/knn/pojo/Result.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/knn/out/production/knn/pojo/Result.class -------------------------------------------------------------------------------- /knn/src/Main.java: -------------------------------------------------------------------------------- 1 | import pojo.Coordinate; 2 | import pojo.Data; 3 | import pojo.Result; 4 | 5 | import java.util.*; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | 11 | int k = 2; 12 | 13 | List coordinateList = Data.getData(); 14 | List distanceList = new ArrayList<>(); 15 | 16 | Coordinate coordinate5 = new Coordinate(3,7); 17 | 18 | 19 | for (Coordinate coordinate : coordinateList) { 20 | double x = coordinate.getX() - coordinate5.getX(); 21 | x = Math.pow(x, 2); 22 | double y = coordinate.getY() - coordinate5.getY(); 23 | y = Math.pow(y, 2); 24 | 25 | Result result = new Result(Math.sqrt(x+y), coordinate.isCircle()); 26 | distanceList.add(result); 27 | 28 | } 29 | 30 | /** 31 | * Listeyi distance değişkene göre sıralar ve buna göre en yakın değerlerin hangi tip olduğu belli olur. 32 | */ 33 | Collections.sort(distanceList, new Comparator() { 34 | @Override 35 | public int compare(Result o1, Result o2) { 36 | return Double.compare(o1.getDistance(), o2.getDistance()); 37 | } 38 | }); 39 | 40 | int circleSum = 0, notCircleSum = 0; 41 | for (int i=0; i notCircleSum){ 53 | coordinate5.setCircle(true); 54 | }else{ 55 | coordinate5.setCircle(false); 56 | } 57 | 58 | coordinateList.add(coordinate5); 59 | 60 | System.out.println(coordinateList); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /knn/src/pojo/Coordinate.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | public class Coordinate { 4 | 5 | /** 6 | * Two dimens coordinate points 7 | */ 8 | private double x, y; 9 | 10 | /** 11 | * Class flag value 12 | */ 13 | private boolean circle; 14 | 15 | public Coordinate(double x, double y, boolean circle) { 16 | this.x = x; 17 | this.y = y; 18 | this.circle = circle; 19 | } 20 | 21 | public Coordinate(double x, double y) { 22 | this.x = x; 23 | this.y = y; 24 | } 25 | 26 | public Coordinate() { 27 | 28 | } 29 | 30 | public double getX() { 31 | return x; 32 | } 33 | 34 | public void setX(double x) { 35 | this.x = x; 36 | } 37 | 38 | public double getY() { 39 | return y; 40 | } 41 | 42 | public void setY(int y) { 43 | this.y = y; 44 | } 45 | 46 | public boolean isCircle() { 47 | return circle; 48 | } 49 | 50 | public void setCircle(boolean circle) { 51 | this.circle = circle; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Coordinate{" + 57 | "x=" + x + 58 | ", y=" + y + 59 | ", circle=" + circle + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /knn/src/pojo/Data.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Data { 7 | 8 | public static List getData(){ 9 | 10 | List coordinateList = new ArrayList<>(); 11 | 12 | Coordinate coordinate1 = new Coordinate(1,4, true); 13 | Coordinate coordinate2 = new Coordinate(3,4, true); 14 | 15 | Coordinate coordinate3 = new Coordinate(7,4, false); 16 | Coordinate coordinate4 = new Coordinate(7,7, false); 17 | 18 | 19 | coordinateList.add(coordinate1); 20 | coordinateList.add(coordinate2); 21 | coordinateList.add(coordinate3); 22 | coordinateList.add(coordinate4); 23 | 24 | return coordinateList; 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /knn/src/pojo/Result.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | public class Result { 4 | 5 | private double distance; 6 | private boolean flag; 7 | 8 | public Result(double distance, boolean flag) { 9 | this.distance = distance; 10 | this.flag = flag; 11 | } 12 | 13 | public Result() { 14 | 15 | } 16 | 17 | public double getDistance() { 18 | return distance; 19 | } 20 | 21 | public void setDistance(double distance) { 22 | this.distance = distance; 23 | } 24 | 25 | public boolean isFlag() { 26 | return flag; 27 | } 28 | 29 | public void setFlag(boolean flag) { 30 | this.flag = flag; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Result{" + 36 | "distance=" + distance + 37 | ", flag=" + flag + 38 | '}'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lcs/lcs.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /lcs/out/production/lcs/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yusufcakal/algorithms/6b5c34db60f8397c22dacd8152cf5bd3acecf39c/lcs/out/production/lcs/Main.class -------------------------------------------------------------------------------- /lcs/src/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | 8 | List stringList = new ArrayList<>(); 9 | List stringList2 = new ArrayList<>(); 10 | List stringCommons = new ArrayList<>(); 11 | 12 | stringList.add("A"); 13 | stringList.add("B"); 14 | stringList.add("T"); 15 | stringList.add("C"); 16 | stringList.add("D"); 17 | stringList.add("E"); 18 | stringList.add("F"); 19 | stringList.add("G"); 20 | stringList.add("Z"); 21 | 22 | stringList2.add("A"); 23 | stringList2.add("B"); 24 | stringList2.add("X"); 25 | stringList2.add("D"); 26 | stringList2.add("F"); 27 | stringList2.add("G"); 28 | stringList2.add("T"); 29 | 30 | for (int i=0; i=alfabe.length){ 26 | dogrusal = dogrusal % alfabe.length; 27 | } 28 | yeni_metin[k] = alfabe[dogrusal]; 29 | } 30 | System.out.println("Sifrelenmis Metin : " + String.valueOf(yeni_metin)); 31 | } 32 | } 33 | 34 | public class Dogrusal { 35 | 36 | public static void main(String[] args) { 37 | Scanner scan = new Scanner(System.in); 38 | cevir c = new cevir(); 39 | System.out.println("Sifreleme Kucuk Harfler Uzerine Yazilmistir " + "F(x) = AX + B"); 40 | System.out.println("\n"); 41 | System.out.println("Sifrelenecek Metni Giriniz : " + "(Bosluk Kabul Edilemez)"); 42 | String metin = scan.nextLine(); 43 | System.out.println("A degerini giriniz : "); 44 | int a = scan.nextInt(); 45 | System.out.println("B degerini giriniz : "); 46 | int b = scan.nextInt(); 47 | c.metincevir(metin, a, b); 48 | } 49 | } 50 | 51 | public class siralama { 52 | int indis; 53 | public void sirala(char k , int a , int b){ 54 | char [] alfabe = new char [26]; 55 | char harf = 97; 56 | for(int i=0; i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /selection_sort/src/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | 8 | List list = new ArrayList<>(); 9 | list.add(8); 10 | list.add(5); 11 | list.add(2); 12 | list.add(6); 13 | list.add(9); 14 | list.add(3); 15 | list.add(1); 16 | list.add(4); 17 | list.add(0); 18 | list.add(7); 19 | 20 | int temp; 21 | 22 | for (int i=0; i