Part 3 Flashcards

1
Q

Stacks and queues are examples of ________ adts

A

Linear

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

Trees are ____________ ADTs

A

Non-linear / Recursive

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

The child of a tree has the type

A

Tree

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

A tree with no children is called

A

A leaf

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

What word is used to refer to positions in a tree?

A

Node

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

The root node of a tree is a node with no _____

A

parent

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

What makes a tree a binary tree?

A

Each node will have no more than 2 children

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

What are the primitive operations of binary trees, and their semantics?

A

createtree - creates a new empty tree

maketree - takes data item, two trees and creates a new tree with the data item in the root and two trees as children

isempty - deduce whether the tree is empty

leftchild/rightchild - return references to the children

value - return the data item at the root (node)

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

What are the three orders of tree traversal?

A

pre-order

post-order

in-order

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

what is pre-order traversal?

A

visit root, then left child in pre-order, then right child in pre-order

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

what is post-order traversal?

A

visit the left child in post-order, then the right child in post-order, then the root

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

what is in-order traversal?

A

visit he left child in-order, then the root, then the right child in-order

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

What is binary chop?

A

Look at middle of array, if its greater than the number searching for, look at middle of left half, else middle of right half & repeat till you find the number

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

What is a binary search tree?

A

A binary tree where all the left children are less than the root and all the right children are greater

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

How are non-binary trees typically implemented?

A

Left child right sibling

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

What is the left-child-right-sibling representation?

A

Each node may has one child

More than one child = the children are stored as references from the first child

A

/

B - C - D

/

E

17
Q

When deleting a node in a binary search tree, if the node has one child, what is the procedure?

A

Replace the reference from the parent to the node with a reference to the node’s child

18
Q

When deleting a node in a binary search tree, if the node has two children, what is the procedure?

A

Replace the reference to the node with a reference to either largest value in left child or smallest value in right child

19
Q

The time taken for insertion, deletion and searching binary search trees are approximately ________

A

proportional to the depth of the tree

20
Q

What is the average depth of a binary search tree if the items are inserted in a random order?

A

2.5log2n

21
Q

What are the average and best times for insertion deletion and searching (big O)?

A

Average: O(logn)

Worst: O(n)

22
Q

When writing a generic class how can it be restricted so the Type must extend comparable?

A

public class BST<t>&gt;</t>