CS 251 Final Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the purpose of a private helper function in a class implementation?

**Private helpers help public functions Private helper functions are used internally within a class to support its functionality without exposing these implementation details externally. They help in breaking down complex tasks into simpler subtasks, enhancing code modularity, readability, and maintainability.

Identify the sequence of nodes that are visited to search for 150.

. 250, 200, 190

To determine if the tree in question is an AVL tree, we must check two conditions ?

1. The tree must be a binary search tree (BST). 2. The difference in heights between the left and right subtrees of any node in the tree must not exceed one (this is known as the balance factor).

Identify the depth of node Q.

2

What will recurFunction(2,3) return? int recurFunction(int x, int y) { if (y == 1){ return 0; } else { return x + recurFunction(x, y-1); } } a. 2 b. 4 c. 6 d. 8

4

What is the largest number of comparisons for searching the BST in the image?

4 comparison (depth)

What is the second node that is visited when searching for 7?

5

What happens when you access an array with an index that is out of range?

Accessing an array with an index that is out of range results in undefined behavior. In many programming environments, this could cause a segmentation fault or access violation, which may crash the program.

Where will a new node 5.5 be inserted? As 4's left child As 5's right child As 6's left child As 7's left child

As 5's right child

What is the Big O notation for a recursive function with a runtime complexity of T(N) = 5N + T(N−1)?

The Big O notation for the recursive function T(N) = 5N + T(N−1) is O(N^2). This is because it performs a linear (5N) operation for each recursive call, and there are N such calls, leading to a quadratic overall complexity.

A well balanced binary search tree of N nodes has an average height of what?

The average height of a well-balanced binary search tree with N nodes is O(log N). In such trees, the height grows logarithmically with the number of nodes, which ensures efficient operations like search, insert, and delete.

T/F A class cannot be implemented without a copy constructor.

False. A class can be implemented without a custom copy constructor. If no copy constructor is provided, the C++ compiler generates a default copy constructor. However, for classes that manage resources (like dynamic memory), a custom copy constructor is often necessary to avoid shallow copies.

T/F A Linked List data structure with only a head pointer is a more efficient implementation than one with both a head and a tail pointer.

False. A linked list with both head and tail pointers can be more efficient for certain operations, like appending elements to the end of the list, as it provides direct access to the tail of the list without needing to traverse the entire list.

T/F Traversal algorithms can only be used with binary search trees.

False. Traversal algorithms are not exclusive to binary search trees; they can be applied to other types of trees as well. Different types of trees, such as binary trees, n-ary trees, AVL trees, etc., can all be traversed using appropriate traversal algorithms.

T/F The queue ADT supports the removal of items from one end and the adding of items to the other end but the list ADT does not.

False. While it's true that the queue ADT allows removal from one end (front) and adding to the other end (rear), the list ADT can also support these operations. In fact, many list implementations (like doubly-linked lists) allow efficient insertion and deletion at both ends.

T/F Post-order traversal is ideal for making copies of a tree.

False. While post-order traversal can be used for various operations, it is not specifically ideal for making copies of a tree. Pre-order or level-order traversal is typically more suitable for this purpose as they maintain the original tree's structure more directly.

T/F Recursive search implementations for a linked list structure are the best choice.

False. While recursive search is a valid approach for linked lists, it is not always the best choice, especially for long lists. Recursive implementations can lead to stack overflow for very long lists, whereas iterative approaches are generally more memory-efficient.

What is the result for each of the following computations and why? int x = 5, y = 8, z = 10; cout << x / y * z << endl; // Result? cout << z / y * x << endl; // Result?

For x / y * z, since x and y are integers, x / y results in 0 (integer division truncates the fraction). Therefore, the expression evaluates to 0 * z, which is 0. For z / y * x, z / y results in 1 (since 10 / 8 = 1.25) but is truncated to 1). Therefore, the expression evaluates to 1 * x, which is 5.

What is the difference between a function's definition and declaration?

Function Declaration: A declaration tells the compiler about the existence of a function, including its name, return type, and parameters, but not its body. Example: int add(int, int); Function Definition: A definition provides the actual implementation of the function, including its body which defines what the function does. Example: int add(int a, int b) { return a + b; }

What is output? #include <iostream> using namespace std; class Greet { public: string g1; string g2; s tring g3; string g4; void Print() const; Greet() { g1 = "Hi! "; g3 = "Good morning! "; g4 = "Good night! "; } }; void Greet::Print() const { cout << g1 << g2 << g3;} int main() { Greet user1; user1.Print(); user1.g2 = "Hello!"; return 0; }

