The post The minimum number of letters for Anagram appeared first on Beytullah SARICA.

]]>in this post, I am going to explain how to find the minimum number of letters for anagram.

An

The original word or phrase is known as the

For example, given the words “rather” and “harder” are NOT anagram each other. Our algorithm should return 2 to make these words anagram. harder needs “t” and rather needs “d” to be anagram word.

here is Python code for the given task.

from collections import Counter def anagram(word1, word2): w1_dict = Counter(word1)# gives us frequency of letters in given word. -- Counter({'r': 2, 'a': 1, 'h': 1, 't': 1, 'e': 1}) w2_dict = Counter(word2) diff_count = 0 for k in w1_dict.keys(): if k not in w2_dict: diff_count += w1_dict[k] else: diff_count += max(0, w1_dict[k] - w2_dict[k]) for k in w2_dict.keys(): if k not in w1_dict: diff_count += w2_dict[k] else: diff_count += max(0, w2_dict[k] - w2_dict[k]) return diff_count print(anagram('rahter', 'harder'))# should return 2 print(anagram('apple', 'pear'))# should return 3 print(anagram('lemon', 'melon'))# should return 0 print(anagram('raki', 'irak'))# should return 0

The post The minimum number of letters for Anagram appeared first on Beytullah SARICA.

]]>The post Cooming Soon… appeared first on Beytullah SARICA.

]]>I will share some of Python codes on my site, as well as my GitHub repository.

stay in touch

This post will be revised soon…

The post Cooming Soon… appeared first on Beytullah SARICA.

]]>The post Canny Edge Detection appeared first on Beytullah SARICA.

]]>- Convert to Grayscale
- Smoothing: Blurring the image to remove noise.
- Finding gradients: The edges should be marked where the gradients of the image has large magnitudes.
- Non-maximum suppression: Only local maxima should be marked as edges.
- Double thresholding: Potential edges are determined by thresholding.
- Edge tracking by hysteresis: Final edges are determined by suppressing all edges that are not connected to a very strong edge.

you can see the codes in the github repository(https://github.com/beytullahsarica/ImageProcessing/tree/master/CannyEdgeDetection)

The post Canny Edge Detection appeared first on Beytullah SARICA.

]]>The post Quicksort appeared first on Beytullah SARICA.

]]>we are going to implement quick sort algorithm in Java. You can create Quicksort.java class under the src folder of your java project. As you seen in Quicksort.java, we split the input parameter which includes the Integer values in the array. First of all, we can get the pivot point of the input array then left and right part of array are used for recursive call for the sort method to find the order of numbers.

To test quick sort algorithm, create Java project and then create three classes:

- Quicksort.java
- QuicksortTest.java
- Util.java

if you wish to pull the whole project, you can visit the my git repository https://github.com/beytullahsarica/Java/tree/master/QuickSort

QuicksortTest.java

package com.sarica.quicksort; import java.util.Arrays; public class QuicksortTest { public static void main(String[] args) { Integer[] t1 = { 3, 6, 8, 10, 1, 2, 1 }; Integer[] t2 = { 3, 6, 8, 10, 1, 2, 1, 78, 343, 23, 234, 23, 6, 9 }; Integer[] t3 = { 63, 1025, 652, 10, 1, 20, 1, 1, 40, 63, 240, 78, 343, 23, 234, 23, 6, 9 }; System.out.println(Arrays.toString(Quicksort.sort(t1))); System.out.println(Arrays.toString(Quicksort.sort(t2))); System.out.println(Arrays.toString(Quicksort.sort(t3))); } }

Quicksort.java

package com.sarica.quicksort; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Quicksort { public static Integer[] sort(Integer[] arr) { int len = arr.length; List<Integer> left = new ArrayList<Integer>(); List<Integer> middle = new ArrayList<Integer>(); List<Integer> right = new ArrayList<Integer>(); int midVal = len / 2; if (len < 1) { return arr; } int pivot = arr[midVal]; for (int i = 0; i < len; i++) { if (arr[i] < pivot) {// less left.add(arr[i]); } else if (arr[i] > pivot) {// greater right.add(arr[i]); } else {// equal middle.add(arr[i]); } } Integer[] leftFinal = Util.getInstance().toArray(Integer.class, left); Integer[] rightFinal = Util.getInstance().toArray(Integer.class, right); Integer[] middleFinal = Util.getInstance().toArray(Integer.class, middle); Integer[] retVal = Util.getInstance().concatAllArrays(sort(leftFinal), middleFinal, sort(rightFinal)); return retVal; } }

Util.java

package com.sarica.quicksort; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; public class Util { private static Util instance = null; public static Util getInstance() { if (null == instance) { instance = new Util(); } return instance; } public <T> T[] concatAllArrays(T[] first, T[]... rest) { int totalLength = first.length; for (T[] array : rest) { totalLength += array.length; } T[] result = Arrays.copyOf(first, totalLength); int offset = first.length; for (T[] array : rest) { System.arraycopy(array, 0, result, offset, array.length); offset += array.length; } return result; } public <C, T extends C> C[] toArray(Class<C> componentType, List<T> list) { @SuppressWarnings("unchecked") C[] array = (C[]) Array.newInstance(componentType, list.size()); return list.toArray(array); } }

The post Quicksort appeared first on Beytullah SARICA.

]]>The post Welcome to my personal website! appeared first on Beytullah SARICA.

]]>The post Welcome to my personal website! appeared first on Beytullah SARICA.

]]>