What is the time-complexity to print a linked list? a. O(1) b. O(n) c. O(n 2 ) d
ID: 3722402 • Letter: W
Question
What is the time-complexity to print a linked list?
a. O(1)
b. O(n)
c. O(n2)
d. O(log n)
Linked lists built forward or backward are identical in every way.
a. true
b. false
In a doubly linked list, some of the operations require modification from how they were implemented for a regular linked list, because of the ____ reference variable(s) in each node.
a. null
b. two
c. three
d. four
In the class LinkedListClass, the search method is declared as ____.
a. public
b. private
c. abstract
d. protected
Explanation / Answer
//Explained below:
1. What is the time-complexity to print a linked list?
a. O(1)
b. O(n)
c. O(n2)
d. O(log n)
answer : b O(n) because it has to go each node atleast once for n nodes
Eg: for (auto i=head;i!=NULL;i=head->next){ //This will print the data of each node.This loop runs n times.So time complexity=O(n)
cout<<i->data <<endl;
}
2.Linked lists built forward or backward are identical in every way.
a. true
b. false
Ans: true
The only difference between forward linked list and backward linked list is placement of head pointer.Remaining operations are performed in the same way for both forward linked list and backward linked list.
3.In a doubly linked list, some of the operations require modification from how they were implemented for a regular linked list, because of the ____ reference variable(s) in each node.
a. null
b. two
c. three
d. four
Ans : b) two
Take double linked list :
struct Node
{
int data;
struct Node *next; // Pointer to next node in DLL
struct Node *prev; // Pointer to previous node in DLL
};
For adding,deleting etc. a node in double linked list, we have to change the *next and *previous values for the corresonding node which needs to added or deleted.So the answer is 2.
4.In the class LinkedListClass, the search method is declared as ____.
a. public
b. private
c. abstract
d. protected
Ans: a)public -Since search method is used by user to search the node,So it should be declared under public in LinkedListClass
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.