Exam 1-4 and Sets, Maps, Hash tables and Graphs for Data Structures 2025 with Hailey Fields

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

1/92

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.

93 Terms

1
New cards

Which statement is correct?

Every data structure has a specific algorithm to implement a certain operation

3 multiple choice options

2
New cards

Which of the following best describes the relationship between the list ADT and the array data structure?

An array is one of several data structures that can be used to implement the list ADT

3 multiple choice options

3
New cards

In a computational problem for finding the highest salary of an employee in a company, what is the input?

The list of employees' salaries

3 multiple choice options

4
New cards

Space complexity analysis helps in avoiding algorithms with _____.

high memory usage

3 multiple choice options

5
New cards

An algorithm's _____ runtime complexity is the scenario where the algorithm does the minimum possible number of operations.

best case

3 multiple choice options

6
New cards

Which is NOT a known characteristic of an NP-complete problem?

All NP-complete problems can be solved efficiently.

3 multiple choice options

7
New cards

ADTs allow programmers to _____.

focus on higher-level operations as per a program's needs

3 multiple choice options

8
New cards

The process of providing only the essentials and hiding the details is known as _____.

abstraction

3 multiple choice options

9
New cards

What is the difference between best case and worst case runtime complexity?

Best case: the scenario where the algorithm does the minimum possible number of operations

Worse case: the scenario where the algorithm does the maximum possible number of operations

3 multiple choice options

10
New cards

Which is an abstract data type (ADT)?

A list

3 multiple choice options

11
New cards

Which of the following statements best describes the relationship between data structures and algorithms?

An efficient algorithm is only as efficient as its choice of data structure

3 multiple choice options

12
New cards

An algorithm to determine the top five salespersons is most likely to utilize what other algorithm?

An algorithm to sort an array in descending order

3 multiple choice options

13
New cards

Which of the following statements is true with reference to searching algorithms?

Binary search starts from the center of a sorted list.

3 multiple choice options

14
New cards

The best case runtime complexity of an algorithm that searches an array of size N is _____.

O(1)

3 multiple choice options

15
New cards

Which of the following statements is true?

Linear search will compare all elements if the search key is not present.

3 multiple choice options

16
New cards

What is the worst-case runtime complexity of the binary search algorithm?

O(log n)

3 multiple choice options

17
New cards

Which is the BEST case scenario when the linear search algorithm searches an array for key 42?

42 is the array's first element

3 multiple choice options

18
New cards

Identify the correct sequence of performing a binary search.

1. Binary search first checks the middle element of the list.

2. If the search key is not found, the algorithm:

i. checks the left sublist if the search key is less than the middle element or

ii. checks the right sublist if the search key is greater than the middle element.

3 multiple choice options

19
New cards

An call is made to RecursiveBinarySearch with array = [0, 1, 1, 2, 4, 5, 8, 13, 17], key = 5, low = 0, and high = 8. What is the index of the middle element?

4

3 multiple choice options

20
New cards

An call is made to RecursiveBinarySearch with array = [0, 1, 1, 2, 3, 5, 8, 13, 17], key = 5, low = 0, and high = 8. What are the low and high argument values for the next call to RecursiveBinarySearch()?

low =5, high= 4

3 multiple choice options

21
New cards

The Big O notation for an algorithm with exactly 50 constant time operations is _____.

O(1)

3 multiple choice options

22
New cards

The lower bound of an algorithm's runtime complexity is _____.

<= best case

3 multiple choice options

23
New cards

Which of the following is an example of constant time O(1)?

accessing an element of an array

24
New cards

A recursive function calls _____.

itself

3 multiple choice options

25
New cards

The Big O notation of the runtime 7+12N+3N2 is _____.

O(n^2)

3 multiple choice options

26
New cards

The worst-case runtime of an algorithm is _____ number of steps taken to execute a program.

the max

3 multiple choice options

27
New cards

In a recursive function, the base case _____ the function.

terminates

3 multiple choice options

28
New cards

Which of the following is a constant time operation?

finding the sum of two numbers input by the user

3 multiple choice options

29
New cards

Quicksort's partitioning algorithm uses a low index and a high index. Partitioning is complete when _____.

the low index is greater than or equal to the high index

30
New cards

What is the merge sort algorithm's runtime?

O(Nlogn)

3 multiple choice options

31
New cards

