Final Flashcards

1
Q

You can directly access the nth node of a linked list. T or F?

A

False

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

The dereference operator * accesses the variable to which a pointer points. T or F?

A

True

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

A linked list is not fixed in size. T or F?

A

True

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

When you return a dynamic array to the heap, you must include the number of elements in the array. T or F?

A

False

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

Arcade Object Creation

A

Arcade myArc(“Games Ablaze”, 5);

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

In a queue, a dequeue operation always removes _____ element.

A

the front

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

Declare a vector [class=Student, studList]

A

vector<Student> studList;</Student>

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

Which of the following statements allocates memory in the heap?

A

a = new int;

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

Given a stack myData: Tom, Sam (top is Tom), what is the output after the following operations?

Push(myData, Hal)

Pop(myData)

Pop(myData)

print(Peek(myData))

A

Sam

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

Linear search will compare all elements if the search key is not present. T or F?

A

True

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

What is the return type for constructors?

A

None

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

include <iostream></iostream>

Which XXX condition generates the following output?Not found

#include <string>
#include <vector>
using namespace std;</vector></string>

int BinarySearch(vector<int> numberList, int element, int lowVal, int highVal) {
int midVal;
if (XXX) {
midVal = (highVal + lowVal) / 2;
if (numberList.at(midVal) == element) {
return midVal;
}
else if (numberList.at(midVal) > element) {
return BinarySearch(numberList, element, lowVal, midVal - 1);
}
else {
return BinarySearch(numberList, element, midVal + 1, highVal);
}
}
else {
return -1;
}
}</int>

int main() {
vector<int> numberList(0);
int element = 20;
int matchPos;
for (int i = 0; i <= 10; ++i) {
numberList.push_back(i);
}
matchPos = BinarySearch(numberList, element, 0, numberList.size() - 1);
if (matchPos >= 0) {
cout << "Found at position " << matchPos << "." << endl;
}
else {
cout << "Not found. " << endl;
}
return 0;
}</int>

A

lowVal <= highVal

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

Which XXX completes the binary search algorithm?

BinarySearch(numbers, numbersSize, key) {
mid = 0
low = 0
high = numbersSize - 1

XXX {
mid = (high + low) / 2
if (numbers[mid] < key) {
low = mid + 1
}
else if (numbers[mid] > key) {
high = mid - 1
}
else {
return mid
}
}

return -1
}

A

while (high >= low)

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

Which of the following is true for overloading a class constructor?

A

The parameter types of the constructors should be different.

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

Given the queue myData 12, 24, 48 (front is 12), what will be the queue contents after the following operations?

Enqueue(myData, 72)

Dequeue(myData)

A

24, 48, 72

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

Heap is a region in program memory where _____.

A

the “new” operator allocates memory

17
Q

Which of the following statements is true about a class’ member function definition?

A

A function definition provides a class name, return type, arguments, and the function’s statements.

18
Q

Which of the following declaration is an accessor?

A

void GetName() const;

19
Q

Given the queue myData 12, 24, 48 (front is 12), where will the new item 72 be enqueued?
Correct!

A

After 48

20
Q

Identify the error in the following algorithm for traversing a linked list.

ListTraverse(list) {
curNode = list⇢head
while (curNode is not null) {
Print curNode’s data
curNode = list⇢head⇢next
}
}

A

The statement curNode = list⇢head⇢next should be curNode = curNode⇢next.

21
Q

Which of the following statements is true about public member functions of a class?

A

A class user can call the functions to operate on the object.

22
Q

Which statement properly frees the dynamically allocated array below?

Musketeer* musketeers = new Musketeer[8];

A

delete [] musketeers;

23
Q

The member access operator (->) is always a non-static member function. T or F?

A

True

24
Q

A member function can access the private data members, but class users cannot. T or F?

A

True

25
Q

A linked list’s head node stores _____ in the list.

A

a pointer to the first item node

26
Q

A memory leak occurs when a program allocates memory but loses the ability to access the allocated memory. T or F?

A

True

27
Q

a = [20, 10];
cout &laquo_space;“Line 3: “ &laquo_space;*(a+1) &laquo_space;endl;

A

10

28
Q

a = [20, 10];
cout &laquo_space;“Line 4: “ &laquo_space;*a+1 &laquo_space;endl;

A

21

29
Q

double primes[] = {2, 3, 5, 7, 11, 13, 17, 19};
*primes =

A

2

30
Q

double primes[] = {2, 3, 5, 7, 11, 13, 17, 19};
*primes+5 =

A

7

31
Q

double primes[] = {2, 3, 5, 7, 11, 13, 17, 19};
*(primes+5) =

A

7