Chapter 39 - Trees Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What does a rooted tree have?

A

» Has a root
» Branches
» Leaves

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

What are the differences between a tree in computer science and real life?

A

» In computer science has its root at the top and its leaves at the bottom

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

What are the typical uses for rooted trees?

A

» Manipulating hierarchial data
» Manipulated sorted lists of data
» Making information easy to search

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

What is a tree?

A

» A tree is a fundamental data structure
» Consists of nodes and pointers

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

What does each tree have?

A

» A root node

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

What are the leaf nodes?

A

» Nodes at the very bottom of the tree
» And a node which has no children

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

What are nodes connected with?

A

» Pointers also known as edges

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

What is a subtree?

A

» A set of nodes and edges from any single node down through all of its descendants is known as a subtree

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

What does each edge connect?

A

» 2 nodes
» Evert node except the root is connect by exactly one edge from another node

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

What is the root?

A

» Only root which has no incoming edges

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

What is the child ?

A

» The set of nodes that have incoming edges from the same node

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

What is a binary tree?

A

» Similar to a standard rooted tree
» In which eah node has a maximum of 2 children

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

What is a binary tree?

A

» Similar to a standard rooted tree
» In which eah node has a maximum of 2 children

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

How can binary trees be represented in memory?

A

» As dicitonaries

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

What are the values of the right pointer/ left pointer if there is no child node?

A

» Null

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

What are the applications of binary trees?

A

» Database applications where efficient searching is required
» Wireless networking and routing tables

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

What does each node in a binary tree contain?

A

» A left pointer
» A right pointer
» Data

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

What are the steps to add an item to a binary tree?

A

» Check if there is free memory for the node - if there isn’t output an error
» Create a new node and insert data into it

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

What happens if the binary tree is empty when data is being added to it?

A

» New node becomes first item - create a start pointer to it

20
Q

What happens if the binary tree is not empty, when trying to add an item to a binary tree?

A

» Start at root node
» If new node should be placed before the current node, follow the left pointer
» If new should be placed after the current node, follow the right pointer
» Repeat until the leaf node is reached
» Set right pointer of the previous node

21
Q

How can we find the item we want to delete from the binary tree?

A

» Start at the root node and set it as the current node
» While the current node exists and is not the one to be deleted:
» If item to be deleted is < than the current node, follow the left pointer, if > follow the right pointer

22
Q

What are the steps to remove an item from a binary tree if the node has no children?

A

» If the previous node is greater than the current node, previous node’s left pointer is set to null

» Else, the previous node’s right pointer is set to null

23
Q

What is the Hibbard deletion algorithm?

A

» To delete a node, we find the smallest value in the right sub-tree(Sucessor)
» And move it the position occupied by G
» Smalles value in the right - sub tree will always be left-most node in the right sub tree

24
Q

What are the problems with the Hibbard delete program?

A

» Tree may become unbalanced, as any node can become the root node.

25
Q

What are the problems of adding and deleting nodes?

A

» It can impact the efficiency algorithms on binary trees

26
Q

What are the steps to use hibbard deletion if the right node exists and it has no left sub tree?

A

» Set the current node to the node’s right pointer
» Set the current node’s pointer to null

27
Q

What is a simple alternative to delete nodes from a tree?

A

» Is to introduce another attribute to each node that flags it for delted
» These deleted nodes are skipped when traversing the tree

28
Q

What is a simple alternative to delete nodes from a tree?

A

» Is to introduce another attribute to each node that flags it for delted
» These deleted nodes are skipped when traversing the tree

29
Q

What is the problem of flagging?

A

» Increase space complexity

30
Q

What are the three different binary tree traversal methods that you need to be aware of?

A

» Pre-order
» In-order
» Post-order

31
Q

What is pre-order traversal?

A

» A variation of a depth-first search used to create a copy of a binary tree

32
Q

What are the steps of pre-order traversal?

A

» Start at root node
» Output node
» Traverse the left sub tree - Continue traversing through the left pointer, until there is no pointer to traverse
» Return to previously visted node and traverse the right sub-tree
» Returen the root node and traverse the right sub-tree

33
Q

What is in-order traversal?

A

» Variation of depth-first search to output the contents

34
Q

What is the signifcant advantage of in-order traversal?

A

» Automatically sorts the contents of the structure without moving data - negates the need for insertion sort

35
Q

What are the steps of in-order traversal?

A

» Traverse the left-sub tree
» Go as fat as possible along the left-sub tree
» Return from the point visting the other nodes
» Traverse as far as possible on the right-sub tree
» Return to the root visiting the root node

36
Q

How can you output nodes in reverse order?

A

» Simply reverse the algorithm by following the right pointer before outputting the node

37
Q

What is a good exam tip?

A

» Make sure you read the question carefully to check whether it ask for a right hand tree or a left hand treee

38
Q

What is prefix notation?

A

» Polish notation - Pre-order traversal

39
Q

What is infix notation?

A

» Inorder traversal

40
Q

What is postfix notation?

A

» Post order traversal
» Reverse polish notation

41
Q

What is post-order traversal?

A

Depth-first search to delete a binary tree

42
Q

What are the steps of a post-order traversal?

A

» Start at the root node
» Traverse left sub-tree
» Follow the left pointer until it is far down as possible
» Go as far as down on the left sub tree
» Return to root visiting node
» Traverse right sub-tree

43
Q

What is one key tip to remember in post-order traversal?

A

» Each markers are on the right hand side of each node

44
Q

What is the purpose of Reverse polish notation?

A

» To evaluate algebraic expressions

45
Q

What are the steps to add nodes to a binary tree?

A

» Start at root node
» If item is less, go left
» If item is more go right

46
Q

What is tree traversal?

A

» The process of visiting(checking or updating) each node in a tree data structure

47
Q

What are the benfits of a binary tree?

A

» Dynamic
» Printed out in a sequence
» Searched quickly