C++ questions
QUESTION 1
What kind of linked list begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node?
A. |
Circular, singly-linked list. |
|
B. |
Circular, doubly-linked list. |
|
C. |
Singly-linked list. |
|
D. |
Doubly-linked list. |
|
E. |
None of the above. |
QUESTION 2
_________ is not an advantage of linked lists when compared to arrays.
A. |
Dynamic memory allocation. |
|
B. |
Efficient insertion and deletion. |
|
C. |
Direct access to any list element. |
|
D. |
No need to allocate extra space, just in case. |
|
E. |
None of the above. |
QUESTION 3
When a new node is inserted to the head of a linked list, will the head pointer and the tail pointer be changed?
A. |
If the list is empty before the insertion, both head and tail will change. |
|
B. |
If the list is not empty before the insertion, head will change. |
|
C. |
Head will always change, but tail will never change. |
|
D. |
Both head and tail will change. |
|
E. |
None of the above. |
QUESTION 4
In general, linked lists allow:
A. |
Insertions and removals anywhere. |
|
B. |
Insertions and removals only at one end. |
|
C. |
Insertions at the back and removals from the front. |
|
D. |
None of the above. |
QUESTION 5
Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code:
for (int i = 0; i < list1.size(); i++)
sum += list1[i];
for (int i = 0; i < list2.getSize(); i++)
sum += list2.get(i);
A. |
Code fragment A is more efficient than code fragment B. |
|
B. |
Code fragment B is more efficient than code fragment A. |
|
C. |
Code fragment A is as efficient as code fragment B. |
|
D. |
None of the above. |
Question 1:-
linked list that begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node is circular,singly-linked list because each an every node is pointed by one pointer which makes it singly linked list and the last node points to the first node which makes it circular linked list.(option A)
Question 2:-
Direct access to any list element,is not an advantage of linked lists when compared to arrays,because we have to access elements sequentially starting from the first node(option C)
Question 3:-
When a new node is inserted to the head of a linked list,Head will always change, but tail will never change because tail pointer always points to null incase of singly-linked list(option C)
Question 4:-
In general, linked lists allow Insertions and removals anywhere,because there is no need to allocate extra space in linked lists.(option A)
Question 5:-
Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code:
code fragment A:-
for (int i = 0; i < list1.size(); i++)
sum += list1[i];
code fragment B:-
for (int i = 0; i< list2.getSize(); i++)
sum += list2.get(i);
Code fragment A is more efficient than code fragment B because extra space is required for the pointers for each node in linked list and Indexing into a linked list is slow because you have to traverse the list to get to the given index, while a vector is contiguous in memory and you can get there using pointer and to find the sum we have to traverse all the elements in vector as well as linked list(option A)
Get Answers For Free
Most questions answered within 1 hours.