Hi! Good morning! bc g2 was empty

The code for class Hotel has been defined in two separate files Hotel.h, and Hotel.cpp. What goes in each file?

Hotel.h (Header File): Contains the declaration of the Hotel class, including class definition, member variables, function prototypes, and any necessary includes or forward declarations. Hotel.cpp (Implementation File): Contains the implementation of the Hotel class's member functions. This is where the actual code for the functions declared in the header file is written.

How many nodes were created in our default constructor in our LinkedList class?

In a typical LinkedList implementation, the default constructor does not create any nodes. It usually initializes the head of the list to nullptr, indicating that the list is initially empty.

userText is "March 17, 2034" What does userText.substr(0, 4) return?

Marc

Explain whether each segment is a constant time or not? while(x > y) x += 1;

NO, Not constant time. The time complexity depends on the values of x and y.

Explain whether each segment is a constant time or not? string s1, s2; ... s3 = concat(s1, s2);

No, copying the string is a linear opperation O(N)

Explain whether each segment is a constant time or not? for(i=0; i < length; i++) sum += i

No, depends on length probably O(N)

The space complexity of a BST insertion algorithm is _____.

The space complexity of a BST insertion algorithm is O(1) if we're talking about additional space required by the algorithm itself, as it does not require extra space proportional to the number of elements in the tree. However, if we're considering the space taken by the tree itself as it grows, then each insertion increases the total space by the size of one node.

What is the output if the input is "Tom - Sawyer"? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl << playerName; return 0;} a. Sawyer b. Tom - Sawyer c. Tom d. Tom Sawyer

Tom

T/F In a circularly linked list data structure, if you loop looking for the ending nullptr you will create an infinite loop.

True. In a circularly linked list, the last node points back to the first node, creating a loop. There is no node with a nullptr as the next node, so searching for nullptr to find the end will result in an infinite loop.

T/F Traversal algorithms cover all nodes in a tree.

True. Traversal algorithms in trees, such as in-order, pre-order, post-order (for binary trees), or level-order traversals, are designed to visit every node in the tree.

Which is an internal node?

X

Explain whether each segment is a constant time or not? x = array[option]; temp = array[option+1];

Yes, direct access by array index (same for vector)

What possible values can x % 10 evaluate to? (x is an integer). a. 0..9 b. 1..10 c. 0..10 d. 1..11

a. 0..9

#include <iostream> using namespace std; const double LB_PER_KG = 2.2; double KgsToLbs(double kilograms) { double pounds; pounds = kilograms * LB_PER_KG; return pounds;} int main() { double pounds; pounds = KgsToLbs(10); cout << pounds; return 0; } a. 22 b. No output: LB_PER_KG causes a compiler error due to being outside any function c. No output: Global variable declared as const causes compiler error d. No output: variable pounds declared into two functions causes compiler error

a. 22

Given a list (0, 1, 1, 2, 3, 5, 8, 13, 17), the binary search algorithm calls BinarySearch(list, 0, 8, 3). The arguments are BinarySearch(list, low, high, value). What is the index of the middle element? a. 4 b. 0 c. 2 d. 3

a. 4 Middle index=⌊low+high​/2⌋ Middle index=⌊0+8/2⌋ Middle index=⌊8/2⌋ Middle index=⌊4⌋ Middle index=4

What is the most accurate Big O notation for the following algorithm? ctr = 0 while (ctr < N) { myAge = ctr val = ctr + 1 while (val < N) { if (ageOfPeople[val] < ageOfPeople[myAge]) myAge = val ++val } tempList = ageOfPeople[ctr] ageOfPeople [ctr] = ageOfPeople[myAge] ageOfPeople [myAge] = tempList ++ctr} a. O(N^2) b. O(logN) c. O(N) d. O(1)

a. O(N^2)

What is the most accurate Big O notation for the following algorithm? ctr = 0 while (ctr < N) { myAge = ctr val = ctr + 1 while (val < N) { if (ageOfPeople[val] < ageOfPeople[myAge]) myAge = val ++val } tempList = ageOfPeople[ctr]; ageOfPeople [ctr] = ageOfPeople [myAge]; ageOfPeople [myAge] = tempList; ++ctr } a. O(N^2) b. O(logN) c. O(N) d. O(1)

a. O(N^2)

