compsci quiz

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

The following statement ________.

*num3 = *val;

stores the value of the variable pointed to by val into the variable pointed to by num3

2
New cards

Consider the following statements:
int *s;
int m;
int j;
j = 25;
s = &j;
m = j;


After these statements, which of the following statements will change the value of j to 88?

*s = 88;

3
New cards

Use the delete operator only on pointers that were

created with the new operator in dynamic memory

4
New cards

Which of the following statements is NOT valid C++ code?

All of these are invalid

int ptr = int *num1;

 

int ptr = &num1;

 

float num1 = &ptr2;

5
New cards

void calc( int* r)
{
   * r += 2;
}

int main( )
{
    int *a = new int(5);
   calc( a );
   cout << *
a;
}

What is the output of *a?

 

7

6
New cards

A pointer variable stores a(n) ___________.

address

7
New cards

The amount of memory used by an array depends on the array's data type and the number of elements in the array.

True

8
New cards

In C++, the name of an array is interpreted as

the address of the first element

9
New cards

What will the following code display?

int numbers[] = {99, 87, 66, 55, 101};
for (int i = 1; i < 4; i++)
    cout << numbers[i] << "  ";

 

87 66 55

10
New cards

Consider the following code segment:

int p = 9, q =  8;
int ptr1 = &p;
int ptr2 = &q;
ptr1 = ptr2;

Which of the following figures correctly illustrates the memory of these variables? 

knowt flashcard image
11
New cards

Consider the following code segment:

int p = 9, q =  8;
int ptr1 = &p;
int ptr2 = &q;
*ptr1 = *ptr2;

Which of the following figures correctly illustrates the memory of these variables? 

knowt flashcard image
12
New cards

What is the constructor that takes no parameters?

default constructor

13
New cards

It is often a good idea to specify the data members as public to allow the client program to access the data member of a class.

False

14
New cards

A class may contain multiple constructors if

They have distinguishable argument lists

15
New cards

Which of the following creates an object of the "Time" class, and initialize it using a constructor that takes three parameters?

Time t(9, 40, 'A');

16
New cards

When C++ sees a ∆ b, where a is ClassName object and b is <Type> object, and ∆ is overloaded using the member function (internal) method.  a ∆ b is equivalent to call.

a.operator∆(b)

17
New cards

Which of the following operators cannot be overloaded?

. :: #

18
New cards

When we define and implement operator overloading in C++:

It may or may not be a class member function

19
New cards

Which operator overloading declaration is "internal"?

bool Time::operator<(const Time & t)

20
New cards

To implement an overloaded binary operator for a class with an external function, two function parameters are required.

True

21
New cards

Insertion to the beginning of an array-based implementation list is generally slower than insertion to its end.

True

22
New cards

Which of the following function is the copy constructor for List ADT

 

List::List(const List & origList)

23
New cards

C++ compiler does not provide any default copy constructor and assignment operator.

False

24
New cards

The assignment operator for a class must not be a function member.

False

25
New cards

When an object's lifetime is over, the object's _____________ is called automatically

destructor

26
New cards

the next field of the last node in a linked list

holds a null pointer

27
New cards

What are the advantages of using the linked list?

Insert new item without shifting

Can expand/contract as necessary

Delete existing item without shifting

28
New cards

Nodes in a linked list are stored in contiguous memory.

False

29
New cards

What is the operation of the following statements for a linked list?

Node * temp = head;
head = new node;
head->data = 25;
head->next = temp;

insert a node to the start of the linked list

30
New cards

A linked list is a series of connected

nodes

31
New cards

What value does function mystery return when called with a value of number = 4?

int mystery( int number )
{
  if (number == 0)
     return 1;

  else
    return ( number * mystery( number – 1 ) );

}

24

32
New cards

When computing Fibonacci numbers, the standard recursive algorithm (based on the definition of the Fibonacci number) is less efficient than iterative algorithms.

True

33
New cards

Consider the following function:

int Func(int x, int y) {

if (x == y) {

return 0;

}

else if (x > y) {

return Func(x - 1, y) + 1;

}

else {

return Func(x, y - 1) + 1;

}

}

What will be the return value of a function call to Func(5,20)? _________

15

34
New cards

To solve a problem recursively, you must identify at least one case in which the problem can be solved without further calling itself.

True

35
New cards

Consider the following function:

void test_a(int n)
{
  cout << n << " ";
  if (n > 0)
    test_a( n - 2 );
}

What is printed by the call test_a(4)?

420

36
New cards

How many times will the following function call itself if 5 is passed as the argument?
void showMessage(int n)

{

if (n>0){

cout << “good day!” << endl;

showMessage(n-1);

}

}

5

37
New cards

how many times will the following function call itself if 5 is passed as the argument?
void showMessage(int n)
{

if (n>0){

cout << “good day!” << endl;

showMessage(n-1);

}

}

An infinite number of times

38
New cards

What is the height of an empty tree?

-1

39
New cards
<p><span>Which of the following is correct about the tree shown below:</span></p>

Which of the following is correct about the tree shown below:

It is NOT a binary search tree because we can find a node whose data is smaller than some node in its left sub-tree.

40
New cards

To list all the nodes in a binary search tree in increasing order, what kind of traversal should be used?

inorder

41
New cards

Consider writing a recursive function that computes the sum of the data field of all nodes in a binary tree. The function’s prototype is:

        Sum(BinNode * root);

Which of the following is the correct recursive case for this function?

return Sum(root->left) + Sum(root->right) + root->data;

42
New cards

Storing data using a binary search tree uses less space than using a linked list.

False

43
New cards
<p><span>Consider the following binary search tree.</span></p><p><span>Consider inserting a new data item 12 into this BST. Then the new node should become the _________ (left child or right child) of the node ______ (write the data value of the node who would become the parent of the inserted node).</span></p>

Consider the following binary search tree.

Consider inserting a new data item 12 into this BST. Then the new node should become the _________ (left child or right child) of the node ______ (write the data value of the node who would become the parent of the inserted node).

right child , 9

44
New cards
<p>T<span>he preorder traversal of the tree shown below should be</span></p>

The preorder traversal of the tree shown below should be

 

11 5 3 8 18 14 26 22 19 30

45
New cards

Quicksort performs better for a sorted list than for a random list.

False

46
New cards

Quicksort on average has computing time

 

O(n log n)

47
New cards

insertion sort on average has computing time

 

O(n2)

48
New cards

Which of the following formulas in big-O notation best represents the expression n3 + log(n) + 100n2 + 9020?

 

O(n3)

49
New cards

What is the running time of the following code segment?

 

int s = 0;
for(int i=0; i<2n; i++){
    s += i*i;
}

O(n)

50
New cards

What is the running time of the following code segment?

 

int s = 0;
for(int i=0; i<n; i++){
    for(int j=0; j<n*n; j++){
        s += 1;
        if(j >= n)
        {
            break;
        }    
    }
}

O(n^2)