CISC220 Midterm 1 Study Guide

0.0(0)
studied byStudied by 16 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/55

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.

56 Terms

1
New cards

IN C++ which of the following allows for direct modification of an argument’s value when passed to a function?

Call by reference

2
New cards

Nick is writing an implementation of the queue ADT. which of the following implementations would have the fastes time complexity for the enqueue and dequeue operations? Select all the apply

SLL and DLL

3
New cards

For insertion at the end of a list, which of the following list implementations is the most efficient

  • array

  • sll without last pointer

  • sll with last pointer

  • dll

  • sll with last pointer

  • dll

4
New cards

Which of the following datatypes are passed by pointer by default?

  • strings

  • objects

  • arrays

  • doubles

  • nothing is passed by pointer by default

arrays

5
New cards

Which of the followintg describes a memory leak?

  • when memory is allocated on the stack and not cleaned up afterward

  • when memory is allocated on he heap and not cleaned up afterward

  • when an excessive ammount of memory is allocated to a program and not used

  • when memory is allocated on the heap and the address is lost of overwritten before it can be deallocated

  • when pointers are mismanages such that the program tries to access memory that is not allocated to it

  • when memory is allocated on he heap and not cleaned up afterward

  • when memory is allocated on the heap and the address is lost of overwritten before it can be deallocated

6
New cards

For insertion at the beginning of a list, which of the following list implementations is the least efficient

  • array

  • sll w/o last pointer

  • sll with last pointer

  • dll

arrat

7
New cards

Removing an element from an array implementation of a list requires approximately 2n space

true

8
New cards

Pop can be done in O(1) time for linked list implementations

False

9
New cards

Provide the appropriate line of code to accomplish the task:
Create a string variable name on the stack with a value of Jake

string name = “Jake”;

10
New cards

Provide the appropriate line of code to accomplish the task:

create a double variable a on the heap

a = new double;

11
New cards

Provide the appropriate line of code to accomplish the task:

Set the address in a to hold a value of 8.3

*a = 8.3

12
New cards

Provide the appropriate line of code to accomplish the task:
Create a boolean arr of length 6 on the heap

bool *arr = new bool [6];

13
New cards

Provide the appropriate line of code to accomplish the task:
Create a pointer sPtr that points at name

String sPtr* = &name;

14
New cards

Provide the appropriate line of code to accomplish the task:
create a pointer sPtr2 that points at sPtr

string **sPtr2 = &sPtr;

15
New cards

Provide the appropriate line of code to accomplish the task:
create a pointer arrPtr that points at the inital index in arr

bool *arrPtr = arr;

16
New cards

Provide the appropriate line of code to accomplish the task:
move arrPtr to point at the next index in arr

arrPtr++;

17
New cards

Provide the appropriate line of code to accomplish the task:
print out the value of name using sPtr2

cout « **sptr2«endl;

18
New cards

Provide the appropriate line of code to accomplish the task:
deallocate a

delete a

19
New cards

Provide the appropriate line of code to accomplish the task:
Deallocate arr

delete [] arr;

20
New cards

Which list implementation is most efficient for the following operations (array, SLL without last pointer, SLL with last pointer, DLL)

Find kth element

array

21
New cards

Which list implementation is most efficient for the following operations (array, SLL without last pointer, SLL with last pointer, DLL)
Remove kth element

all???

22
New cards

Which list implementation is most efficient for the following operations (array, SLL without last pointer, SLL with last pointer, DLL)
Find x in the list

all

23
New cards

Which list implementation is most efficient for the following operations (array, SLL without last pointer, SLL with last pointer, DLL)
Insert at the beginning of the list

SLL and DLL

24
New cards

Which list implementation is most efficient for the following operations (array, SLL without last pointer, SLL with last pointer, DLL)
Insert at the end of the list

SLL wit last pointer, DLL

25
New cards

What is the time complexity to:
Remove last in a SLL without the last pointer

O(n)

26
New cards

What is the time complexity to:
Remove last in an array

O(n)

27
New cards

What is the time complexity to:
Insert at the beginning of a SLL

O(1)

28
New cards

What is the time complexity to:
Concatenate with two DLLs

O(1)

29
New cards

For insertion at the beginning of a list, which of the following list implementations is the least efficient?

  • array

  • sll without last pointer

  • sll with last pointer

  • dll

array

30
New cards