Consider that there is a class Team for soccer team members under Soccer namespace and another classTeamfor basketball team members under Basketball namespace. What is the correct syntax that will help the compiler identify the correct Team? a. Soccer::Team SoccerTeamMembers; Basketball::Team BasketballTeamMembers; b. Soccer: Team SoccerTeamMembers; Basketball: Team BasketballTeamMembers; c. Soccer , Basketball:: Team (SoccerTeamMembers, BasketballTeamMembers); d. Team (SoccerTeamMembers, BasketballTeamMembers);

a. Soccer::Team SoccerTeamMembers; Basketball::Team BasketballTeamMembers;

Identify the statement that will throw an error in the following code? class Student { public: void SetName(string studentName); void Display(); private: string name; char grade; int Grade();}; void Student::Display() { grade = Grade(); } int Student::Grade(){...} void SetName(string studentName) { name = studentName;} int main() { Student stu1; stu1.Display(); ... stu1.Grade(); } a.stu1.Grade(); b.stu1.Display(); c.int Student::Grade() d.void Student::Display() { grade = Grade();}

a. stu1.Grade(); private function trying to be accessed directly

Given sets A, B, and C, + indicates the intersection of the sets, and - indicates the difference between the sets (similar to the Project). A = {2, 3, 4, 5} B = {1, 4, 3, 7} C = {5, 1, 6, 4} Assuming operations are performed left to right, what set results from: A + B - C a. {2, 3} b. {} (an empty set) c. {2} d. {3} e. {4, 5}

a. {3}

Given the list Students: Tom, Harry, Sam, Kim, Tina, Hal, Sally. What is the value of the data stored in the node indicated by the tail pointer of the given list? a. Sally b. Tom c. Kim d. Hal

a.Sally

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? a. The middle error only b. The first error only c. All the errors d. The last error only

b. The first error only

Given the number list (2, 12, 8, 19, 5, 30), identify the merged list in merge sort after the completion of the second level. a. (2, 12, 8) and (5, 19, 30) b. (2, 8, 12) and (5, 19, 30) c. (2, 5, 8) and (12, 19, 30) d. (2, 12, 8) and (19, 5, 30)

b. (2, 8, 12) and (5, 19, 30)

What is the value of x? int y = 9; int z = 3; double x; x = (y / (z + 1.0)); a. 2 b. 2.25 c. 3 d. Error: The operands are different types and cannot be divided

b. 2.25 In this expression, y is an integer, z is an integer, and 1.0 is a double. The expression inside the parentheses, (z + 1.0), will be evaluated first. Because 1.0 is a double, the result of z + 1.0 will be a double with the value 4.0. When y, which is 9, is divided by 4.0, the result will be a double, because at least one of the operands (4.0) is a double. So, the value of x will be 9 / 4.0, which is 2.25.

What is the output? #include <iostream> #include <queue> #include <map> #include <string> using namespace std; int main () { queue<double>joyTime; double yourNum = 0; joyTime.push(15.5); joyTime.push(14.5); joyTime.front(); joyTime.push(13.5); joyTime.pop(); joyTime.push(12.5); joyTime.pop(); joyTime.push(11.5); joyTime.pop(); yourNum = joyTime.front() + joyTime.back(); cout << yourNum; return 0;} a. 30 b. 24 c. 26 d. 25

b. 24

The most accurate Big O notation for an algorithm with exactly 50 constant time operations is _____. a. O(50) b. O(1) c. O(50N) d. 50·O(1)

b. O(1)

Which of the following statements is correct? a. The queue ADT supports the insertion and deletion of items at the front and the back. b. The list ADT supports the printing of the list contents but the queue ADT does not. c. The queue ADT supports the removing of items from one end and the adding of items to the other end but the list ADT does not. d. The queue ADT supports the printing of the list contents but the list ADT does not.

b. The list ADT supports the printing of the list contents but the queue ADT does not.

What is output? #include <iostream> #include <utility> using namespace std; int main() { pair<string, double> prodCost1; pair<string, double> prodCost2; pair<string, double> prodCost3; int totalCost; p rodCost3 = make_pair("Apple", 0.5); prodCost1 = make_pair("Banana", 1.00); prodCost2 = make_pair("Orange", 3.75); totalCost = prodCost1.second + prodCost2.second + prodCost3.second; cout << "Total cost of "; cout << prodCost1.first << ", " << prodCost2.first << " and " << prodCost3.first; cout << " is " << totalCost << " Dollars."; return 0;} a. Total price of Banana, Orange and Apple is 5.25 Dollars. b. Total price of Banana, Orange and Apple is 5 Dollars. c. Total price of Banana, Orange and Apple is 6 Dollars. d. Total price of Banana, Orange and Apple is 5.00 Dollars.

