Final Exam Cramming Up (Chapter 11-15) Flashcards
(57 cards)
Which is the complexity of a bubble sort algorithm?
O(n2)
Given the following list, which is the first step of a insertion sort?
{6, 2, 4, 3}
{2, 6, 4, 3}
Given the following list, what is the number of passes to sort the elements using an insertion sort?
14, 12, 16, 6, 3, 10
5
Given the following list, which is the first step of a selection sort?
{6, 4, 3, 1}
{1, 4, 3, 6}
Which is the complexity of a selection sort algorithm?
O(n^2)
Given the following list, which is not one of the possible “halves”?
{ 13, 32, 26, 9, 34, 18, 41, 43 }
18, 41
Which is the complexity of a merge sort algorithm?
O(n log n)
Which sorting algorithms has the lowest worst-case complexity?
Merge Sort
Given the following list, the best candidate of “pivot” of a quick sort is __.
{ 2, 5, 1, 7, 4, 9, 12, 11, 10 }
4
Given the following array, what will be the array after the first pass of bubble sort?
{5, 2, 8, 1, 9}
{2, 5, 1, 8, 9}
The following is a sample code of __ sorting.
void Sort(int arr[], int n)
{
bool swapped;
for (int i = 0; i < n - 1; i++)
{
swapped = false;
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
swap(arr[j], arr[j + 1]);
swapped = true;
}
}
if (!swapped)
break;
}
}
Bubble
The following is a sample code of __ sorting.
void Sort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
int min_idx = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
swap(arr[min_idx], arr[i]);
}
}
Selections
Given the following array, what will be the array after the first pass of selection sort?
{5, 2, 8, 1, 9}
{1, 2, 8, 5, 9}
Given the following array, what will be the array after the first pass of bubble sort?
{64, 34, 25, 12, 22, 11, 90}
{34, 25, 12, 22, 11, 64, 90}
How many maximum children can a node of a tree structure have?
No limit.
Which statement is not true about a tree structure?
The “root” node is the bottom-most node in a tree structure.
The operation of processing or visiting each element in the list is called ____.
Traversal
How many maximum children can a node of a “binary tree” have?
2
Given the following tree, which is not a leaf?
8 / | \ 5 7 6 / \ 4 3
5
The following “show()” function is an implementation of the __ traversal of a binary tree structure.
void show(bstnode *node)
{
if (node != NULL)
{
show(node->left);
cout «_space;node->data «_space;” “;
show(node->right);
}
in-order
The following “show()” function is an implementation of the __ traversal of a binary tree structure.
void show(bstnode *node)
{
if (node != NULL)
{
show(node->left);
show(node->right);
cout «_space;node->data «_space;” “;
}
}
post-order
The following is a __ tree.
50 / \ 30 70 / \ / \ 20 40 60 80
binary search
If 26 is inserted to the following binary search tree, what will tree turn out to be?
0 / \ 40 70 / / \ 25 65 80
0
/ \
40 70
/ / \
25 65 80
\
26
What is the defining characteristic of a Binary Search Tree (BST)?
The left child is always smaller than the parent, and the right child is always larger.