2021. 5. 3. 20:56ㆍ개발공부/자료구조 알고리즘
- Intro to Maps
. Retrieve based on keys, which are unique.
. Similar with arrays in that assists key uses like an index, but it need not be numeric and don't designate directly as array.
. Have advantage when save data by uninteger index.
> Applications of Maps are ID-PW, Domain-IP...etc
- Ambiguity of null in Maps
. put returns null if when entry is empty. It can return null also when (k, null) key has value of null.
> Some implementations explicitly forbid use of null value. However, we can use containsKey(k) to find out whether entry is null.
- Implementation of Unsorted Map
. O(n). Not efficient because of the need of scan through the entire list.
. put, get, remove methods requires check if value k is empty. Use nonpublic method findIndex(k) for that.
> In remove, we can use ArrayList class's remove method but we don't because of unnecessary of loop shifts all subsequent to the left. Since map is not unordered, we relocate last entry to vacate(removed) cell, remove last entry.
출처 : Data Structures and Algorithms in Java, 6th Edition 6th Edition (Michael T. Goodrich, Wiley)
'개발공부 > 자료구조 알고리즘' 카테고리의 다른 글
[프로그래머스 스쿨] 알고리즘 - 1 (0) | 2023.06.28 |
---|---|
[Data Structure & Algorithm in Java 6th] Ch.3 Fundamental Data Structure (0) | 2021.05.19 |
[Data Structure & Algorithms in Java 6th] Ch.10 - Hash tables (0) | 2021.05.12 |
[Data Structures & Algorithms in Java 6th] Ch.8 - Trees (0) | 2021.04.29 |
[Data Structures & Algorithms in Java 6th] Ch.1 - Java Prmier (0) | 2021.04.29 |