b. Total price of Banana, Orange and Apple is 5 Dollars.

The _____ function reads an input line into a string. a. str() b. getline(); c. getchar(); d. clear();

b. getline();

Given two vectors, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX/ YYY. vector<string> studentNames; vector<int> studentScores; for (int i = 0; i < studentScores.size(); ++i) { if (XXX > 80) { cout << YYY << " "; }} a. studentNames.at(i) / studentNames.at(i) b. studentScores.at(i) / studentNames.at(i) c. studentNames.at(i) / studentScores.at(i) d. studentScores.at(i) / studentScores.at(i)

b. studentScores.at(i) / studentNames.at(i)

Given string s is "Sunday", what is the ending value of char myChar? myChar = s.at(s.size() - 1); a. a b. y c. " d.No such character

b. y

If a file exists in a directory and contains data when an ofstream object is opened with just the file name to write data into the file _____. a. the new data is appended at the end of the file. b. the system creates a duplicate file for the new data. c. the file is overwritten with the new data. d. an error is generated as the file cannot be overwritten.

c. the file is overwritten with the new data.

Which is not a valid identifier? a. firstName b. first_name c. 1stName d. name1

c. 1stName

Which is true? a. C++ came after C+ but before C b. C came after C++ c. C++ came after C d. C++ came after C+

c. C++ came after C

What is the typical runtime for insertion sort for singly-linked lists? a. O(N) b. O(N⋅logN) c. O(N^2) d. O(N⋅(N−1))

c. O(N^2) This is because insertion sort compares elements and shifts them one at a time to sort the list. In the worst case, each element is compared with all the other elements already sorted in the list, which results in a quadratic time complexity. Even though insertion into a linked list is O(1), the comparisons required to find the correct location for each element lead to an overall O(N^2) time complexity.

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 while (curNode is not null) should be while (list⇢tail is not null). b. The statement curNode = list⇢head should be curNode = list⇢tail. c. The statement curNode = list⇢head⇢next should be curNode = curNode⇢next. d. The statement while (curNode is not null) should be while (curNode is null).

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

_____ is a predefined ostream object that is pre-associated with a system's standard output, usually a computer screen. a. >> b. cin c. cout d. <<

c. cout

A recursive function calls _____. a. at least two more functions b. another function c. itself d. main function

c. itself

myString is declared as a string and is the only variable declared. Which is a valid assignment? a. myString = 'Hello'; b. myString = Hey; c. myString = "H"; d. myString = [Hoy];

c. myString = "H";

Given two same-sized integer vectors prevValues and newValues. Which assigns eq with 1 if the vectors are equal, and 0 otherwise. Choices are in the form XXX / YYY / ZZZ. if (XXX) { YYY;} else { ZZZ;} a. prevValues == newValues / eq = 0 / eq = 1 b. prevValues = newValues / eq = 0 / eq = 1 c. prevValues == newValues / eq = 1 / eq = 0 d. prevValues = newValues / eq = 1 / eq = 0

c. prevValues == newValues / eq = 1 / eq = 0

The _____ class defines a container of ordered elements that supports element insertion at the tail and element retrieval from the head. a. map b. set c. queue d. pair e. stack

c. queue

Consider a class Student with public member functions and private data members. Which XXX is valid for the code? class Student { public: void SetName(string studentName); void SetGrade(int studentGrade); void Display(); private: string name; int grade;}; int main() { Student stu1; XXX ... } a. stu1.name = "Harry"; b. myString = stu1.name; c. stu1.Display(); d. stu1.SetGrade("Harry");

c. stu1.Display();

Which XXX outputs 0? #include <iostream> #include <map> #include <string> using namespace std; int main () { map<string, int> stuScore; stuScore.emplace("Bob", 80); stuScore.emplace("Bill", 90); stuScore.emplace("Mike", 95); stuScore.emplace("John", 75); XXX; cout << stuScore.count("John") ;} a. stuScore.clear("John"); b. stuScore.remove("John"); c. stuScore.clear(); d. stuScore.remove();

c. stuScore.clear();

Which of the following is not a valid set? a. {10, 15, 20} b. {12, 14, 16} c. {11, 22, 33, 11} d. {5, 10, 15}

