Final Exam Flashcards

1
Q
#include 
    using namespace std;
    template
    type Max(type Var1, type Var2)
    {
        if (Var1 > Var2)
            return Var1;
        else
            return Var2;
    }
    int main()
    {
        int p;
        p = Max(100, 200);
        cout << p << endl;
        return 0;
    }
A

200

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

Which of the following correctly indicates templates?

A

template

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
#include 
    using namespace std;
    template 
    void loopIt(T x)
    {
        int count = 3;
        T val[count];
        for (int ii=0; ii < count; ii++)
        {
            val[ii] = x++;
            cout <<  val[ii] << endl;
        }
    };
    int main()
    {
        float xx = 2.1;
        loopIt(xx);
    }
A
  1. 1
  2. 1
  3. 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
Which is true about template functions:
One will work with many different types
Duplicate code is increased
Takes longer to execute
None
A

One will work with many different types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
#include 
    using namespace std;
    template 
    class Test
    {
        public:
        Test()
        {
        };
        ~Test()
        {
        };
        type Funct1(type Var1)
        {
            return Var1;
        }
        type Funct2(type Var2)
        {
            return Var2;
        }
    };
    int main()
    {
        Test Var1;
        Test Var2;
        cout << Var1.Funct1(200) << endl;
        cout << Var2.Funct2(3.123) << endl;
        return 0;
    }
A

200

3.123

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

A generic data type is one in which the types of the items being manipulated are defined, but the operations are not. (T or F)

A

False

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

Assume that there is a BinaryTreeNode class and we are prototyping the insertion operator in the in the header file for the BinaryTreeNode.

The following prototype compiles without warning or error assuming that the method is appropriately implemented elsewhere.

friend ostream& operator

A

False

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

What is the output of this program?

    #include 
    using namespace std;
    template
    class TestVirt
    {
        public:
        virtual type TestFunct(type Var1)
        {
            return Var1 * 2;
        }
    };
    int main()
    {
        TestVirt Var1;
        cout << Var1.TestFunct(100) << endl;
        return 0;
    }
A

200

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
void fun2(int n) 
{ 
  if(n == 0) 
    return; 

fun2(n / 2);
cout &laquo_space;n % 2;
}
Assume we call it as follows:

fun2(4);

A

100

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

When crafting a recursive method, which of the following is NOT required?

  • Recursive call
  • Parameter to recursive call that heads toward base case
  • Multiple base cases (e.g for 0 and 1)
  • Single base case
A

Multiple base cases

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

Assume we have the following function defined:

#define LIMIT 20
void fun2(int n) 
{ 
  if (n <= 0) 
    return; 
  if (n > LIMIT) 
    return; 
  cout << n << " ";
  fun2(2 * n); 
  cout << n << " ";
}
Assume we call it in the following way:

fun2(2);
What is displayed?

A

2 4 8 16 16 8 4 2

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

Assume we have the following function defined:

int fun1(int x, int y)  
{ 
  if(x == 0) 
    return y; 
  else
    return fun1(x - 1,  x + y); 
} 
Assume that we call it as follows:

cout &laquo_space;fun1(3, 2);

A

8

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

Assume that we are implementing a traditional Binary Search Tree without balancing. What is the worst-case efficiency for the insert method?

A

O(N)

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

A/n ___________________ is a sequence of edges from one node in a binary tree to one of its descendants.

A

path

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

Assume the following values have been inserted into a binary search tree in the following order:

15 7 9 21 44 30 33 29 10 1 17

What is the height of the tree?

A

4

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

Assume the following items are inserted into a binary search tree in the order shown.

15 7 9 21 44 30 33 29 10 1 17

Which value is the inorder successor of 15?

A

17

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

Assume the following values have been inserted into a binary search tree in the order shown.

                    15  7  9  21  44  30  33  29  10  1  17

Assume that the value 3 is then inserted, which node is the parent of 3?

A

1

18
Q

The algorithmic complexity of the search method for binary search tree is

A

O(logN)

19
Q

When using the AVL strategy to balance a binary tree, what property of the node’s children is used to determine whether the node is considered balanced?

A

height

20
Q

Assume the following values are inserted into an AVL tree in this order.

                 15  7  9  21  44  30  33  29  10  1  17

After which value’s insertion will the tree be rebalanced for the first time?

A

9

21
Q

What is the efficiency of an AVL tree’s search function?

A

O(LogN)

22
Q

Assume the following values are inserted into an AVL tree in this order.

                 15  7  9  21  44  30  33  29  10  1  17

After which value’s insertion will the tree be rebalanced for the second time?

A

44

23
Q

Heaps are often used to represent what other data structure because of their efficiency?

A

Priority Queue

24
Q

Heaps are “totally ordered” datasets like binary trees (T or F)

A

false

25
Q

Assume the following values are inserted into a heap such that the “lowest” value has the “highest” priority.

15 7 9 21 44 30 33 29 10 1 17

Which value is the right child of 9?

A

33

26
Q

In a Binary Heap represented by an array indexed starting at 1 (i.e. the first item in the heap is at location 1). For the item in location 15, what is the location of its parent?

A

7

27
Q

In a Binary Heap represented by an array indexed starting at 1 (i.e. the first item in the heap is at location 1). For the item in location 15, what is the location of its left child?

A

30

28
Q

A/n ____________________ connected graph is a directed graph where the underlying undirected graph is connected but the directed graph is not.

A

weakly

29
Q

When using an adjacency matrix to represent the edges in a directed graph, the edges are mirrored across the “axis of symmetry” (diagonal). (T or F)

A

False

30
Q

In a graph, a simple path may contain duplicate vertices (nodes) but not duplicate edges.

A

false

31
Q

In a graph, the length of a path is defined by the number of vertices (nodes) in the path. (T or F)

A

False

32
Q

Adjacency matrices can be used to represent weighted graphs but cannot be multiplied to determine path lengths. (T or F)

A

True

33
Q

In a complete graph, there exists a path from every vertex (or node) to every other vertex

A

True

34
Q

When using an adjacency matrix to represent the edges in a undirected graph, the edges are mirrored across the “axis of symmetry” (diagonal).

A

True

35
Q

In Djikstra’s algorithm, a/n ______________ must be used to store the collection of nodes that are yet to be expanded (usually called “to visit”).

A

Priority Queue

36
Q

Assume that we have a set of integers called myset. We want to display all the items in the set using an iterator, which of the following correctly creates an iterator into mySet and initializes it to the first item in the set?

A

set::iterator it = myset.begin();

37
Q

Sets are usually stored using which of the following data structures?

A

Binary Search Tree

38
Q

Sets represent a sorted collection of unique items.

A

True

39
Q

Insert and search operations for a Hash Table are both O(1). (T or F)

A

True

40
Q

When designing a hash function for a HashTable, what is the most important characteristic?

A

Collisions rarely occur until it is at least 1/2 full

41
Q

When a Hash Table is full, you should increase its size by 5 items at a time so that the amount of memory used is still O(N). (T or F)

A

False

42
Q

Which of the following statements correctly declares a map that uses a student’s identification number (like those used at UCCS) to look up their name?

A

map students;