In a singly linked list, which of the following statements is true?

  • each node contains a reference to the previous node

  • each node contains a reference to the next node

  • each node contains a reference to the first node

  • it allows for constant-time random access to elements

  • it has a fixed size determines at initialization

  • each node contains a reference to the next node

31
New cards

Inserting an element into an array implementation of a list requires approximately 2n total space

True

32
New cards

According to list ADT, lists must have indices

True

33
New cards

Which of the following datatypes are passed by pointer by default?
- strings

  • objects

  • arrays

  • doubles

  • nothing is passed by pointer by default

arrays

34
New cards

According to the List ADT, implementations must support insertion at the kth position

True

35
New cards

In C++, which of the following allows for direct modification of an argument’s value when passed to a function?

  • call by value

  • call by pointer

  • call by reference

  • none of the above

call by reference

36
New cards

In a doubly linked list, which of the following operations has the highest time complexity (big ) notation?
- insertion at the beginning

  • deletion from the end

  • searchin for an element

  • reversing the list

Searching for an element

Reversing the list

37
New cards

What is the worst-case time complexity of Selection Sort?

a) O(log n)
b) O(n)
c) O(n log n)
d) O(n²)

O(n^2)

38
New cards

Which sorting algorithm inserts elements into an already sorted sublist?
a) Quick Sort
b) Bubble Sort
c) Selection Sort
d) Insertion Sort

d) Insertion Sort

39
New cards

True or False: In C++, arrays are passed into functions by value.

False

40
New cards

Which of the following correctly declares a pointer to an integer?
a) int x;
b) int x;
c) int x;
d) int &x;

int *x;

41
New cards

What does the '&' symbol represent in C++?
a) Value
b) Address
c) Dereference
d) Multiplication

Address

42
New cards

Which function call modifies the original variable in main?
a) void f(int x, int y)
b) void f(int x)
c) void f(int x*)
d) void f(int &x)

void f(int &x)

43
New cards

What is printed by this code?
int x = 3; void doublefn(int x) { x = x * 2; } doublefn(x); cout << x;
a) 3
b) Compilation error
c) 0
d) 6

3

44
New cards

Which of the following is NOT true about the heap?
a) Memory is manually managed
b) Variables persist beyond scope
c) Compiler controls allocation
d) Used with 'new' keyword

Compiler controls allocation

45
New cards

What does the delete keyword do in C++?
a) Removes a variable from scope
b) Deletes a file
c) Frees memory on the heap
d) Frees memory on the stack

Frees memory on the heap

46
New cards

True or False: A destructor is automatically called when an object goes out of scope.

True

47
New cards

Which of the following is a valid reason to use the heap?
a) To manage global constants
b) To speed up execution
c) To create objects that persist beyond function scope
d) To store temporary loop variables

To create objects that persist beyond function scope

48
New cards

Output?
ZooCreature *animal = new ZooCreature;

animal->firstname = "Gerald";

func1(animal);

cout << animal->firstname;

void func1(ZooCreature *pet) { pet->firstname = "April"; }

a) Compilation error
b) Undefined
c) April
d) Gerald

April

49
New cards

Which of the following is NOT a characteristic of a linked list?
a) Sequential access
b) Fixed size
c) Dynamic memory allocation
d) Allows duplicates

Fixed size

50
New cards

Which operation adds a node to the end of a linked list?
a) insert()
b) addFirst()
c) pop()
d) push()

push()

51
New cards

What does the next pointer in a linked list node do?
a) Points to next node
b) Stores data
c) Points to head of list
d) Points to previous node

Points to next node

52
New cards

True or False: Arrays allow random access while linked lists allow sequential access.
a) Only for doubly linked lists
b) False
c) True
d) Only for sorted arrays

True

53
New cards

Which sorting algorithm performs better on nearly sorted data?
a) Merge Sort
b) Bubble Sort
c) Insertion Sort
d) Selection Sort

Insertion Sort

54
New cards

What is the role of a destructor in a class with heap-allocated fields?
a) Print debug info
b) Initialize variables
c) Free heap memory
d) Allocate stack memory

Free heap memory

55
New cards

Which of the following correctly inserts a node at the kth position in a linked list?
a) kthNode->next = node;
b) node->next = kthNode->next; kthNode->next = node;
c) node = kthNode->next;
d) node->next = kthNode;

node->next = kthNode->next; kthNode->next = node;

56
New cards

Output?
MyClass t(2,"a");

for (int i = 0; i < 2; i++) { MyClass t2(3,"l"); }

MyClass t3(2,"m");

a) lalm
b) alm
c) mll
d) llam

alm