SW2 Midterm 2 BST

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

contains Algorithm (searching in BST)

returns a binary tree t
if t is empty x is not found
r is the root, of t then found

<p>returns a binary tree t<br>if t is empty x is not found<br>r is the root, of t then found</p>
2
New cards

Insert Element  in  BST

if tree is empty, assemble single node tree with x
otherwise compares x with r and resemble recursively

<p>if tree is empty, assemble single node tree with x<br>otherwise compares x with r and resemble recursively</p>
3
New cards

removeSmallest(HelperFunction)

located in the left most side of the tree

<p>located in the left most side of the tree </p>
4
New cards

remove (Delete specific element from BST)

3 cases: deleting leaf, deleting a single child, deleting from a node with two children
O(h) complexity worst case 

<p>3 cases: deleting leaf, deleting a single child, deleting from a node with two children<br>O(h) complexity worst case&nbsp;</p>
5
New cards

Height (Tree Height)

Mathematical:

-empty tree: 0 
-non empty Tree = 1+Math.max(height(L), height(R))

<p>Mathematical:</p><p>-empty tree: 0&nbsp;<br>-non empty Tree = 1+Math.max(height(L), height(R))</p>
6
New cards

size (counting all nodes)

empty: 0
nonempty: 1 + size(leftTree) + size(rightTree)

<p>empty: 0<br>nonempty: 1 + size(leftTree) + size(rightTree)</p>
7
New cards

PreOrder


root>left>right
Traversal for copying or printing the tree structure

<p><br>root&gt;left&gt;right<br>Traversal for copying or printing the tree structure</p>
8
New cards

In Order Traversal

Left>Root>Right
getting keys from BST in sorted order

<p>Left&gt;Root&gt;Right<br>getting keys from BST in sorted order</p>
9
New cards

Post-order


Order: left>right>Root

Traversal for deleting a subtrees/tree, children first (need to delete the children first before deleting the root)

<p><br>Order: left&gt;right&gt;Root<br><br>Traversal for deleting a subtrees/tree, children first (need to delete the children first before deleting the root)</p>
10
New cards

BST order

root k > left subtree

root k < right subtree

11
New cards

Math.max(a,b)

-Returns greater of two numbers
-Used for height

12
New cards

Mathematical size of non empty Tree

b.size = 0

13
New cards

Characteristics of Binary Trees

size, labels, height, follow recursive structure, do not have to be balanced

14
New cards

Assemble (T root, Binary Tree<T> left, Binary Tree<T> left, )

Kernal method: combines root, and the 2 subtrees

15
New cards

T disassemble (BinaryTree <T> left, BinaryTree<T>right)

returns the root value and breaks apart the left and right subtrees, and clears the original tree

16
New cards

T root()

returns the root (so long as its nonempty)

17
New cards

T replaceRoot (T x)

replaces the root with x (and returns old root) such that it is a nonempty Tree

18
New cards

Iterator<T> iterator()

return an iterator that visits labels in-order by contract

19
New cards