자료구조(Array vs Linked) 관련하여 질문을 드리고자합니다.
Seolhun opened this issue · comments
Hun, Seol(Sol) commented
This issue is...
- Edit typos or links
- Inaccurate information
- New Resources
- Suggestions
- Questions
- Enhancement
- Comments
Description
/*** Returns the (non-null) Node at the specified element index.*/
Node<E> node(int index) {
// assert isElementIndex(index);
if (index < (size >> 1)) {
Node<E> x = first;
for (int i = 0; i < index; i++)
x = x.next;
return x;
} else {
Node<E> x = last;
for (int i = size - 1; i > index; i--)
x = x.prev;
return x;
}
}
Java LinkedList 코드를 보면 삭제/삽입 전 해당 인덱스를 탐색하기 위해 Binary search와 같은 중간 값을 기준으로 탐색을 합니다. 즉, 이는 시간 복잡도가 O(n)이 아닌 O(Log N)을 갖는 것이 더 적합한 의견이 아닐까 생각하는데, 어떻게 생각하는지 알고싶습니다.
그리고 좋은 글 감사합니다.