Data Structures Midterm

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/117

encourage image

There's no tags or description

Looks like no tags are added yet.

118 Terms

1
New cards

Worst-case time complexity

Maximum time an operation can take for input size n.

2
New cards

Average-case time complexity

Expected time over an assumed distribution of inputs or tree shapes.

3
New cards

Amortized time complexity

Average cost per operation over a sequence of operations, even if some operations are expensive.

4
New cards

Primitive operation (POP)

An elementary operation counted in algorithm analysis: assignment, function call, arithmetic, comparison, Boolean operation, indexing/pointer traversal, or return.

5
New cards

Big-O notation

Asymptotic upper bound on an algorithm's growth rate.

6
New cards

Hash table load factor

λ = n/N, where n is the number of entries and N is table capacity.

7
New cards

Hash function

Maps a key to an integer hash code.

8
New cards

Compression function

Maps a hash code to a valid table index.

9
New cards

Polynomial hash method

Weights character positions when calculating a string's hash code, so different character orders can produce different codes.

10
New cards

MAD compression method

Multiply-Add-Divide: maps a hash code to an index using multiplication, addition, and modulo by table capacity.

11
New cards

Hash table: Clear

Average O(n); worst-case O(n).

12
New cards

Hash table: Get

Average O(1); worst-case O(n).

13
New cards

Hash table: Put

Average O(1); worst-case O(n).

14
New cards

Hash table: Remove

Average O(1); worst-case O(n).

15
New cards

Hash table: Replace

Average O(1); worst-case O(n).

16
New cards

Hash table: ChangeCapacity

O(n) average and worst case.

17
New cards

Hash table: Rehash

O(n) average and worst case.

18
New cards

BST: Clear

O(n) average and worst case.

19
New cards

BST: Find

Average O(log n); worst-case O(n).

20
New cards

BST: Height

Average O(log n); worst-case O(n).

21
New cards

BST: Insert

Average O(log n); worst-case O(n).

22
New cards

BST: Remove

Average O(log n); worst-case O(n).

23
New cards

BST: Copy

O(n) average and worst case.

24
New cards

BST: Preorder to List

O(n) average and worst case.

25
New cards

B-Tree: Clear

O(n) average and worst case.

26
New cards

B-Tree: Find

O(log_t n) average and worst case.

27
New cards

B-Tree: Height

O(log_t n) average and worst case.

28
New cards

B-Tree: Insert

O(log_t n) average and worst case.

29
New cards

B-Tree: Remove

O(log_t n) average and worst case.

30
New cards

Hash table expected operation time

O(1), assuming a suitable hash function and reasonable load factor.

31
New cards

Hash table worst-case operation time

O(n), when many keys collide or the table must be scanned.

32
New cards

BST worst-case operation time

O(n), when the tree degenerates into a chain.

33
New cards

B-Tree operation time

O(log_t n), where t is the minimum degree/order parameter.

34
New cards

Effect of increasing B-Tree t

A larger t can reduce tree height and the number of levels traversed.

35
New cards

Separate chaining recommended load factor

λ < 0.9, according to the study notes.

36
New cards

Open addressing recommended load factor

λ < 0.5, according to the study notes.

37
New cards

Propositions 4.3, 4.5, 4.9, 10.7, 10.8, 14.1 and Theorem 18.1

4.3: 1+...+n=n(n+1)/2, useful for O(n²) nested loops. 4.5: geometric sum=(a^(n+1)-1)/(a-1), for a≠1. 4.9: degree-d polynomial is O(n^d). 10.7: n-entry multi-way search tree has n+1 external nodes. 10.8: (2,4)-tree height is O(log n), so operations are O(log n). 14.1: (a,b)-tree height is logarithmic in n. 18.1: B-Tree find, insert and remove are O(log_t n).

38
New cards

Hash table load factor formula

λ = n/N, where n is entries and N is capacity.

39
New cards

Separate chaining

Stores colliding entries in a collection, such as a linked list, at the same bucket.

40
New cards

Open addressing

Stores entries directly in the table and probes for another slot after a collision.

41
New cards

Closed addressing

Another name used in the notes for separate chaining.

42
New cards

Collision

Occurs when multiple keys map to the same table index.

43
New cards

Linear probing

After a collision, check successive table positions, wrapping around at the end.

44
New cards

Quadratic probing

Checks positions A[(i+j²) mod N] for j=0,1,2,...

45
New cards

Quadratic probing limitation

May cause clustering and may fail to visit every slot under unsuitable table-size conditions.

46
New cards

Double hashing

Uses a second hash function to determine the probe step after a collision.

47
New cards

Double hashing probe formula

