Eunhan's library

Eunhan's web site

Merge Sort

Definition one of sort algorithms Technique Decrease and Conquer Algorithm steps Recusively loop Recusively loop left side and right side until the input array cannot separated every separated parts only one element is in there. This is sorted. merge arrays with sort. Java code public static void mergeSort(int[] input) { mergeSortRecurr(input, 0, input.length - 1); } public static void mergeSortRecurr(int[] input, int left, int right) { if (left < right) { int midPos = left + (right - left) / 2; mergeSortRecurr(input, left, midPos); mergeSortRecurr(input, midPos + 1, right); merge(input, left, right, midPos); } } public static void merge(int[] input, int left, int right, int midPos) { //mid pos does not check unlike the left and right int temp1 = midPos - left + 1; int temp2 = right - midPos; //temp array and copy int[] L = new int[temp1]; int[] R = new int[temp2]; for (int i = 0; i < temp1; ++i) L[i] = input[left + i]; for (int j = 0; j < temp2; ++j) R[j] = input[midPos + 1 + j]; int i = 0; int j = 0; int k = left; while (i < temp1 && j < temp2) { if (L[i] <= R[j]) { input[k] = L[i]; ++i; } else { input[k] = R[j]; ++j; } ++k; } while (i < temp1) { input[k] = L[i]; ++i; ++k; } while (j < temp2) { input[k] = R[j]; ++j; ++k; } } Avg.

import [library] to [intellij]

purpose import [library] to [intellij] What is library? pre-made code collection that you can use it right away. It help people to develop program quickly. Steps download library file (jar file) File -> Project Structure Modules -> project -> Dependencies of tabs click “+”(=JARs or directories…) to select the jar file that you want to import. left side bar underExternal Libraries, you will see imported library.

Quick Sort

Definition one of sort algorithms The most important sort algorithm Use this algorithm anywhere with any languages The best way to avoid worst time complexity is pick pivot randomly. if program most not have $O(n^2)$, need to use other sorting algorithm. Technique Decrease and Conquer Algorithm steps Recusively loop based on Lomuto. pick pivot the most right element. left side will be smaller than pivot value and right side will be bigger than pivot.

Insertion Sort

Definition one of sort algorithms Technique Brute Force Algorithm steps first loop first to the end compare looping number and left side. if left side number is bigger than right side, swap them. since number swapped, check left side numbers and make sure the left side is getting smaller step 4 means that if left side is small and does not swap, it does not need to check further. Repeat 1~5 until all of them sorted.

List of Data Structures in Python

List Definition One of the data structure in python. Almost same as array in other languages. Object. Data Structures in Python List Tuple Dictionary set declaration temp=[] temp=list() temp=[5,9,44] index structure characteristic List in List is possible. This is same as 2D array in other languages String in python is same as List slicing [starting index : ending index-1 : condition index] [0:8:3] = select index 0 to 7 by adding 3 [:8:] = select index 0 to 7 by adding 1 [7::] = select index 7 to -1 by adding 1 [::-1] = select index 0 to -1 by adding -1 a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print(a[0:8:3]) # [0, 3, 6] print(a[:8:]) # [0, 1, 2, 3, 4, 5, 6, 7] print(a[7::]) # [7, 8, 9] print(a[::-1]) # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Arithmetic Operation a=[1,2,3] b=["apple","house","computer"] print(a+b) # [1, 2, 3, 'apple', 'house', 'computer'] # print(a+3) # error # print(a-b) # error # print(a-3) # error # print(a*b) # error print(b*3) # ['apple', 'house', 'computer', 'apple', 'house', 'computer', 'apple', 'house', 'computer'] print(b*0) # [] # print(a/b) # error # print(a/3) # error add element append() = add a new element behind extend() = add new elements behind insert() = add new elements by index [] = add new elements by index condition a=[1,2,3,4,5,6,7,8,9] b=["apple","house","computer"] a.

personal blog with Hugo-3.create blog

Purpose Create personal blog with Hugo and hosting with github at Windows 10. For this purpose, you need knowledge of HTML, Markdown, and Hugo structure. If you knwo golang, css, js, that will be better. But you do not have to. used tools install date : 03-31-2021 hugo version : hugo v0.82.0 git version : git version 2.31.1.windows.1 windows : 10 windows terminal: v1.7.572.0 Chocolatey : v0.10.15 create blog create static site Go to any fodler that you want to and then run windows terminal.

Add Strings

Problem Problem_Link My Answer 1 hour limit no search on internet My code class Solution { public String addStrings(String num1, String num2) { StringBuilder sb = new StringBuilder(); int num1Leng = num1.length() - 1; int num2Leng = num2.length() - 1; int round = 0; for (int i = Math.max(num1.length(), num2.length()) - 1; i > -1; --i) { if (num1Leng < 0) { sb.append(String.valueOf(((num2.charAt(num2Leng) - 48) + round)%10)); if ((((num2.

Remove Duplicates from Sorted Array

Problem Problem_Link My Answer 1 hour limit no search on internet My code class Solution { public int removeDuplicates(int[] nums) { if(nums==null ||nums.length==0) return 0; int temp = -101; int count=0; int pos=0; for(int i=0;i<nums.length;++i){ if(temp!=nums[i]){ temp=nums[i]; nums[pos]=nums[i]; ++count; ++pos; } } return count; } } Time complexity : $O(n)$ Space complexity : $O(1)$ My result Runtime: 2 ms, faster than 22.76% of Java online submissions for Remove Duplicates from Sorted Array.

Selection Sort

Definition one of sort algorithms Technique Brute Force Algorithm steps find smallest number in the list swap the smallest number and first place the first element is sorted find smallest number in the list except the sorted element. swap the smallest number and second place Repeat 1~5 until all of them sorted. Example-Java public static int[] selectionSort(int[] input) { for (int i = 0; i < input.length - 1; ++i) { for (int j = input.

Bubble Sort

Definition one of sort algorithms Technique Brute Force Algorithm steps compare two numbers smaller number will be left and bigger number will be in right side. compare over and over again untill the end of the list Now, biggest number will stay in most right side. This number is sorted Start over from first number except sorted place. Repeat 1~5 until all of them sorted. Example-Java public static int[] bubbleSort(int[] input) { for (int i = 0; i < input.