CS314 Exam 3

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/61

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.

62 Terms

1
New cards

What must be done if a class has one or more abstract methods?

The class must be declared abstract to avoid compile errors.

2
New cards

Can objects of an abstract type be instantiated?

No, objects of an abstract type cannot be instantiated.

3
New cards

What is required for a subclass inheriting abstract methods?

The subclass must implement all inherited abstract methods or be declared abstract.

4
New cards

What is the best and worst case time complexity for adding an element in a linked list?

Best case and worst case are both O(1)

5
New cards

What is the best and worst case time complexity for adding an element in an array list?

Best case is O(1). Worst case is O(N) if need to resize

6
New cards

Order of Insert for Singly-Linked List

Best Case: O(1) if inserting at the beginning or end. Average Case: O(N). Worst Case: O(N) if inserting immediately before the last element, need to traverse through almost the whole list.

7
New cards

Order of Insert for Doubly-Linked List

Worst Case: O(N). Can cut T(N) in half by starting from either front or back based on if the position is in the first or second half of the list.

8
New cards

Order of Insert for Array List

Worst Case: O(N) because of shifting all the elements.

9
New cards

Doubly Linked List - Advantages

Can traverse through the list backwards, Easier to implement remove(), Lower time complexity when searching for an element

10
New cards

Doubly Linked List - Disadvantages

Uses 50% more storage, Updates double the references when inserting/removing

11
New cards

Should we make the front or back of the Linked List the "top" of the stack?

Front because all methods are O(1)
Back will cause the pop() to be O(N). For a Doubly Linked List
It doesn't matter, all functions will be O(1)

12
New cards

Should we make the front or back of the list the front of the queue?

Front of LL is front of queue because back would have an O(N) dequeue

For a doubly linked list?
It doesn't matter, all functions will be O(1)

ArrayList?
Both of them suck Front will cause an O(N) dequeue Back will cause an O(N) enqueue

13
New cards

Best-case time complexity for Selection Sort

O(N^2)

14
New cards

Worst-case time complexity for Selection Sort

O(N^2)

15
New cards

Average-case time complexity for Selection Sort

O(N^2)

16
New cards

Is Selection Sort a comparison sort?

Yes

17
New cards

Is Selection Sort an in-place sort?

Yes

18
New cards

Is Selection Sort a stable sort?

No

19
New cards

Best-case time complexity for Insertion Sort

O(n) when data is already sorted.

20
New cards

Worst-case time complexity for Insertion Sort

O(N^2)

21
New cards

Average-case time complexity for Insertion Sort

O(N^2)

22
New cards

Is Insertion Sort a comparison sort?

Yes

23
New cards

Is Insertion Sort an in-place sort?

Yes

24
New cards

Is Insertion Sort a stable sort?

Yes

25
New cards

Best-case time complexity for Radix Sort

O(N * log10(max Val))

26
New cards

Worst-case time complexity for Radix Sort

O(N * log10(max Val))

27
New cards

Average-case time complexity for Radix Sort

O(N * log10(max Val))

28
New cards

Is Radix Sort a comparison sort?

No

29
New cards

Is Radix Sort an in-place sort?

No

30
New cards

Is Radix Sort a stable sort?

Yes

31
New cards

Best-case time complexity for Merge Sort

O(NlogN)

32
New cards

Worst-case time complexity for Merge Sort

O(NlogN)

33
New cards

Average-case time complexity for Merge Sort

O(NlogN)

34
New cards

Is Merge Sort a comparison sort?

Yes

35
New cards

Is Merge Sort an in-place sort?

No

36
New cards

Is Merge Sort a stable sort?

Yes

37
New cards

Best-case time complexity for Quick Sort

O(NlogN)

38
New cards

Worst-case time complexity for Quick Sort

O(N^2)

39
New cards

Average-case time complexity for Quick Sort

O(NlogN)

40
New cards

Is Quick Sort a comparison sort?

Yes

41
New cards

Is Quick Sort an in-place sort?

Yes

42
New cards

Is Quick Sort a stable sort?

No

43
New cards

Full Binary Tree

A tree in which each node has 0 or 2 children

44
New cards

Complete Binary Tree

A binary tree in which every parent has exactly two children, except in the last row, which is filled left to right

45
New cards

BST Insertion - Best Case

Balanced BST with a height of O(logN)

46
New cards

BST Insertion - Worst Case

Degenerate BST with a height of O(N) Removes advantages of using a BST

47
New cards

put() (HashMap)

O(1) - Uses HashCode to insert

48
New cards

get() (HashMap)

O(1)

49
New cards

remove() (HashMap)

O(1)

50
New cards

put() (TreeMap)

O(log n) - inserts keys in sorted order

51
New cards

get() (TreeMap)

O(log n) - finds key in tree

52
New cards

remove() (TreeMap)

O(log n) - finds key in tree, removes

53
New cards

Red-Black Tree rules

1. Tree is a binary search tree
2. Every node is labeled red or black
3. The root of the tree is black
4. Red rule: If a node is red, it's children must be black
5. Path rule: Every path from a node to a null link must contain the same number of black nodes

54
New cards

Red-Black Tree Insertion

1. Insert a red node
2. When traversing down the tree for insertion, swap color of black nodes with two red children
3. Case 1: If the parent of the new node is black, then done!
Case 2: If the parent of the new node is red (breaks the red rule) then need to extra work to reinstate the rules of the red black tree Case 2A: if the new node is an outside node AND if the sibling of the parent is black (or doesn't exist), perform a rotation Case 2B: If the new node is an inside node AND if the sibling of the parent is black (or doesn't exist), perform a double rotation
If root becomes red just change it to black
Recolor everything so it passes the tests

55
New cards

Dense graph

contains a "large" number of edges - use an adjacency matrix

56
New cards

Sparse Graph

number of edges is "much less" than the maximum number of possible edges - use an adjacency list because storing a mostly 0s matrix is not space efficient

57
New cards

How to determine the "central" vertex

pick the vertex that is 1. Connected to the most vertices
2. Has the shortest average path to its connected vertices

58
New cards

Open addressing

probing

59
New cards

closed addressing

chaining

60
New cards

Load Factor

Number of elements divided by the number of buckets (N/B)

61
New cards

Remove a Heap

1. remove element at a given index (for priority queue, always remove highest priority element)
2. Move last element in the array to that index
3. If this smaller has a larger than either of its children, swap parent and the smaller child
4. Repeat 2 until heap property is satisfied or till no more children

62
New cards

Efficiency of adding a word to a trie given the word has N characters

O(N)