Binary Trees Info Flashcards

Memorize

1
Q

What is a Generic method and what is it used for

A

a.) It is a method definiton having a special type parameter that may be used in place for types

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

Define what a tree is?

A

A tree is a set of Nodes

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

What is the distingushed Node in a tree if it is not empty

A

Root

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

What is the External node called in a tree?

A

Leaf

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

What is the internal node in a tree

A

A node with one or more children

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

What is a path in a tree

A

A path from node Vi to node Vk is a sequence of nodes such that vi+1 for 1<=i<=k

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

What is the length of a tree?

A

The length of the tree is the number of edges encountered so (k-1)

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

What is the depth of a tree

A

The depth of any node is the length of 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 an Ancestor and what is a descendant

A

If there is a path from V1 to V2 then V1 is ancestor of V2 and V2 is the descendant of V1

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

What is the height of the tree

A

The height of the tree is the height of its root

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

What does a tree node include

A

An element and nodes linked together

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

What is the Special case of K-ary Trees

A

it is a tree whose nodes have at mose two children pointers – binary trees

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

Define a Binary Tree

A

It is a rooted tree in which no node can have more than two children AND the children are distinguished as left and right

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

What is a General Binary Tree

A

It is a tree where each node has a most two nodes

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

What is a full binary Tree

A

A binary tree where every interior node has two children or is an external node

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

What is a perfect Binary tree

A

A full binary tree that every external node is at the same level

17
Q

what is a complete binary tree

A

It is like the perfect binary tree, except the last level may not be full but is filled from left to right

18
Q

Define a Binary Search Tree

A

It is a binary tree in which at every node v the values stored in the left subtree is less than the values stored in the right subtree which is greater

19
Q

What function must a BST class implement

A

A compareTo because the elements in the BST nodes must be comparable . Therefore a comparable interface or class must be defined

20
Q

How do we find whether an element exist in a BST

A

a.) Traverse for only the match
b.) Otherwise not found so return null

21
Q

What is the Running time for BST

A

O(Log N)

22
Q

How do we Insert in a BST

A

Traverse down a tree until there is no subtree Then create a new node

23
Q

What is the three cases for Deleting a node in BST

A

a.) A node has no children
delete it do nothhing more
b.) A node has one child
skip the node so that the node points to the child
c. A node has two children
replace the nodes data with the smallest data in right subtree
recursively delete the node

24
Q

What functions does the Doubly linked List have

A

add, remove, isEmpty and etc

25
Q

Explain PreOrder Traversal in BST

A

If the previous node was a parent then the next node is the immediate left child

If we already visted the left child then the next node is the immediate right child

if the those children do not exist then we backtrack up the tree

26
Q

Explain the InOrder Traversal in BST

A

First we go as far left as possible from the root keep tracking the node we pass

At a leaf we process the node retun to its parent process it and then move to the right child

27
Q

Explain the postOrder traversal in BST

A

hFirst go far right as possible from the root until we reach a node with no left cild

If the node we stop at has a right child then we move to it the again descend to the left as far as possible and repeat

28
Q

What are some recursive functions to define for BST?

A

Is it a full binary tree
is it a perfect binary tree
height of a tree
Number of Interior
Number of exterior nodes

29
Q

What is the typical base case of BST

A

O(N)