

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This is about data structure lecture note
Typology: Lecture notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!
data next data next data next data next _head
_tail
_size 4
'w' 'a' 'y' 'c'
UnorderedList Object
a) The search(targetItem) method searches for targetItem in the list. It returns True if targetItem is in the list; otherwise it returns False. Complete the search(targetItem) method code:
class UnorderedList: def search(self, targetItem):
b) The textbook’s unordered list ADT does not allow duplicate items, so operations add(item), append(item), and insert(pos, item) would have what precondition?
c) Complete the append(item) method including a check of it’s precondition(s)?
def append(self, item):
d) Why do you suppose I added a _tail attribute?
Lecture 8 - Page 1
e) The textbook’s remove(item) and index(item) operations “Assume the item is present in the list.” Thus, they would have a precondition like “Item is in the list.” When writing a program using an UnorderedList object (say myGroceryList = UnorderedList() ), how would the programmer check if the precondition is satisfied? itemToRemove = input(“Enter the item to remove from the Grocery list: “)
if myGroceryList.remove(itemToRemove)
f) The remove(item) and index(item) methods both need to look for the item. What is inefficient in this whole process?
g) Modify the search(targetItem) method code in (a) to set additional data attributes to aid the implementation of the remove(item) and index(item) methods.
h) Write the index(item) method including a check of its precondition(s).
def index(self, item):
i) Write the remove(item) method including a check of its precondition(s).
def remove(self, item):
Lecture 8 - Page 2