Final Exam Cramming Up (Chapter 11-15) Flashcards

(57 cards)

1
Q

Which is the complexity of a bubble sort algorithm?

A

O(n2)

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

Given the following list, which is the first step of a insertion sort?

{6, 2, 4, 3}

A

{2, 6, 4, 3}

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

Given the following list, what is the number of passes to sort the elements using an insertion sort?

14, 12, 16, 6, 3, 10

A

5

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

Given the following list, which is the first step of a selection sort?

{6, 4, 3, 1}

A

{1, 4, 3, 6}

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

Which is the complexity of a selection sort algorithm?

A

O(n^2)

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

Given the following list, which is not one of the possible “halves”?

{ 13, 32, 26, 9, 34, 18, 41, 43 }

A

18, 41

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

Which is the complexity of a merge sort algorithm?

A

O(n log n)

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

Which sorting algorithms has the lowest worst-case complexity?

A

Merge Sort

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

Given the following list, the best candidate of “pivot” of a quick sort is __.

{ 2, 5, 1, 7, 4, 9, 12, 11, 10 }

A

4

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

Given the following array, what will be the array after the first pass of bubble sort?

{5, 2, 8, 1, 9}

A

{2, 5, 1, 8, 9}

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

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;
}
}

A

Bubble

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

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]);
}
}

A

Selections

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

Given the following array, what will be the array after the first pass of selection sort?

{5, 2, 8, 1, 9}

A

{1, 2, 8, 5, 9}

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

Given the following array, what will be the array after the first pass of bubble sort?

{64, 34, 25, 12, 22, 11, 90}

A

{34, 25, 12, 22, 11, 64, 90}

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

How many maximum children can a node of a tree structure have?

A

No limit.

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

Which statement is not true about a tree structure?

A

The “root” node is the bottom-most node in a tree structure.

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

The operation of processing or visiting each element in the list is called ____.

A

Traversal

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

How many maximum children can a node of a “binary tree” have?

A

2

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

Given the following tree, which is not a leaf?

 8    / | \   5  7  6  / \ 4  3
A

5

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

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 &laquo_space;node->data &laquo_space;” “;
show(node->right);
}

A

in-order

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

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 &laquo_space;node->data &laquo_space;” “;
}
}

A

post-order

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

The following is a __ tree.

 50     /    \    30      70   /  \    /  \  20   40  60   80
A

binary search

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

If 26 is inserted to the following binary search tree, what will tree turn out to be?

 0    /   \   40   70  /     / \ 25    65 80
A

0
/ \
40 70
/ / \
25 65 80
\
26

24
Q

What is the defining characteristic of a Binary Search Tree (BST)?

A

The left child is always smaller than the parent, and the right child is always larger.

25
What is the maximum number of children a node can have in a binary tree?
2
26
Which traversal method visits the root node first, followed by the left subtree, and then the right subtree?
Preorder
27
Which of the following is NOT a common application of trees?
Sorting algorithms
28
Given the following values, what would be the root of the BST created from these values? 50, 30, 70, 20, 40, 60, 80
50
29
Given an undirected graph G with V vertices and E edges, the sum of the degrees of all vertices is __.
2e
30
__ is a sequence of vertices that connect two nodes in a graph.
Path
31
The number of edges in a “complete directed graph” with 12 vertices is __.
12*11
32
Given the following matrix, which statement is correct? \ A B C D E A 0 1 0 0 1 B 1 0 0 1 0 C 0 0 0 1 1 D 0 1 1 0 1 E 1 0 1 1 0
There is an edge between node C and node D.
33
Given the following matrix, which edge has a value of 1 with "edges" being an array of all edges in a graph? i\j 0 1 2 3 4 0 0 1 0 0 1 1 1 0 0 1 0 2 0 0 0 1 1 3 0 1 1 0 1 4 1 0 1 1 0
edges[1][3]
34
In C++, when a pointer will point to an array of pointers, the pointer must be declared with the __ sign.
**
35
Which is the best candidate for being a data structure of a "weighted" directed graph?
struct node { int data; int cost; node* next; }
36
Assuming "arrNode" is an array, which can deallocate it?
delete[] arrNode;
37
Given the following that defines an array of "edge" type which is a structure for a directed graph, how many nodes are in the graph? edge edges[] = { {0, 1}, {0, 3}, {1, 2}, {1, 4}, {2, 3} };
5
38
Given the following code in which "graph" is a structure for a "weighted" directed graph, which statement is true? graph edges[] = { {A,B,2}, {A,C,4}, {B,E,3}, {C,E,2}, {D,B,4}, {E,D,3} };
The cost between node B and E is 3.
39
A graph is a non-linear data structure consisting of __.
nodes and edges
40
Which of the following is an example of common graph representation?
Graphical matrix
41
In an adjacency matrix representation of a graph, a value of 1 at index (i, j) indicates __.
There is an edge from vertex i to vertex j
42
What is the fundamental difference between a directed and undirected graph?
The direction of edges in an undirected graph is bidirectional.
43
In an adjacency matrix, what does a value of 0 at position (i, j) indicate?
There is no edge between vertices i and j
44
In a hash table of size 13, which index positions would 29 and 135 be mapped to?
3, 5
45
Given the following values and the hash function, h(x) = x%10, which of the following statements are true? 4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199
9679, 1989, 4199 hash to the same key
46
Given the following values and a hash table of length 10 uses a hash function, h(k)=k%10, which keys are not in use? 42, 23, 34, 57, 46, 35
0, 1, 8, 9
47
Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 1023?
h(i) = i % 10
48
__ describes the situation that several values are hashed to the same key in the hash table.
Collision
49
What is a hash function? It is function that __.
Computes the key for a value in the array
50
A __ is a general-purpose data structure for storing a group of objects. A dictionary has a set of keys and each key has a single associated value.
dictionary
51
Which is possible a hash function used by a linear probing (or open addressing) algorithm to find the next available slot?
h(x) = (x + i) % size
52
Given the following array of values to be inserted into a hash table that holds exactly 11 values. Which of the following best demonstrates the contents of the hash table after all the keys have been inserted using linear probing? 113, 117, 97, 100, 114, 108, 116, 105, 99
99, 100, __, 113, 114, __, 116, 117, 105, 97, 108
53
What is the term for when two different keys produce the same hash value?
Collision
54
What is a hash function?
A function that maps keys to integer values.
55
Given the following code, which function is the hash function? h1(int sz) { size = sz; } int h2(int key) { return key % size; } void h3(int key, int value) { int index = h2(key); } int h4(int key) { int index = h2(key); } void h5(int value) { cout << value; }
h2
56
Which of the following statement best describes the following code? int hash(int key, int size) { return key % size; }
It divides the key by a prime number slightly larger than the hash table size and uses the remainder as the index.
57
Hash values are a powerful tool that can be used to solve a variety of problems in computer science. Which is not an example of real-world use case?
Linear Search