Which is the BEST case runtime for the quicksort algorithm?

O(Nlogn)

3 multiple choice options

32
New cards

Which is the WORST case runtime for the quicksort algorithm?

O(n^2)

33
New cards

Complete the following to declare a type parameter.

template

T SomeFunction(T arg) {

... .. ...

}

typename

3 multiple choice options

34
New cards

Which is the correct syntax for defining a class's function outside the class declaration?

returnType MyClass::MyFunction() { ... }

3 multiple choice options

35
New cards

What property of a vector is changed when a vector's reserve function is called?

the capacity of the vector

3 multiple choice options

36
New cards

The vector class we defined had three member variables: elements, dataEnd, and memoryEnd. Which of the following statements can be used to return the capacity of the vector?

return memoryEnd - elements;

37
New cards

The vector class we defined had three member variables: elements, dataEnd, and memoryEnd. Which of the following statements should be used in the destructor?

delete[] elements;

3 multiple choice options

38
New cards

Suppose you have a program in which you use a vector to hold your data and you want to use a built-in function which takes an array parameter. Which of the following functions would be best to use in this situation to allow the built-in function to be called?

The vector's data function

39
New cards

What attribute of a vector is changed when a vector's resize function is called?

the size of vector

3 multiple choice options

40
New cards

Under what condition does calling a vector's push_back function cause additional memory to be reserved?

when the size equals the capacity

3 multiple choice options

41
New cards

The vector class we defined had three member variables: elements, dataEnd, and memoryEnd. Which of the following statements can be used to return the size of the vector?

return dataEnd - elements

3 multiple choice options

42
New cards

Which of the following correctly removes the first node from a singly-linked list that contains more than one node?

Node* temp = head;

head = head->next;

delete temp;

3 multiple choice options

43
New cards

What is the runtime complexity of the pop_back (remove from the end) operation in a singly-linked list?

O(n)

3 multiple choice options

44
New cards

The find function visits _____ when searching for 83 in the singly-linked list (80, 81, 82, 83).

all the nodes

3 multiple choice options

45
New cards

Which of the following pointers need to be updated to correctly insert a node at the end (push_back) of an empty singly-linked list?

the head pointer and tail pointer

3 multiple choice options

46
New cards

In a singly-linked list with 1 element, the tail pointer ____ and the next pointer of the head node ____.

points to the head node, is null

3 multiple choice options

47
New cards

Which of the following is an example of a linked list traversal operation?

printing the list

3 multiple choice options

48
New cards

Given the doubly-linked list animalList (Cat, Dog), which nodes will be the head and tail nodes after the following operations?

Insert node Bird after node Cat

Insert node Fish after node Dog

Remove node Cat from list

Remove node Fish from list

head = node Bird

Tail = node Dog

3 multiple choice options

49
New cards

The doubly-linked list append (push_back) operation changes the list's _____ if the list is empty and changes the list's _____ if the list is not empty.

head and tail, tail

3 multiple choice options

50
New cards

The doubly-linked list prepend (push_front) operation changes the list's _____ if the list is empty and changes the list's _____ if the list is not empty.

head and tail, head

3 multiple choice options

51
New cards

Given the doubly-linked list students (Tom, Sam), what will be the second node in the list after the following operations?

Node Hal is inserted after the tail

Node Pam is inserted after the head

Pam

3 multiple choice options

52
New cards

Which of the following pointers need to be updated to correctly insert a node at the end (push_back) of a non-empty doubly-linked list?

The next pointer of the tail nodeThe prev pointer of the node to insertThe tail pointer

3 multiple choice options

53
New cards

The find operation in a doubly-linked list has a worst case time complexity of _____.

O(N)

3 multiple choice options

54
New cards

Which function adds an element to the beginning of a std::list?

push_front()

3 multiple choice options

55
New cards

Which function adds an element to the back end of a std::list?

push_back()

3 multiple choice options

56
New cards

Which operation is valid for bidirectional iterators but not valid for forward iterators?

--

3 multiple choice options

57
New cards

Which of the following statement about the std::end function is true?

std::end returns an iterator to past-the-end element

3 multiple choice options

58
New cards

Which of the following containers can NOT be used in a call to the std::begin function?

stack

3 multiple choice options

59
New cards

Which of the following statements about using the operators ++, ==, and != with iterators and pointers is true?

