size head bag figure sample instance of the bag class within the same module it is specified in lines - at the bottom of the modulebut it is not intended for use outside the bag class the remove(method implements the removal operation as presented in the previous sectionbut with couple of modifications the if statement that checked the status of the curnode variable has been replaced with an assert statement this was necessary since the remove operation of the bag has precondition that the item must be in the bag in order to be removed if we make it pass the assertionthe item counter is decremented to reflect one less item in the bagthe node containing the item is unlinked from the linked listand the item is returned as required by the adt definition comparing implementations the python list and the linked list can both be used to manage the elements stored in bag both implementations provide the same time-complexities for the various operations with the exception of the add(method when adding an item to bag implemented using python listthe item is appended to the listwhich requires (ntime in the worst case since the underlying array may have to be expanded in the linked list version of the bag adta new bag item is stored in new node that is prepended to the linked structurewhich only requires ( table shows the time-complexities for two implementations of the bag adt in generalthe choice between linked list or python list depends on the application as both have advantages and disadvantages the linked list is typically better choice for those applications involving large amounts of dynamic datadata that changes quite often if there will be large number of insertions and/or deletionsthe linked structure provides fast implementation since large amounts operation python list linked list bag( ( ( len(bo( ( in (no(nb add(xo(no( remove(xo(no(ntraversal (no(ntable comparing the bag adt implemented using python list and linked list