Ch 4: Trees Flashcards

1
Q

what is a binary tree?

A

a tree where each node has up to two “children”: left and right child

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a leaf?

A

a tree node with no children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is an internal node?

A

a node with at least one child

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the parent?

A

a node with a child is said to be the child’s parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what are ancestors?

A

the node’s parent, the parent’s parent, etc. up to the tree’s root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a root node?

A

the one tree node with no parent (“top” node)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is an edge?

A

a link from a node to a child

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is a node’s depth?

A

number of edges on the path from the root to the node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a tree’s height?

A

the largest depth of any node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is the height of a tree with no nodes?

A

height is 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

when is a tree full?

A

every node contains 0 or 2 children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

when is a tree complete?

A

when all levels, except possibly the last level, contain all possible nodes and all nodes in the last level are as far left as possible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

when is a tree perfect?

A

when all internal nodes have 2 children and all leaf nodes are at the same level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what are trees commonly used to represent?

A

hierarchical data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is binary space partitioning (BSP)?

A

a technique of repeatedly separating a region of space into two parts and cataloging objects contained within the regions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is a BSP tree?

A

a binary tree used to store information for BSP

17
Q

what is in each node of a BSP tree?

A

holds information about a region of space and which objects are contained in this region

18
Q

what is a binary search tree (BST)?

A
  • a form of a binary tree that has an ordering property that any node’s left subtree keys are less than the nodes keys and the right subtree keys are more than the nodes keys
  • ordering property allows for faster searching
19
Q

what is search?

A

to find a node with a desired key, if such node exists

20
Q

what is a successor?

A

the node that comes after in the BST ordering

21
Q

what is a predecessor?

A

the node that comes before in the BST ordering

22
Q

what is the search algorithm?

A

given a key, returns first node found watching key or null if matching node with found

23
Q

what is insert?

A

an operation that inserts a new node in a proper location obeying the BST ordering property

24
Q

what is remove?

A

an operation that removes the first-found matching node, restructuring the tree to preserve the BST ordering property

25
Q

what is tree traversal?

A

an algorithm that visits all nodes in the tree once and performs an operation on each node

26
Q

what is in-order traversal?

A

visits all nodes in a BST from smallest to largest

27
Q

what is in-order traversal useful for?

A

when printing tree’s nodes in sorted order

28
Q

what is a trie (prefix tree)?

A

a tree representing a set of strings

29
Q

what does each node represent in a trie?

A

represents a single character and has at most one child per distinct alphabet character

30
Q

what is a terminal node?

A

represents a terminating character, which is the end of a string in the trie

31
Q

what is trie insert

A

an operation that creates a path from the next to a terminal node that visits all the string’s characters in a sequence

32
Q

explain the trie insert algorithm

A

a current node pointer initially points to root node, then a loop iterates through the string’s characters. for each character C, a new child node is added only if the current node does not have a child for C. the current node pointer is assigned with the current node’s child for C. after all characters are processed, a terminal node is added and returned

33
Q

what is trie search?

A

an operation that returns the terminal node corresponding to that string, or null if the string is not in the trie

34
Q

what is trie remove?

A

an operation that removes the string’s corresponding terminal code and non-root ancestors with 0 children

35
Q

explain BST insert algorithm

A
  1. if root is null then node is set to root
  2. if root isn’t null, then if key is less than root it’ll check if root’s left is empty. if it is then node is placed. other wise it’ll check again if key is greater than or less than the node and keep traversing until it finds it spot
  3. if root isn’t null and key is more than root it’ll check Iif roots right is empty. if it is then node is placed otherwise it’ll check again if key is greater than or less than the node and keep traversing until it finds it spot
36
Q

explain BST remove algorithm

A
  1. search for a matching node in the tree
  2. if found:
    - if node is a leaf node, the node is removed and parents left/right is set to null, if node was root then root is set to null and tree is empty
    - if node is an internal node with one child, then the parent node’s child will be set to the current node’s child
    - if node is an internal node with two children, the successor is found (the right most child in node’s subtree) and copied in place of the current node. the originally successor is deleted
37
Q

explain BST inorder traversal algorithm

A
  1. current node points to root
  2. if root is null, return otherwise printInOrder is recursively called on root’s left, then current node is printed, then printInOrder is recursively called on root’s right