SlideShare a Scribd company logo
Answers
a) It is more efficient to delete the last node in an array because we can access the last element in
constant time O(1) and we can delete the value at that position. In case of linked list we need to
traverse the entire list to reach the last node which requires O(n) time and then we delete the
node.
b) It is inefficient to delete the first node in an array because after deleting the first element we
need to shift the remaining elements one position to the left which requires O(n) time. In case of
linked list we can directly delete the first node by changing the pointer to the first node and
freeing the memory which was earlier allocated to the first element. This operation can be done
in O(1) time.
c) In case of an array after deleting the specific element we need to shift the remaining elements
one position to the left and hence it is inefficient. In case of a linked list we need to traverse the
linked list till we reach the node to be deleted and then we can change the pointers to delete the
node.
d) It is more efficient to insert a node at the end of an array because we can access the last index
in O(1) time and then we can insert the element at that position. In case of linked list we need to
traverse till the end of list and then we can insert the element which requires O(n) time and is
inefficient.
e) It is inefficient to insert a node at the front of an array because we need to make room for the
new element to be inserted by shifting all the elements one position to the right and then insert
the element at the first index of array. In case of linked list we can create a new node and insert
the node at first position by modifying the pointers which is efficient.
f) It is inefficient to insert a node in general in case of array because we need to make room for
the element by shifting the element one position to the right and then we can insert the element at
that index position. In case of linked list we need to traverse the list till we reach the specific
position and then we can insert the element by modifying the pointer.
g) It is more efficient to access a node in case of an array because arrays support random access
and we can access any index in constant time. In case of linked list we need to traverse the list in
order to find the element at specified index which is not efficient.
Solution
Answers
a) It is more efficient to delete the last node in an array because we can access the last element in
constant time O(1) and we can delete the value at that position. In case of linked list we need to
traverse the entire list to reach the last node which requires O(n) time and then we delete the
node.
b) It is inefficient to delete the first node in an array because after deleting the first element we
need to shift the remaining elements one position to the left which requires O(n) time. In case of
linked list we can directly delete the first node by changing the pointer to the first node and
freeing the memory which was earlier allocated to the first element. This operation can be done
in O(1) time.
c) In case of an array after deleting the specific element we need to shift the remaining elements
one position to the left and hence it is inefficient. In case of a linked list we need to traverse the
linked list till we reach the node to be deleted and then we can change the pointers to delete the
node.
d) It is more efficient to insert a node at the end of an array because we can access the last index
in O(1) time and then we can insert the element at that position. In case of linked list we need to
traverse till the end of list and then we can insert the element which requires O(n) time and is
inefficient.
e) It is inefficient to insert a node at the front of an array because we need to make room for the
new element to be inserted by shifting all the elements one position to the right and then insert
the element at the first index of array. In case of linked list we can create a new node and insert
the node at first position by modifying the pointers which is efficient.
f) It is inefficient to insert a node in general in case of array because we need to make room for
the element by shifting the element one position to the right and then we can insert the element at
that index position. In case of linked list we need to traverse the list till we reach the specific
position and then we can insert the element by modifying the pointer.
g) It is more efficient to access a node in case of an array because arrays support random access
and we can access any index in constant time. In case of linked list we need to traverse the list in
order to find the element at specified index which is not efficient.

More Related Content

More from anilgoelslg

