본문 바로가기
javascript

Tree / Binary Search Tree

by rami_ 2022. 2. 26.

1. Tree

In computer science, a tree is a widely used abstract data type(추상적인 데이터 유형) that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes.

A tree data structure can be defined recursively as a collection of nodes, where each node is a data structure consisting of a value and a list of references to nodes. The start of the tree is the "root node" and the reference nodes are the "children". No reference is duplicated and none points to the root.

출처 : Wikipedia

 

 

2. Binary Search Tree

In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted binary tree data structure whose internal nodes each store a key greater than all the keys in the node's left subtree and less than those in its right subtree. The time complexity of operations on the binary search tree is directly proportional to the height of the tree.

Binary search trees allow binary search for fast lookup, addition, and removal of data items, and can be used to implement dynamic sets and lookup tables. Since the nodes in a BST are laid out in such a way that each comparison skips about half of the remaining tree, the lookup performance is proportional to that of binary logarithm.

The performance of a binary search tree is dependent on the order of insertion of the nodes into the tree; several variations of the binary search tree can be built with guaranteed worst-case performance. The basic operations include: search, traversal, insert and delete. BSTs with guaranteed worst-case complexities perform better than an unsorted array, which would require linear search time.

The complexity analysis of BST shows that, on average, the insert, delete and search takes O(log n) for n nodes. In the worst case, they degrade to that of a singly linked list: O(n)

출처 : Wikipedia

'javascript' 카테고리의 다른 글

if..else / if.. else if  (0) 2022.02.27
Early Return  (0) 2022.02.27
this  (0) 2022.02.16
prototype/__proto__  (0) 2022.02.05
closure  (0) 2022.02.02