A[(i+f(j)) mod N], where f(j)=j×c(h'(k)) in the notes.

48
New cards

Secondary hash function requirement

The secondary hash must not produce a zero step size.

49
New cards

Example secondary hash function

c(h(k)) = q − (h(k) mod q), according to the notes.

50
New cards

Purpose of rehashing

Recompute bucket positions for existing entries after table capacity changes.

51
New cards

Hash table resizing and amortized analysis

A resize costs O(n), but infrequent geometric resizing can make amortized insertion O(1).

52
New cards

BST ordering property

Every key in a node's left subtree is smaller; every key in its right subtree is greater.

53
New cards

BST search rule

If the target is smaller, go left; if greater, go right; if equal, return the node.

54
New cards

BST insertion rule

Follow the ordering property until reaching an empty child position, then insert.

55
New cards

BST removal with two children

Replace the removed key with the minimum key in its right subtree, then remove that successor.

56
New cards

BST typical search time

O(log n) for a suitably shaped tree.

57
New cards

BST worst-case search time

O(n) when the tree degenerates into a chain.

58
New cards

Ancestor

Node u is an ancestor of v if u=v or u is an ancestor of v's parent.

59
New cards

Descendant

Node v is a descendant of u if u is an ancestor of v.

60
New cards

Is a node its own ancestor?

Yes, according to the notes' definition.

61
New cards

Is a node its own descendant?

Yes, according to the notes' definition.

62
New cards

Depth of a node

Number of ancestors, excluding the node itself.

63
New cards

Height of a tree

Maximum node depth; equivalently, the number of edges on the longest root-to-leaf path.

64
New cards

Height of an external node

0, according to the notes.

65
New cards

External nodes in a BST

Represented by null pointers.

66
New cards

External nodes in a B-Tree

Represent actual external positions rather than null pointers, according to the notes.

67
New cards

Preorder traversal

Visit root, traverse left subtree, then right subtree.

68
New cards

Inorder traversal

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

69
New cards

Postorder traversal

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

70
New cards

Level-order traversal

Visit nodes level by level, typically using a queue.

71
New cards

Depth-first search (DFS)

Explores deeply before backtracking; typically uses a stack or recursion.

72
New cards

Breadth-first search (BFS)

Explores level by level; typically uses a queue.

73
New cards

(a,b)-tree size property

Each internal node other than the root has at least a children; every internal node has at most b children.

74
New cards

(a,b)-tree depth property

All external nodes have the same depth, so the tree is balanced.

75
New cards

B-Tree minimum degree t

Parameter determining the minimum number of keys and children allowed in non-root nodes.

76
New cards

B-Tree minimum keys per non-root node

t−1 keys.

77
New cards

B-Tree maximum keys per node

2t−1 keys in the standard minimum-degree convention.

78
New cards

B-Tree minimum children per non-root internal node

t children.

79
New cards

B-Tree maximum children per internal node

2t children in the standard minimum-degree convention.

80
New cards

B-Tree root key property

The root has at least one key when the tree is nonempty.

81
New cards

B-Tree height

O(log_t n).

82
New cards

B-Tree find

O(log_t n).

83
New cards

B-Tree insert

O(log_t n).

84
New cards

B-Tree remove

O(log_t n).

85
New cards

B-Tree split during insertion

Split a full node and promote its median key to the parent.

86
New cards

B-Tree borrowing during deletion

Transfer a key through the parent from a sibling with an extra key.

87
New cards

B-Tree merging during deletion

Combine a child, a separator key from the parent, and a sibling when borrowing is unavailable.

88
New cards

B-Tree root contraction

If deletion leaves the root empty with one child, make that child the new root.

89
New cards

How to calculate f(n)

Count primitive operations as a function of input size n.

90
New cards

How to determine Big-O from f(n)

Identify the dominant growth term; ignore constant factors and lower-order terms.

91
New cards

Single loop running n times

O(n), assuming constant work per iteration.

92
New cards

Two nested loops each running n times

O(n²), assuming constant work per iteration.

93
New cards

Three nested loops each running n times

O(n³), assuming constant work per iteration.

94
New cards

Sequential loops

Add their costs; the dominant term determines the overall Big-O.

95
New cards

Triangular nested-loop iteration count

1+2+...+n=n(n+1)/2, giving O(n²).

96
New cards

Loop that doubles its variable each iteration

O(log n), when doubling until reaching n.

97
New cards

Array indexing

One primitive operation under the notes' counting model.

98
New cards

Pointer traversal

One primitive operation under the notes' counting model.

99
New cards

Assignment

One primitive operation under the notes' counting model.

100
New cards

Arithmetic operation

One primitive operation under the notes' counting model.