Quiz 10_ Searching, Files and Vectors_ CMPT130 D100 Introduction to Computer Programming I

pdf

School

Douglas College *

*We aren’t endorsed by this school

Course

130

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

9

Uploaded by LieutenantSparrow1721

Report
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 1/9 Quiz 10: Searching, Files and Vectors Due Nov 27 at 11:59am Points 12 Questions 11 Available Nov 26 at 11:30am - Nov 27 at 11:59am 1 day Time Limit 30 Minutes This quiz was locked Nov 27 at 11:59am. Attempt History Attempt Time Score LATEST Attempt 1 27 minutes 12 out of 12 Score for this quiz: 12 out of 12 Submitted Nov 27 at 12:26am This attempt took 27 minutes. 1 / 1 pts Question 1 Bob has a collection of 1,000 photographs that he took as a child stored in a large box in his basement. They are sorted in date order from oldest (when he was ten) to newest (when he was fifteen). Bob is looking for a picture of his cousin Lucy but he cannot remember when he took it. He plans to look through his photographs one by one beginning with the first. If the photograph is not the one he is looking for he will put it back in the box in the same place he found it and look at the one next to it. He will repeat this process until he finds the photograph of Lucy or reaches the last photograph in the box. What algorithm is Bob using? selection sort linear search Correct! Correct! binary search
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 2/9 insertion sort bogo sort 1 / 1 pts Question 2 Given the array: int data[] = {16, 34, 4, 1, 12} Which search algorithm would be fastest (fewest number of comparisons) to find the value 1 in data without modifying data in any way before searching, and why? Binary search, because in this case it will find the value faster Linear search, because binary search would not work Correct! Correct! Binary search, because it always finds the value faster Linear search, because it starts at the smallest value first 1 / 1 pts Question 3 Given the array: int data[] = {5, 8, 11, 15, 22} How many different array elements will be compared to the target value when using binary search to find the element 32 in the " data " array? 5
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 3/9 4 3 Correct! Correct! 1 2 1 / 1 pts Question 4 Given the array: int data[] = {5, 8, 11, 15, 22} How many different array elements will be compared to the target value when using linear search to find the element 15 in the " data " array? 1 5 2 3 4 Correct! Correct! 1 / 1 pts Question 5 Suppose that a sorted array is searched for a value using the binary search algorithm. The array contains 1,000,000 elements and the value to be searched for is not in the array.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 4/9 Which is the best estimate for the number of different elements that will be compared to the target value before binary search determines that the target value is not in the array? 20 Correct! Correct! 10000 1000 1000000 100000 log2 of 1000000 - or the results of the search demo. 1 / 1 pts Question 6 What is printed by the code fragment shown below? The contents of input.txt are:
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 5/9 black green red blue 1 black 2 green 3 red 4 blue black bgrb Correct! Correct! black orange green yellow red brown blue bgrb fail 1 / 1 pts Question 7 What is printed by the code fragment shown below? The contents of data.txt are: car light block ring
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 6/9 tube power light car block tube car block tube Correct! Correct! c a r b l o c k t u b e block power tube light car ring block power tube 1 / 1 pts Question 8 What is printed by the code fragment shown below? The contents of numbers.txt are: 40 803 2 95
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 7/9 0 32 5 0325 Correct! Correct! 4 80 0 9 40 95 0 30 20 50 1 / 1 pts Question 9 Which of the following C++ statements prints out the last element in a non- empty vector named prices ? cout << prices.at().empty(); cout << prices.at().size(); cout << prices.at(prices.size()); cout << prices.at(prices.size() - 1); Correct! Correct! cout << prices.size().at(); 1 / 1 pts Question 10 Which of the following C++ statements should be added to the code below in order to generate the vector {'x', 'x', 'x'}?
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 8/9 characters.at(i) = 'x'; characters.pop_back("x"); characters.push_back("x"); characters.push_back('x'); Correct! Correct! 'x'.push_back(characters); 2 / 2 pts Question 11 Select lines of code in the correct order from 1 to 4 to write a function that sets the points in a vector of points to form a diagonal line from { x =0, y =0} to { x =n, y =n}, where n is the number of points in the function's vector parameter . The definition of the point struct is shown below. Note that opening and closing {}s are shown and that not all of the answers are relevant. 1 void setDiagonal(vector<p Correct! Correct! 2 Correct! Correct!
12/7/21, 3:13 PM Quiz 10: Searching, Files and Vectors: CMPT130 D100 Introduction to Computer Programming I https://canvas.sfu.ca/courses/64792/quizzes/178196 9/9 Other Incorrect Match Options: void setDiagonal(vector<point_t> pts, int n) { for (point_t : pt) { pts.x = i; for (int i = 0; i <= pts.size(); i++) { void setDiagonal(vector<point_t> pts) { pts.y = i; } } pts.y.at(i) = i; } } pts.x.at(i) = i; for (int i = 0; i < pts.size(); 3 pts.at(i).x = i; Correct! Correct! 4 pts.at(i).y = i; } } Correct! Correct! Quiz Score: 12 out of 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help