Subject: Data Structures and Algorithms, C++ please help in this take-home quiz. need full marks please double-check ans
Posted: Fri Jun 10, 2022 11:58 am
Subject: Data Structures and Algorithms, C++ please help
in this take-home quiz. need full marks please double-check
answers.
Please give correct Answers to all 10
questions need all answers! and all
correct! posted last time also but got wrong and
incomplete, please provide all 10 correct answers will
give an upvote if correct. Also, explain why correct need all 10
Questions! within 2 hours.
note: You should expect more than one correct answer for
those questions stating "more than one answer may be
selected". You need to give the exact correct answers (no
more, no fewer) to get the mark. In
particular, Question 9 also allows for
more than one correct answer.
Question 1 (0.8 Mark) What is the time complexity of inserting a new element before the fourth to last element in a singly linked list? Suppose the length of the linked list is n. A. 0(1) B. O(n) C. O(nlogn) D. 0(²) Question 2 (0.8 Mark) Suppose you use a simple division hash function, h (k)=k%n, and linear probing to insert a series of elements: 4,5,6,8,10, one by one to an array (Suppose the length of array: n=6). What would be the array position (or index) to store 10? A. 0 B. 1 C. 3 D. 4 Question 3 (0.8 Mark) What is the worst-case time complexity of adding an element to a binary heap? Suppose n is the number of elements that already exist in the heap before the addition. You may consider either a max-heap or a min-heap; that will not affect the result. A. O(logn) B. O(n) C. O(nlogn) D. O(n²)
Question 4 (0.8 Mark) The visiting orders of a Postorder traversal and an Inorder traversal of a tree are shown below: Post-order: B D FACEG In-order: GED BC FA What is the visiting order a Preorder traversal of the same tree? A. GEAF CD B B. GEC D BA F C. GED BC FA D. None of the above Question 5 (0.8 Mark) Suppose x is the value at the bottom of a std::stack after the following operations: push (1), push (3), push (5), pop (),pop (), push (7), pop (), push (9). What operation sequences make the value at the front of a std::queue equal x (More than one answer may be selected)? A. push (1), push (3), pop (), push (1), push (5), pop (), push (1), push (7) B. push (1), push (3), push (1), push (5), pop (), pop (), pop (), push (7), push (9) C. push (5), push (3), push (1), pop (), pop (), push (9), push (3), push (7), pop () D. push (2), pop (), push (2), push (7), push (1), pop (), push (9), push (4), pop ()
Question 6 (0.8 Mark) Which of the data structures below can be iterated over using std::iterator? (More than one answer may be selected)? To iterate over a data structure means to access all the elements in the data structure one by one. A. std::tuple B. std::map C. std::set D. std::list Question 7 (0.8 Mark) Which of the following is TRUE about pointers and memory deallocation in C++? A. We cannot use the 'delete' keyword to deallocate the space that is allocated statically. B. Suppose head is a pointer to the first node of a linked list. We can do delete head; to deallocate the memory taken by the whole linked list. C. Suppose p is a pointer to certain memory space. We can simply set p=nullptr; to deallocate the space. D. We do not need to deallocate space as C++ can automatically recycle the space that is not in use. Question 8 (0.8 Mark) Which of the following is/are TRUE about hash functions (More than one answer may be selected)? A. A "good" hash function can generate a hash according to the input very quickly. B. A "good" hash function may have a certain chance of generating different hashes for the same input. C. A "good" hash function has a low chance of generating the same hash for different inputs. D. A hash function may work well for one set of inputs but not for another set of inputs.
Question 9 (0.8 Mark) Suppose a binary heap (Heap) and a binary search tree (BST) contain the same elements (e.g., ints). Which of the following is/are NOT true about binary heap and binary search tree? A. The height of the Heap might be larger than the height of the BST. B. Heap-sort may have lower big-O complexity in giving an (either ascending or descending) ordering of the elements than the BST does. C. It is more efficient to do a lookup in BST than in Heap. D. Heap always takes less memory space than BST no matter what data structures are used to implement them. Question 10 (0.8 Mark) What is the time complexity of the following code (Suppose m>0 and n>1)? int func (int m, int n) { int i=0; while (m<100) { i++; m++; } for (int i=0; i<n-1; i++) { for (int j-n; j>i; j--) return i*j; }
A. 0(m) B. 0(²) C. 0(m+n²) D. 0(1)
in this take-home quiz. need full marks please double-check
answers.
Please give correct Answers to all 10
questions need all answers! and all
correct! posted last time also but got wrong and
incomplete, please provide all 10 correct answers will
give an upvote if correct. Also, explain why correct need all 10
Questions! within 2 hours.
note: You should expect more than one correct answer for
those questions stating "more than one answer may be
selected". You need to give the exact correct answers (no
more, no fewer) to get the mark. In
particular, Question 9 also allows for
more than one correct answer.
Question 1 (0.8 Mark) What is the time complexity of inserting a new element before the fourth to last element in a singly linked list? Suppose the length of the linked list is n. A. 0(1) B. O(n) C. O(nlogn) D. 0(²) Question 2 (0.8 Mark) Suppose you use a simple division hash function, h (k)=k%n, and linear probing to insert a series of elements: 4,5,6,8,10, one by one to an array (Suppose the length of array: n=6). What would be the array position (or index) to store 10? A. 0 B. 1 C. 3 D. 4 Question 3 (0.8 Mark) What is the worst-case time complexity of adding an element to a binary heap? Suppose n is the number of elements that already exist in the heap before the addition. You may consider either a max-heap or a min-heap; that will not affect the result. A. O(logn) B. O(n) C. O(nlogn) D. O(n²)
Question 4 (0.8 Mark) The visiting orders of a Postorder traversal and an Inorder traversal of a tree are shown below: Post-order: B D FACEG In-order: GED BC FA What is the visiting order a Preorder traversal of the same tree? A. GEAF CD B B. GEC D BA F C. GED BC FA D. None of the above Question 5 (0.8 Mark) Suppose x is the value at the bottom of a std::stack after the following operations: push (1), push (3), push (5), pop (),pop (), push (7), pop (), push (9). What operation sequences make the value at the front of a std::queue equal x (More than one answer may be selected)? A. push (1), push (3), pop (), push (1), push (5), pop (), push (1), push (7) B. push (1), push (3), push (1), push (5), pop (), pop (), pop (), push (7), push (9) C. push (5), push (3), push (1), pop (), pop (), push (9), push (3), push (7), pop () D. push (2), pop (), push (2), push (7), push (1), pop (), push (9), push (4), pop ()
Question 6 (0.8 Mark) Which of the data structures below can be iterated over using std::iterator? (More than one answer may be selected)? To iterate over a data structure means to access all the elements in the data structure one by one. A. std::tuple B. std::map C. std::set D. std::list Question 7 (0.8 Mark) Which of the following is TRUE about pointers and memory deallocation in C++? A. We cannot use the 'delete' keyword to deallocate the space that is allocated statically. B. Suppose head is a pointer to the first node of a linked list. We can do delete head; to deallocate the memory taken by the whole linked list. C. Suppose p is a pointer to certain memory space. We can simply set p=nullptr; to deallocate the space. D. We do not need to deallocate space as C++ can automatically recycle the space that is not in use. Question 8 (0.8 Mark) Which of the following is/are TRUE about hash functions (More than one answer may be selected)? A. A "good" hash function can generate a hash according to the input very quickly. B. A "good" hash function may have a certain chance of generating different hashes for the same input. C. A "good" hash function has a low chance of generating the same hash for different inputs. D. A hash function may work well for one set of inputs but not for another set of inputs.
Question 9 (0.8 Mark) Suppose a binary heap (Heap) and a binary search tree (BST) contain the same elements (e.g., ints). Which of the following is/are NOT true about binary heap and binary search tree? A. The height of the Heap might be larger than the height of the BST. B. Heap-sort may have lower big-O complexity in giving an (either ascending or descending) ordering of the elements than the BST does. C. It is more efficient to do a lookup in BST than in Heap. D. Heap always takes less memory space than BST no matter what data structures are used to implement them. Question 10 (0.8 Mark) What is the time complexity of the following code (Suppose m>0 and n>1)? int func (int m, int n) { int i=0; while (m<100) { i++; m++; } for (int i=0; i<n-1; i++) { for (int j-n; j>i; j--) return i*j; }
A. 0(m) B. 0(²) C. 0(m+n²) D. 0(1)