Chapter 25

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

linked structure

How can a binary search tree be implemented?

locate it in the tree does it have a left child? delete the element and reconnect the tree

How do you delete an element from a BST?

Let current point to node that contains the element parent point to parent of the current node determine case

How do you delete an element from a binary search tree?

NO YES NO NO

If a set of elements is inserted into a BST in two different orders, will the two corresponding BSTs look the same? Will the inorder traversal be the same? Will the postorder traversal be the same? Will the preorder traversal be the same?

What is the time complexity for search, insertion, and deletion if the tree is well balanced?

O(logn)

What is the time complexity for search, insertion, and deletion?

O(n)

inorder: AFGMRT preorder: GFARMT postorder: AFMTRG

Show the inorder, preorder, and postorder of traversing the elements in the binary tree shown in

True or False. Every internal node in a Huffman tree has two children.

True

nodes that share the same parent node

What are Siblings?

all common operations for trees

What can we use an interface named Tree to define?

Tree

What does AbstractTree partially implement?

creates a node for element e and inserts it into the tree

What does insert(E e) method do?

false

What does the insert(E e) method return if the element is already in the tree?

a path of the nodes as an array list

What does the path(E e) method return?

subtree is empty and "element" is not in the tree

What if If current is null?

has no duplicate elements, left subtree is less than the node, right subtree is greater than the node

What is a binary search tree?

set of all nodes at a given depth

What is a level of the tree?

a leaf

What is a node without children called?

root, left, right level by level

What is breadth-first traversal?

0

What is height of a tree that contains a single node?

left, root, right freefall

What is inorder traversal?

left, right, root leafbreak

What is postorder traversal?

can use for each loop to traverse tree can use Iterator methods hasNext() next and remove hides structural details, provides uniform way of traversing

What is the benefit of being a subtype of Iterable<E> ?

length of the path from the root to the node

What is the depth of a node?

the length of the path from the root node to its furthest leaf

What is the height of a nonempty tree?

-1

What is the height of an empty tree?

number of the edges

What is the length of a path in a binary tree?

a left (right) child of the node

What is the root of a left (right) subtree of a node is called?

O(n)

What is the time complexity of inserting an element into a BST?

the process of visiting each node in the tree exactly once

What is tree traversal?

iterator() method returns instance of java.util.iterator

What method is defined in the java.lang.Iterable<E> interface?

provides a uniform way of traversing the elements in a container, while hiding the container's structural details

Why is Iterator an important software design pattern?

stack

after implementing iterator what should you use to store the nodes?

what is a greedy algorithm?

algorithm makes choice that is optimal locally in hope choice leads to globally optimal solution

how is greedy programming used in huffman coding tree?

chooses two trees with the smallest weight and creates a new node as their parent.

16 becomes left child of 20

delete 10 from the tree

16 becomes the root

delete 20 from the tree

57 becomes left child of 60

delete 55

59 becomes the root

delete 60

What is a greedy algorithm? Give an example.

finding local optimal soln in hope of globally optimal soln ex: to get coins for $0.98 use three quarters two dimes two pennies uses largest unit as much as possible

recursion

how can you display a binary tree?

If the tree is empty, create a root node with the new element else find the parent (either left or right)

how do you insert an element into the tree?

public void remove() { throw new UnsupportedOperationException ("Removing an element from the iterator is not supported"); }

how do you prevent the user from using the iterator remove method?

If "element" is less than "current.element" , assign "current.left" to "current" If "element" is less than "current.element" , assign "current.right" to "current" If "element" is equal to "current.element" , return "true"

how do you search for an element in a binary search tree?

forward iterator elements traversed once

what does java.util.Iterator define?

traversing in both forward and backward directions

what does java.util.ListIterator define?

false

what does the delete method return if the element is not in the binary search tree?

binary tree that stores characters based on occurrences

what is Huffman coding tree?

checks to avoid runtime errors

what is defensive programming?

compresses data by using fewer bits to encode frequently occurring characters

what is huffman coding?

delete

what is more efficient remove method in iterator or delete method in BinaryTree?

root, left, right outline

what is preorder traversal?

if (element not found) return true; if (current has no left child: case 1) else (has left child: case 2) return true;

what is the layout of the code that deletes an element from a binary search tree?

44 left child of 45

what is the result of adding 44?

connect parent with right child of current node

when removing an element from a binary search tree, what do you do if the current node does not have a left child?

Let rightMost point to largest element in left subtree parentOfRightMost point to parent of rightMost node Replace element value in current node with the one in rightMost node connect the parentOfRightMost node with the left child of the rightMost node delete the rightMost node

when removing an element from a binary search tree, what do you do if the current node has a left child?


Ensembles d'études connexes

AP Computer Science Principles Vocabulary

View Set

1-2 Apprentice Lineman Study Guide

View Set

Causes of the Russian Revolution

View Set

LearningCurve - Chapter 13: Monopoly

View Set