본문 바로가기

반응형

분류 전체보기

(347)
Linked List linked list는 자료구조 중 하나인데, 저장할 수 있는 공간이 있으면, 다음 데이터 공간 주소를 함께 가지고 있는 구조이다. 배열과의 차이 배열은 정해진 공간이 있어서, 작업 중에 공간을 늘리거나 줄일 수가 없다. 그에 반해 linked list는 더하거나 빼는 것이 가능한데, 데이터 안에 그 위치 정보를 주는 것이다. 그런데 여기에서 새롭게 추가가 되었던 노드 정보를 끊고 다음 데이터로 연결을 시키게 되면, 아까 추가되었던 데이터를 부를 수 있는 방법이 사라졌기 때문에 사라진 것처럼 보이지만, 실제로는 메모리를 잡아먹고 있는 상태이다. C++과 같은 언어에서는 저 메모리를 삭제하겠다고 실제로 선언을 해줘야만 데이터가 사라지지만, 자바에서는 이러한 경우 자동적으로 삭제가 된다. 속도적으로는 데이터..
퀵 정렬 자바 퀵 정렬이라는 것은 작은 것은 왼쪽으로 큰 것은 오른쪽으로 분류를 하는 기법이다. 이렇게 두 개로 나눈 것을 파티션이라고 하는데, 파티션 안에서 또 파티션으로 쪼개면서 같은 기능을 반복하므로써 최종적으로 가장 작은 것부터 큰 것까지 정렬을 하게 된다. 퀵 정렬의 시간 복잡도는 O(n log n)으로 평균적으로 시간이 이 정도가 나온다는 뜻이다. 보통은 이것보다 빠르지만, 최악의 경우는 n2까지 나오기도 한다.
HashTable in java HashTable Hash Table is the most useful data structure for interview questions. for any problem, have hashtables at the top of your mind as a possible technique to solve problems. Key value lookup So this gives you a way of given a key, asscociating a value with it for quick lookups. String -> hashCode -> index - Array is often much smaller than the number of hashcodes
Dynamic Arrays in Java Problems with Arrays Fixed size Can pick size at runtime But size can't just be changed So we run out of room We want an Array That can grow Elements of Dynamic Arrays A list of items Accessible by index efficiently - constant time can grow arbitrarily long We need The arrya to store the data in The capacity of the arrya (already available in Java) The number of items currently stored in the arr..
LeetCode two sum brute force java This is the first time trying to solve leetcode but, I could only code 2 repeating for statements. and never could think of from if to return statement although when I saw the answer, it was easy to understand. I don't really think I understand how repeated for statement works and I will try to explain it to understand. for(int i=0;i
백준 15596번 자바 문제 문제를 아예 제대로 이해하지 못하고, 클래스를 만들려고 하고 있었고 다음이 결과다. import java.util.Scanner; public class Test { public static void main(String[] args) { //정수 n개가 주어졌을 때, n개의 합을 구하는 함수를 작성하시오. // //작성해야 하는 함수는 다음과 같다. // //Java: long sum(int[] a); (클래스 이름: Test) //a: 합을 구해야 하는 정수 n개가 저장되어 있는 배열 (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000) //리턴값: a에 포함되어 있는 정수 n개의 합 Scanner sc = new Scanner(System.in); int N = sc.nextI..
백준 3444번 자바 문제 평균은 되겠지 package bj4344; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testcase = sc.nextInt(); int[] arr; // numStu만큼의 array를 만든다. for(int i=0;i
백준 8958번 자바 문제 OX퀴즈 문제를 잘못 읽고 OX에서 O의 갯수를 세는 프로그램을 짰다. 그런데 그 마저도 완벽하지가 않다. 5 OOXXOXXOOO OOXXOOXXOO OXOXOXOXOXOXOX OOOOOOOOOO OOOOXOOOOXOOOOX 이러한 인풋을 넣었을 때, 처음이 영이 나오고, 나머지 4개가 옳게 나온다. 그러니까 처음에 집어넣은 5까지 arraylist화 시켜버린 셈인데, 아직 정확히 왜 그렇게 되는 지 알 수 없다. import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) {..

반응형