line breaks

This commit is contained in:
Jidong Xiao
2023-11-17 13:45:13 -05:00
parent 0b0f6bd3c4
commit 51e4236416

View File

@@ -77,9 +77,13 @@ and the child and parent “pointers” can be implicitly calculated.
- To do this, number the nodes in the tree starting with 0 first by level (top to bottom) and then scanning across - To do this, number the nodes in the tree starting with 0 first by level (top to bottom) and then scanning across
each row (left to right). These are the vector indices. Place the values in a vector in this order. each row (left to right). These are the vector indices. Place the values in a vector in this order.
- As a result, for each subscript, i, - As a result, for each subscript, i,
– The parent, if it exists, is at location ⌊(i − 1)/2⌋. – The parent, if it exists, is at location ⌊(i − 1)/2⌋.
– The left child, if it exists, is at location 2i + 1. – The left child, if it exists, is at location 2i + 1.
– The right child, if it exists, is at location 2i + 2. – The right child, if it exists, is at location 2i + 2.
- For a binary heap containing n values, the last leaf is at location n − 1 in the vector and the first node with less than two children is at location ⌊(n − 1)/2⌋. - For a binary heap containing n values, the last leaf is at location n − 1 in the vector and the first node with less than two children is at location ⌊(n − 1)/2⌋.
- The standard library (STL) priority_queue is implemented as a binary heap. - The standard library (STL) priority_queue is implemented as a binary heap.