Both pointers and iterators support all three operators (++, ==, and !=), with identical behavior across both types

3 multiple choice options

60
New cards

Which of the following iterator types satisfies the requirements of each other iterator type?

random-access

3 multiple choice options

61
New cards

Which of the following statements about using iterators to iterate over a std::list is true?

Bidirectional iterators can be used with std::list, allowing traversal both forward and backward

3 multiple choice options

62
New cards

Which of the following statements regarding the dereference operator (*) is true?

The dereference operator can be used with both pointers and iterators, allowing access to the value they point to or refer to

3 multiple choice options

63
New cards

Which of the following is an L-value?

an int variable named x

3 multiple choice options

64
New cards

Which of the following statements about input iterators and output iterators is true?

Input iterators are used for reading data from a container, while output iterators are used for writing data to a container

3 multiple choice options

65
New cards

Which of the following containers can be sorted by calling the std::sort function?

vector

66
New cards

Which stack functions can safely be called on an empty stack?

size, push

3 multiple choice options

67
New cards

What is the result of calling the pop method on a stack?

It removes the top element from the stack

3 multiple choice options

68
New cards

Which statement declares a C++ stack with integer items named numberStack?

stack numberStack;

3 multiple choice options

69
New cards

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

1) Push Hal

2) Push Raj

3) Pop

4) Pop

Tom, Sam (top is Tom)

3 multiple choice options

70
New cards

Which C++ function performs the peek operation on a stack?

top

3 multiple choice options

71
New cards

Which C++ function performs the peek operation on a queue?

front

3 multiple choice options

72
New cards

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

after 48

3 multiple choice options

73
New cards

Which of the following structures use a std::deque as the default underlying container?

std::stack

std::queue

3 multiple choice options

74
New cards

Which of the following statements is NOT true about C++ std::queue?

the pop function can be called on a queue at any time

3 multiple choice options

75
New cards

Does an error exist in the code below?

queue items;

items.push("Hello");

cout << items.front() << endl;

No. The code outputs "Hello".

3 multiple choice options

76
New cards

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

the front

3 multiple choice options

77
New cards

Which of the following operations are NOT efficient for a deque to perform?

insert/remove in middle

3 multiple choice options

78
New cards

Given the queue myData 12, 24, 36 (front is 12), what is the result of the following operations?

myData.pop();

myData.pop();

myData.pop();

cout << myData.size();

0

3 multiple choice options

79
New cards

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

myData.push(72);

myData.pop();

24, 48, 72

3 multiple choice options

80
New cards

Which abstract data type best fits the following verse?

"So the last will be first, and the first last." Matthew 20:16

stack

3 multiple choice options

81
New cards

What is a leaf node?

a node with no children

3 multiple choice options

82
New cards

What is the minimum height of a binary tree containing n nodes?

O(log n)

3 multiple choice options

83
New cards

Which of the following best describes a max-heap?

A complete binary tree in which every node's key is greater than or equal to the node's children's keys

3 multiple choice options

84
New cards

What is the maximum height of a binary tree containing n nodes?

O(n)

3 multiple choice options

85
New cards

What happens when a leaf node is removed?

The parent's left or right child node becomes null

3 multiple choice options

86
New cards

When is a new node inserted as the left child?

When the new node's key is less than the current node and the current node's left child is null

3 multiple choice options

87
New cards

Which of the following rules does a valid BST follow?

Left subtree keys ≤ node's keys

3 multiple choice options

88
New cards

What is the height of a BST built by inserting nodes in the order 12, 24, 23, 48, 47?

3

3 multiple choice options

89
New cards

What is the height of a BST built by inserting nodes in the order 20, 10, 30?

1

3 multiple choice options

90
New cards

Which is the worst-case height of AVL?

Less than or equal to 1.5 times compared to minimum binary tree height

3 multiple choice options

91
New cards

What are the worst-case time complexities of the insert, remove, and search operations for BSTs?

insert: O(n)

remove: O(n)

search: O(n)

3 multiple choice options

92
New cards

Which of the following statements is true about a perfect BST?

A perfect BST is a valid AVL tree and also a valid Red Black tree (given all nodes are colored black)

3 multiple choice options

93
New cards

What are the worst-case time complexities of the insert, remove, and search operations for AVL and Red Black trees?

insert: O(log n)

remove: O(log n)

search: O(log n)

3 multiple choice options