Weighted average cost of all financing sources(Thus weight is give.pdf
Weighted average cost of all financing sources(Thus weight is give.pdfWeighted average cost of all financing sources(Thus weight is give.pdf
Weighted average cost of all financing sources(Thus weight is give.pdf
anilgoelslg
 
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
anilgoelslg
 
import java.util.; public class queuing{ get factorial in.pdf
  import java.util.; public class queuing{     get factorial     in.pdf  import java.util.; public class queuing{     get factorial     in.pdf
import java.util.; public class queuing{ get factorial in.pdf
anilgoelslg
 
Zeff increases from rigght to left in a period, a.pdf
                     Zeff increases from rigght to left in a period, a.pdf                     Zeff increases from rigght to left in a period, a.pdf
Zeff increases from rigght to left in a period, a.pdf
anilgoelslg
 
What exactly was involved in the reaction Were y.pdf
                     What exactly was involved in the reaction Were y.pdf                     What exactly was involved in the reaction Were y.pdf
What exactly was involved in the reaction Were y.pdf
anilgoelslg
 
True Infrared spectroscopy is one of the fastest.pdf
                     True  Infrared spectroscopy is one of the fastest.pdf                     True  Infrared spectroscopy is one of the fastest.pdf
True Infrared spectroscopy is one of the fastest.pdf
anilgoelslg
 
sp2 note; NO2- adopts a bent and planar geometry.pdf
                     sp2  note; NO2- adopts a bent and planar geometry.pdf                     sp2  note; NO2- adopts a bent and planar geometry.pdf
sp2 note; NO2- adopts a bent and planar geometry.pdf
anilgoelslg
 
I2 is purple color. using oxidizing areagent to o.pdf
                     I2 is purple color. using oxidizing areagent to o.pdf                     I2 is purple color. using oxidizing areagent to o.pdf
I2 is purple color. using oxidizing areagent to o.pdf
anilgoelslg
 
D. 7 Solution D. 7 .pdf
                     D. 7  Solution                     D. 7  .pdf                     D. 7  Solution                     D. 7  .pdf
D. 7 Solution D. 7 .pdf
anilgoelslg
 
conductivity of the solution is due to its ions. .pdf
                     conductivity of the solution is due to its ions. .pdf                     conductivity of the solution is due to its ions. .pdf
conductivity of the solution is due to its ions. .pdf
anilgoelslg
 
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdfX has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
anilgoelslg
 
Sorry ,need more informationSolutionSorry ,need more informati.pdf
Sorry ,need more informationSolutionSorry ,need more informati.pdfSorry ,need more informationSolutionSorry ,need more informati.pdf
Sorry ,need more informationSolutionSorry ,need more informati.pdf
anilgoelslg
 
raised outcomes exists across several situations, as an example by .pdf
raised outcomes exists across several situations, as an example by .pdfraised outcomes exists across several situations, as an example by .pdf
raised outcomes exists across several situations, as an example by .pdf
anilgoelslg
 
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdf
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdfQ-1Ans-MAC address is a globally unique identifier assigned to n.pdf
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdf
anilgoelslg
 
Rest of the programSolutionRest of the program.pdf
Rest of the programSolutionRest of the program.pdfRest of the programSolutionRest of the program.pdf
Rest of the programSolutionRest of the program.pdf
anilgoelslg
 
Net neutrality is the principle that Internet service providers and .pdf
Net neutrality is the principle that Internet service providers and .pdfNet neutrality is the principle that Internet service providers and .pdf
Net neutrality is the principle that Internet service providers and .pdf
anilgoelslg
 
Malnutrition people lacks energy so they interact less with the peop.pdf
Malnutrition people lacks energy so they interact less with the peop.pdfMalnutrition people lacks energy so they interact less with the peop.pdf
Malnutrition people lacks energy so they interact less with the peop.pdf
anilgoelslg
 
Insecticide                                                     .pdf
Insecticide                                                     .pdfInsecticide                                                     .pdf
Insecticide                                                     .pdf
anilgoelslg
 
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdfC. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
anilgoelslg
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdf
anilgoelslg
 

More from anilgoelslg (20)

Weighted average cost of all financing sources(Thus weight is give.pdf
Weighted average cost of all financing sources(Thus weight is give.pdfWeighted average cost of all financing sources(Thus weight is give.pdf
Weighted average cost of all financing sources(Thus weight is give.pdf
 
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
( 1) jirovecii tropozoites produce sexually by fission is a false st.pdf
 
import java.util.; public class queuing{ get factorial in.pdf
  import java.util.; public class queuing{     get factorial     in.pdf  import java.util.; public class queuing{     get factorial     in.pdf
import java.util.; public class queuing{ get factorial in.pdf
 
Zeff increases from rigght to left in a period, a.pdf
                     Zeff increases from rigght to left in a period, a.pdf                     Zeff increases from rigght to left in a period, a.pdf
Zeff increases from rigght to left in a period, a.pdf
 
What exactly was involved in the reaction Were y.pdf
                     What exactly was involved in the reaction Were y.pdf                     What exactly was involved in the reaction Were y.pdf
What exactly was involved in the reaction Were y.pdf
 
True Infrared spectroscopy is one of the fastest.pdf
                     True  Infrared spectroscopy is one of the fastest.pdf                     True  Infrared spectroscopy is one of the fastest.pdf
True Infrared spectroscopy is one of the fastest.pdf
 
sp2 note; NO2- adopts a bent and planar geometry.pdf
                     sp2  note; NO2- adopts a bent and planar geometry.pdf                     sp2  note; NO2- adopts a bent and planar geometry.pdf
sp2 note; NO2- adopts a bent and planar geometry.pdf
 
I2 is purple color. using oxidizing areagent to o.pdf
                     I2 is purple color. using oxidizing areagent to o.pdf                     I2 is purple color. using oxidizing areagent to o.pdf
I2 is purple color. using oxidizing areagent to o.pdf
 
D. 7 Solution D. 7 .pdf
                     D. 7  Solution                     D. 7  .pdf                     D. 7  Solution                     D. 7  .pdf
D. 7 Solution D. 7 .pdf
 
conductivity of the solution is due to its ions. .pdf
                     conductivity of the solution is due to its ions. .pdf                     conductivity of the solution is due to its ions. .pdf
conductivity of the solution is due to its ions. .pdf
 
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdfX has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
X has density function x2 ( ox2)Y = X(2 - X)the density f.pdf
 
Sorry ,need more informationSolutionSorry ,need more informati.pdf
Sorry ,need more informationSolutionSorry ,need more informati.pdfSorry ,need more informationSolutionSorry ,need more informati.pdf
Sorry ,need more informationSolutionSorry ,need more informati.pdf
 
raised outcomes exists across several situations, as an example by .pdf
raised outcomes exists across several situations, as an example by .pdfraised outcomes exists across several situations, as an example by .pdf
raised outcomes exists across several situations, as an example by .pdf
 
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdf
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdfQ-1Ans-MAC address is a globally unique identifier assigned to n.pdf
Q-1Ans-MAC address is a globally unique identifier assigned to n.pdf
 
Rest of the programSolutionRest of the program.pdf
Rest of the programSolutionRest of the program.pdfRest of the programSolutionRest of the program.pdf
Rest of the programSolutionRest of the program.pdf
 
Net neutrality is the principle that Internet service providers and .pdf
Net neutrality is the principle that Internet service providers and .pdfNet neutrality is the principle that Internet service providers and .pdf
Net neutrality is the principle that Internet service providers and .pdf
 
Malnutrition people lacks energy so they interact less with the peop.pdf
Malnutrition people lacks energy so they interact less with the peop.pdfMalnutrition people lacks energy so they interact less with the peop.pdf
Malnutrition people lacks energy so they interact less with the peop.pdf
 
Insecticide                                                     .pdf
Insecticide                                                     .pdfInsecticide                                                     .pdf
Insecticide                                                     .pdf
 
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdfC. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
C. 10.0.0.65Host 10.0.0.65 is the device IP address of the host th.pdf
 
import java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdfimport java.util.; public class IteratorDemo {public static voi.pdf
import java.util.; public class IteratorDemo {public static voi.pdf
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 

Answersa) It is more efficient to delete the last node in an array.pdf

  • 1. Answers a) It is more efficient to delete the last node in an array because we can access the last element in constant time O(1) and we can delete the value at that position. In case of linked list we need to traverse the entire list to reach the last node which requires O(n) time and then we delete the node. b) It is inefficient to delete the first node in an array because after deleting the first element we need to shift the remaining elements one position to the left which requires O(n) time. In case of linked list we can directly delete the first node by changing the pointer to the first node and freeing the memory which was earlier allocated to the first element. This operation can be done in O(1) time. c) In case of an array after deleting the specific element we need to shift the remaining elements one position to the left and hence it is inefficient. In case of a linked list we need to traverse the linked list till we reach the node to be deleted and then we can change the pointers to delete the node. d) It is more efficient to insert a node at the end of an array because we can access the last index in O(1) time and then we can insert the element at that position. In case of linked list we need to traverse till the end of list and then we can insert the element which requires O(n) time and is inefficient. e) It is inefficient to insert a node at the front of an array because we need to make room for the new element to be inserted by shifting all the elements one position to the right and then insert the element at the first index of array. In case of linked list we can create a new node and insert the node at first position by modifying the pointers which is efficient. f) It is inefficient to insert a node in general in case of array because we need to make room for the element by shifting the element one position to the right and then we can insert the element at that index position. In case of linked list we need to traverse the list till we reach the specific position and then we can insert the element by modifying the pointer. g) It is more efficient to access a node in case of an array because arrays support random access and we can access any index in constant time. In case of linked list we need to traverse the list in order to find the element at specified index which is not efficient. Solution Answers a) It is more efficient to delete the last node in an array because we can access the last element in constant time O(1) and we can delete the value at that position. In case of linked list we need to
  • 2. traverse the entire list to reach the last node which requires O(n) time and then we delete the node. b) It is inefficient to delete the first node in an array because after deleting the first element we need to shift the remaining elements one position to the left which requires O(n) time. In case of linked list we can directly delete the first node by changing the pointer to the first node and freeing the memory which was earlier allocated to the first element. This operation can be done in O(1) time. c) In case of an array after deleting the specific element we need to shift the remaining elements one position to the left and hence it is inefficient. In case of a linked list we need to traverse the linked list till we reach the node to be deleted and then we can change the pointers to delete the node. d) It is more efficient to insert a node at the end of an array because we can access the last index in O(1) time and then we can insert the element at that position. In case of linked list we need to traverse till the end of list and then we can insert the element which requires O(n) time and is inefficient. e) It is inefficient to insert a node at the front of an array because we need to make room for the new element to be inserted by shifting all the elements one position to the right and then insert the element at the first index of array. In case of linked list we can create a new node and insert the node at first position by modifying the pointers which is efficient. f) It is inefficient to insert a node in general in case of array because we need to make room for the element by shifting the element one position to the right and then we can insert the element at that index position. In case of linked list we need to traverse the list till we reach the specific position and then we can insert the element by modifying the pointer. g) It is more efficient to access a node in case of an array because arrays support random access and we can access any index in constant time. In case of linked list we need to traverse the list in order to find the element at specified index which is not efficient.