자바 4

[Practice Algorithm, GeeksForGeeks] Given a sorted and rotated array, find if there is a pair with a given sum

정렬되고, 순회되어 변경된 배열에서 주어진 sum의 값에 더해지어 만족되는 value pair 쌍을 구하는 문제이다. 본래는 while문으로 O(n!)간단하게 만들어 볼 수 있으나, binary search로 max값에 해당하는 Pivot을 찾아내고, 경우에 따라 다른 시간복잡도를 보이는 알고리즘을 짜보았다.. ㅠ www.geeksforgeeks.org/given-a-sorted-and-rotated-array-find-if-there-is-a-pair-with-a-given-sum/ Given a sorted and rotated array, find if there is a pair with a given sum - GeeksforGeeks A Computer Science portal for gee..

[Practice Algorithm, GeeksForGeeks] Search pivot in an sorted and rotated array

음.. 정렬되고, 순회되어 변경된 array에서 해당 key를 찾고 index를 반환하는 알고리즘이다. 당장 생각나는 바로는 무식하게 for문으로 돌려서 O(n)으로 찾을 수 있겠지만, 문제에서 찾고자 하는 바는 O(logn)의 시간복잡도를 원한다. 음.. 이진트리를 쓰면 O(logn)으로 줄여볼 수 있을거 같은데, 이진트리를 쓰지않고서 할 수 있는 방법이 있을까? practice.geeksforgeeks.org/problems/search-in-a-rotated-array/0 Search in a Rotated Array | Practice | GeeksforGeeks practice.geeksforgeeks.org 문제 Given a sorted and rotated array A of N disti..

[Practice Algorithm, GeeksForGeeks] Rotate Array2

저번에 포스팅한 rotate Array와 비슷한 문제를 풀어보았다. practice.geeksforgeeks.org/problems/rotate-array-by-n-elements/1# Rotate Array | Practice | GeeksforGeeks practice.geeksforgeeks.org 문제 Given an array of size N. The task is to rotate array by D elements where D ≤ N. Example 1: Input: N = 7 Arr[] = {1, 2, 3, 4, 5, 6, 7} D = 2 Output: 3 4 5 6 7 1 2 Explanation: Rotate by 1: [2, 3, 4, 5, 6, 7, 1] Rotate by 2: ..

[Practice Algorithm, GeeksForGeeks] Rotate Array

오늘은 알고리즘을 기초부터 시작해보기 위해GeeksForGeeks라는 사이트에서 자료 구조 및, 정렬 알고리즘 등을 찾아보았다. 그 중, Array 관련 문제중, rotate Array를 사이트 문제에서 찾아 구현해보았다. practice.geeksforgeeks.org/problems/rotate-array-by-n-elements/0# Rotate Array | Practice | GeeksforGeeks practice.geeksforgeeks.org 문제 Given an unsorted array arr[] of size N, rotate it by D elements (clockwise). Input: T : testcase의 개수 N : array의 Size D : rotation의 Size ..