본문 바로가기

Algorithm3

더하기, 곱하기 시간복잡도 계산 더하기, 곱하기 시간복잡도 계산 더하기 더하기 시간복잡도 O(n) 2개의 이진수를 그냥 더해주면 되기에 for 문 한 번 돌리면 됨. 곱하기 시간복잡도 O(n제곱) 2개의 수를 곱한다 가정하면, 이진수로 변환하고 일렬로 나열한 후, 밑에자리에서부터 곱하기 시작. 밑에 자리에서부터 곱하게되면 n만큼의 이진수가 최대 n-1 만큼 나오게 되며, 그렇기에 시간복잡도 O(n제곱) 물론 알고리즘 마다 시간복잡도가 다름. 자바에서 곱하기 알고리즘을 어떤걸 사용하는가? Reference https://peng-hi.tistory.com/2 https://stackoverflow.com/questions/32998207/what-is-asymptotic-complexity-of-integers-multiplication.. 2020. 12. 10.
쿽소트와 머지소트의 최악의 경우 시간복잡도. 둘의 차이점. 퀵소트와 머지소트의 최악의 경우 시간복잡도 퀵소트 최악의 경우 O(n제곱) 퀵소트는 Pivot 이 비교할 때마다 끝까지 다 비교하면 n번 비교할테니 높이 n 과 비교 하는 횟수 n 으로 인해 O(n제곱). 머지 소트 O(nlogn) 머지 소트는 분할을 전부 한 후, 마지막에 비교하는 것이기에 최악의 경우라도 O(nlogn) 왜냐하면 높이 logN * 전부 비교한다고 해도 kn 이니 logN*N 이 시간 복잡도 퀵소트와 머지소트 차이점 차이점은 퀵소트는 메모리를 안쓴다는 거고. 머지 소트는 입력 배열과 동일한 배열이 필요 (메모리 사용) 2020. 8. 30.
[LeetCode] AddTwoNumbers 문제 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input:* (2 -> 4 -> 3) + (5 -> 6 -> 4) Output:* 7 -> 0 -> 8 Explanation:* 3.. 2020. 7. 11.