Flashcards
CMPUT 175 final exam review
Cards in this deck (23)
- 1What are the best-case, worst-case, and average case running times of Bubble Sort?Best: O(n)
Worst: O(n^2)
Average: O(n^2) - 2What is the time complexity of the number of comparisons that take place in selection sort?O(n^2)
- 3What is the time complexity of the number of swaps that take place in selection sort?O(n)
- 4What are the best-case, worst-case, and average case time complexities of the number of comparisons made by insertion sort?Best: O(n) comparisons
Worst: O(n^2) comparisons
Average: O(n^2) comparisons - 5What are the best-case, worst-case, and average case time complexities of the number of swaps done by insertion sort?Best: O(1)
Worst: O(n^2)
Average: O(n^2) - 6What is the time complexity of merge sort?O(n log n)
- 7What are the best-case, worst-case, and average time complexities of quick sort?Best: O(n log n)
Worst: O(n^2)
Average: O(n log n) - 8What are the in-place sorting algorithms discussed in class?Merge sort, quick sort
- 9Consider the list [5, 8, 2, 3, 7, 6, 1] What would be the state of the list after the first pass of Quick Sort?[1, 2, 3, 5, 7, 6, 8]
- 10Consider the tree a / \ / \ b c d e / \ f g Give the preorder, inorder, and postorder traversal of the tree.Preorder: a b f g c d e
Inorder: f b g c d a e
Postorder: f g b c d e a - 11What is a binary search tree?A BST is a binary tree in which, for every node, the element in the node is >= the elements in the left subtree and <= the elements in the right subtree.
- 12In what order is a preorder traversal carried out?Root -> left -> right
- 13In what order is an inorder traversal carried out?Left -> root -> right
- 14In what order is a postorder traversal carried out?Left -> right -> root
- 15What are the fields used to initialize a binary search tree node?key, value, leftChild, rightChild, parent
- 16What are the methods in a binary search tree?put(self, key, value)
get(self, key)
remove(self, key)
getSize(self)
getRoot(self) - 17Say I want to delete a node that has two children. What do I need to do?1. Find a successor - largest key in left subtree or the smallest key in right subtree
2. Copy (swap) the key/value of the chosen successor to the current node, then recursively remove it. - 18Consider the list [2, 7, 5, 9, 3, 1, 4] What does the list look like after the first pass of selection sort?[1, 7, 5, 9, 3, 2, 4]
- 19Consider the list [3, 1, 6, 5, 2, 8, 7] What will the list look like after the first pass of bubble sort?[1, 3, 5, 4, 8, 2, 7]
- 20Consider the list [2, 7, 5, 7, 3, 1, 4] What will it look like after the first pass of insertion sort?[2, 5, 7, 3, 1, 4]
- 21Order these running times in ascending order in terms of their efficiency: n, log(n), 1, n^2, n log(n), n^3, 2^n1
log(n)
n
n log(n)
n^2
n^3
2^n - 22If I want to add a new node to the head (front) of a doubly-linked list, I would write: new_node.setPrevious(_____)None
- 23When inserting a new node into a doubly-linked list, I may need to update as many as __ links.4
Information
- Description
- Computer Science Flashcards on CMPUT 175 final exam review, created by Chuck Hanson on 11/04/2018.
- Created by
- Chuck Hanson
- Views
- 3
- Rating