CSCI 211 Test 2 Flashcards

1
Q

a tree is a

A

non-linear structure in which elements are organized into a hierarchy; it is comprised of a set of nodes in which elements are stores and edges connect one node to another, and each node is located on a particular level

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

a node can have ? parent(s)

A

only one

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

a node with no children

A

leaf node

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

not the root node or a leaf node

A

internal node

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

a subtree is

A

a tree structure that makes up part of a larger tree

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

one important criterion for classifying trees is

A

the number of children it can have

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

defining trees (3 things)

A
  1. Nodes connected by edges
  2. Can be classified by max # children
  3. Do not have cycles or “loops” - they are recursive structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

binary tree

A

tree in which nodes have at most two children

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

a tree is balanced if

A

all of the leaves of the tree are on the same level or within one level of each other

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

a balanced n-ary tree with m elements will have a height of

A

log base n of m

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

a tree is complete if

A

it is full, or full to the next-to-last level with all leaves af the bottom level on the left side of the tree

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

all tree traversals start at the ? of the tree

A

root

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

each node can be thought of as the ? of a subtree

A

root

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

list the four classic types of tree traversals

A
  1. Preorder
  2. Inorder
  3. Postorder
  4. Level-order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Preorder

A

Visit the root, then traverse the subtrees left to right

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

Inorder

A

Traverse the left subtree, then visit the root, then traverse the right subtree

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

Postorder

A

Traverse the subtrees from left to right, then visit the root

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

Level-order

A

Visit each node at each level of the tree from top to bottom and left to right

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

expression tree

A

a tree that shows the relationships among operators and operands in an expression; evaluated from the bottom up

20
Q

decision tree

A

a tree whose nodes represent decision points, and whose children represent the options available

21
Q

binary search trees

A

elements are organized to facilitate finding a particular element when needed - the left subtree of each node n contains elements less than the element stored in n and the right subtree of each node n contains elements greater than or equal to the element stored in n

22
Q

a LinkedList is more efficient than a BST for which operations?

A

removeFirst and first

23
Q

a right rotation on a BST

A
  1. make the left child element of the root the new root element
  2. make the former root element the right child element of the new root
  3. make the right child of what was the left child of the former root the new left child of the former root
24
Q

a left rotation on a BST

A
  1. make the right child element of the root the new root element
  2. make the former root element the left child element of the new root
  3. make the left child of what was the right child of the former root the new right child of the former root
25
Q

an AVL tree

A

ensures a BST stays balanced because for each node in the tree, there is a numeric balance factor (the diff between the heights of its subtrees)

26
Q

heap (technically a minheap)

A

a complete binary tree in which each element is less than or equal to both of its children

27
Q

is a heap a binary tree? a binary search tree?

A

yes; no

28
Q

adding a new element to a heap

A
  1. add as leaf
  2. move element upward toward root, exchanging positions with its parent, until the relationship among the elements is appropriate
29
Q

removing the min element of a heap

A
  1. move the last leaf of the tree to be the new root of the tree
  2. move it down the tree as needed until the relationships among the elements is appropriate
30
Q

priority queue

A

removes elements in priority order, independent of the order in which they were added; a heap is a classic mechanism for implementing

31
Q

we would rather implement heaps with ? than ?

A

arrays than links

32
Q

implementing heaps with arrays: a parent element at index n will have children stored at ? and ? of the array; conversely, for any node other than the root, the parent of the node is found at index ?

A

2n+1 and 2n+2; (n-1)/2

33
Q

heap sort

A

sorts a set of elements by adding each one to a heap, then removing them one at a time

34
Q

set

A

a collection with no duplicates; primary purpose is to determine whether an element is a member

35
Q

map

A

a collection that establishes a relationship between keys and values; the goal is to have an efficient way to obtain a value given its key

36
Q

keys of a map must be ?, but multiple keys could map to the same object

A

unique

37
Q

implementation of sets and maps using trees

A

all of the basic operations are performed with O(logn) efficiency

38
Q

an element in a hash table is stored in a location based on a ?

A

hash function

39
Q

a hash function makes some calculation based on the ?

A

element

40
Q

multiple elements may be stored in the same location of a hash table

A

“collision”

41
Q

a hash function that maps each element to a unique location is called a ?

A

perfect hashing function

42
Q

hash code

A

a short sequence of bits computed from the contents of a longer piece of data (desirable for diff data to produce diff hash codes)

43
Q

hash function

A

maps a data value (or its hash code) to an array index (use to decrease the number of possible indexes)

44
Q

each location in a hash table is called a

A

“cell” or “bucket”

45
Q

access time to a particular element in a hash table is ? of the number of elements stored

A

independent