일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 선적분
- 함수
- Asteroid RL
- 파이썬
- 미분 방정식
- 회로이론
- 벡터 해석
- 자료형
- Class
- 소행성
- 2P1L
- 강화학습
- java
- BST
- 신경망
- Python
- 딕셔너리
- 딥러닝
- 코드업
- 이진탐색트리
- 자바
- 피보나치 수열
- 백트래킹
- 최단 경로
- cURL
- auto-encoder
- 벡터해석
- dictionary
- 델
- 계단 오르기
- Today
- Total
Zeta Oph's Study
[Data Structure (Java)] Map 본문
https://crane206265.tistory.com/86
[Data Structure (Java)] Heapsort
https://crane206265.tistory.com/85 [Data Structure (Java)] Heaphttps://crane206265.tistory.com/84 [Data Structure (Java)] Tree (3) - Binary Search Treehttps://crane206265.tistory.com/82 [Data Structure (Java)] Tree (2) - Tree Traversal Algorithmshttps:/
crane206265.tistory.com
이제 다시 새로운 주제를 해봅시다. Map입니다.
Map ADT
: Key-Value pair abstraction
- insert a value with specified key
- given a key, search for the corresponding value
ex) symbol table, dictionary, associative array ...
* associative array abstraction
: generalized array - keys do not need to be integers between 0~n-1
Map API
API for the Map (Data Type - key : Key / value : Value) (M : Map instance)
methods | explanation |
int size() | return # of entries in M |
boolean isEmpty() | return if M is empty |
Value get(Key k) | return the value v associated with key k (if such entry does not exist : return null) |
void put(Key k, Value v) | if key k exist : replace the associated value to v else : adds entry (k, v) |
Value remove(Key k) | remove the entry with key k, return its value (if M is empty : return null) |
<Iterable> keySet() | return the iterable collection containing all the keys in M |
<Iterable> values() | return the iterable collection containing all the values in M |
<Iterable> entrySet() | return the iterable collection containing all the key-value entries in M |
* Conventions
- no duplicate key
- no null keys / values -> we don't know wheter key/value is null or does not exist
- no limit on # of key-value pairs
Map implementation
in java.util package
1. java.util.HashMap : not ordered entries
2. java.util.LinkedHashMap : entires can be retrieved in insertion order / access order
3. java.util.TreeMap : TreeMap class implementing SortedMap is efficient for traversing the keys in sorted order
ex) Class<keyDataType, valueDataType> -> HashMap<String, Integer>, etc.
<Elementary implementation of Map>
Unordered linked list : sequential search
operation | running time | explanation |
search | O(n) | scan through all keys until find a match |
insert | O(n) | scan through all keys to find if the key already exists |
Ordered array : binary search
- parallel array for key-value pairs : one for keys Key[] & one for values Value[]
operation | running time | explanation |
search | O(log n) | binary search |
insert | O(n) | searching position to insert : O(log n) shifting to maintain sorted array : O(n) ==> O(n) |
'프로그래밍 > Java' 카테고리의 다른 글
[Data Structure (Java)] Set (1) | 2024.06.05 |
---|---|
[Data Structure (Java)] Hash (Separate Chaining & Linear Probing) (1) | 2024.06.05 |
[Data Structure (Java)] Heapsort (2) | 2024.06.03 |
[Data Structure (Java)] Heap (2) | 2024.06.02 |
[Data Structure (Java)] Tree (3) - Binary Search Tree (1) | 2024.06.01 |