본문 바로가기

전체 글

(92)
[Data Structure 기초연습] 해시 테이블을 이용한 수 찾기 //20240302 //해시 테이블을 이용한 수 찾기 //주어진 첫 번째 배열을 이용하여 해시 테이블을 초기화 한 후 //두 번째 배열이 주어졌을 때 해당 배열 내 데이터가 해시 테이블에 있는지 확인하는 코드를 작성하세요 import java.util.Hashtable; public class hashTablePractice06 { public static void solution(int[] arr1 , int[] arr2){ Hashtable ht = new Hashtable(); for (int i = 0; i < arr1.length; i++) { ht.put(arr1[i], arr1[i]);//key 와 value 둘다 동일한 값으로 저장 } for (int i = 0; i < arr2.lengt..
[Data Structure 기초연습] HashTable - 해시 충돌 해결 - 분리 연결법 //20240229 //해시 충돌 해결 - 분리 연결법 class Node6{ int key; int data; Node6 next; Node6(){} Node6(int key, int data, Node6 next){ this.key = key; this.data = data; this.next = next; } } class LinkedList6{ Node6 head; LinkedList6(){} LinkedList6(Node6 node){ this.head = node; } public boolean isEmpty(){ return this.head == null; } public void addData(int key, int data){ if(this.head == null){ this.head ..
[Data Structure 기초연습] HashTable - 해시 충돌 해결 - 개방 주소법 (이중 해싱) //해시 충돌 해결 - 개방 주소법 (이중 해싱) class MyHashTable4 extends MyHashTable{ int c; MyHashTable4(int size){ super(size); this.c = this.getHashC(size); } public int getHashC(int size){ int c = 0; if(size 2 ; i--) { boolean isPrime = true; for (int j = 2; j < i; j++) { if(i % j == 0){ isPrime = false; break; } } if (isPrime){ c = i; break; } } return c; } public int getHash2(int key){ int hash = 1 + key % ..