c. {11, 22, 33, 11} no duplicates in sets

In the following code, the fourth element of the vector after using the sort function sort(petNames.begin(), petNames.end()) is _____. vector<string>petNames; petNames.push_back("Bella"); petNames.push_back("Lucy"); petNames.push_back("Luna"); petNames.push_back("Lola"); petNames.push_back("Lolla"); petNames.push_back("Bailey"); a.Lola b.Luna c.Lolla d. Lucy

c.Lolla

Given a doubly-linked list (2, 3, 4, 5, 6, 7), node 2's pointer(s) point(s) to _____. a. node 3 b. null c. node 3 and null d. the head and node 3

c.node 3 and null

Given the queue myData 12, 24, 36 (front is 12), what is the result of the following operations? Pop(myData) Pop(myData) Pop(myData) print(GetLength(myData)) a. 3 b. 2 c. 1 d. 0

d. 0

Identify the equation to calculate the balance factor, B, of an AVL tree node N. a. B=min(Height(RightSubTree(N)),Height(LeftSubTree(N))) b. B=max(Height(RightSubTree(N)),Height(LeftSubTree(N))) c. B=Height(LeftSubTree(N))+Height(RightSubTree(N)) d. B=Height(LeftSubTree(N))−Height(RightSubTree(N))

d. B=Height(LeftSubTree(N))−Height(RightSubTree(N))

To search for 10 in the array, the first function call is BSearch(arr, 0, 4, 10), what is the second function call? int BSearch(int arr[], int lowVal, int highVal, int num) { if (highVal >= lowVal) { int mid = lowVal + (highVal - lowVal) / 2; if (arr[mid] == num) return mid; if (arr[mid] > num) return BSearch(arr, lowVal, mid - 1, num); else return BSearch(arr, mid + 1, highVal, num); } return -1; } int main() { int arr[] = { 2, 3, 4, 10, 40}; int n = 5; int num = 10; int result = BSearch(arr, 0, n - 1, num); if(result == -1) { cout << "Element is not present in array"; } else { cout << "Element is present at index " << result; } return 0; } a. BSearch(arr, 0, 2, 10) b. BSearch(arr, 2, 4, 10) c. BSearch(arr, 0, 1, 10) d. BSearch(arr, 3, 4, 10)

d. BSearch(arr, 3, 4, 10)

What is the output for input values 1, 2, 3, 4, and 5? #include <iostream> #include <vector> using namespace std; void AddSport(vector<int>&sports, int teamsNum) { sports.push_back(teamsNum); } void Print(const vector<int>&sports) { unsigned int i; for (i = 0; i < sports.size(); ++i) cout << " " << sports.at(i);} void Delete(vector<int>&sports) { sports.erase(sports.begin() + 1); } int main() { vector<int> sports; int teamsNum = 0; for(int i = 0; i < 5; i++) { cout << "Add Team Ranking: "; cin >> teamsNum; AddSport(sports, teamsNum); } cout << "Team Ranking: "; Print(sports); Delete(sports); Print(sports); return 0;} a. Team Ranking: 1 3 4 5 1 2 3 4 5 b. Team Ranking: 1 3 4 5 1 3 4 5 c. Team Ranking: 1 3 4 5 d. Team Ranking: 1 2 3 4 5 1 3 4 5

d. Team Ranking: 1 2 3 4 5 1 3 4 5

The following program generates an error. Why? const int NUM_ELEMENTS = 5; vector<int> userVals(NUM_ELEMENTS); unsigned int i; userVals.at(0) = 1; userVals.at(1) = 7; userVals.at(2) = 4; for (i = 0; i <= NUM_ELEMENTS; ++i) { cout << userVals.at(i) << endl;} a. The vector userVals has 5 elements, but only 3 have values assigned. b. Variable i is declared as an unsigned integer. c. The integer NUM_ELEMENTS is declared as a constant d. The for loop tries to access an index that is out of the vector's valid range.

d. The for loop tries to access an index that is out of the vector's valid range

The following program generates an error. Why? #include <iostream> #include <string>using namespace std; class Arcade { public: Arcade(); Arcade(string name, int r); void Print(); private: string arcName; int rating; }; Arcade:: Arcade() { arcName = "New"; rating = 1;} Arcade:: Arcade(string name, int r) { arcName = name; rating = r;}v oid Arcade:: Print() { cout << "Name is: " << arcName << endl; cout << "Rating is: " << rating << " stars" << endl;} int main() { Arcade myArc(Games Ablaze, 5); myArc.Print(); } a. The object creation should be Arcade myArc(Games Ablaze, 5) b. The object creation should be Arcade myArc.Arcade(Games Ablaze 5); c. The object creation should be Arcade myArc.Arcade('Games Ablaze', 5); d. The object creation should be Arcade myArc("Games Ablaze", 5);

d. The object creation should be Arcade myArc("Games Ablaze", 5);

Which XXX tests the input value 4 using a print statement (without using assert)? int SquareNum(int origNum) { return origNum * origNum; } int main() { cout << "Testing started" << endl; XXX; cout << "Testing completed" << endl; return 0; } a. test(4) b. SquareNum(4) c. cout << "4, expecting 16, got: " << test(4) << endl d. cout << "4, expecting 16, got: " << SquareNum(4) << endl

d. cout << "4, expecting 16, got: " << SquareNum(4) << endl

Which expression evaluates to true if the corresponding characters of strings s1 and s2 are equal independent of case? Ex: "C" and "c" should be considered equal. a. str1.at(i) == str2.at(i) b. str1.at((tolower(i)) == str2.at(tolower(i)) c. str1.at(i) == toupper(str2.at(i)) d. toupper(str1.at(i)) == toupper(str2.at(i))

d. toupper(str1.at(i)) == toupper(str2.at(i))z

What is output? #include <iostream> #include <utility> using namespace std; int main() { pair<string, int> playerName; captainName = make_pair("Roy", 10); cout << captainName.first; return 0;} a. Roy b. 10 c.Error: Operator mismatch. d.Error: Variable not declared in this scope.

d.Error: Variable not declared in this scope.

Given an empty stack menuItems, what will be the result of the following operations? StackPush(menuItems , item Pizza) StackPush(menuItems , item Chips) StackPush(menuItems , item Nachos) StackPush(menuItems , item Tea) print(StackPeek(menuItems)) a. Pizza b. Tea Nachos Chips Pizza c. Pizza Chips Nachos Tea d. null, undefined, error e. Tea

e. Tea Since Tea is the last item pushed onto the stack, it will be at the top of the stack. Therefore, when you peek at the stack, you'll see Tea.

What is the difference between emplace() and insert()?

emplace(): Constructs a new element in-place directly at the location in the container using the provided arguments, avoiding extra copy or move operations. insert(): Inserts an existing object into the container, either by copying or moving, which can be less efficient than constructing it in place. ( more memory)

Which XXX function returns the map entry associated to 12.4? #include <iostream> #include <map> #include <string> using namespace std int main () { map<string, double> logIn; logIn.emplace("emp1", 12.4); logIn.emplace("Emp2", 10.5); logIn.emplace("eMp2", 1.30); logIn.emplace("12.4", 12.4); XXX cout << logIn.count("12.4"); return 0;} a. logIn.emplace("12.4") b. logIn.clear("12.4") c. logIn.at("12.4"); d. logIn.count("12.4")

logIn.at("12.4");

Which is an invalid access for the vector? vector<int> numsList; numList.push_back(4); numList.push_back(2); numList.push_back(0); numList.push_back(1); a. numsList.at(2) b. numsList.at(0) c. numsList.at(4) d. numsList.at(1)

numsList.at(4)

For map<string, int> patientName; which statement will add a mapping for a patient named Julia of age 32? a. patientName.emplace("Julia", 32); b. patientName.replace("Julia", 32); c. patientName.at("Julia", 32); d. patientName.erase("Julia", 32); Question 4

patientName.emplace("Julia", 32);

Name one property of the C++ set data structure that makes it useful.

set data structure is implemented as a self-balancing binary search tree (typically a Red-Black tree) and its key property is that it stores unique elements in a specific order. This ensures no duplicates and allows for efficient access, insertion, and deletion operations, which are generally of logarithmic complexity.


Ensembles d'études connexes

LPN to RN Transition - Fundamentals - Chapter 1: Introduction to Nursing

View Set

CITI - SoCRA - GCP for Clinical Trials with Investigational Drugs and Biologics (ICH Focus)

View Set

Gastrointestinal Practice Question

View Set

exam 2 SAMPLE QUESTIONS FROM DR .YOUAN'S LECTURE

View Set

BUSM 501 Midterm Exam Chapters 3,6,8

View Set

Continuidad de los Parques Análisis

View Set