Laboratory Walkthrough 8

# Note that two lists might intersect even if their

• CaptainStrawCrow5189
• 5

This preview shows page 3 - 5 out of 5 pages.

Note that two lists might intersect even if their lengths are not equal, just as in the example. 4. reverse(sll) reverses the given list (so the head becomes the last item, and an item j points to an item i if in the original list i was pointing to j ). The function returns None; it modifies the original list to become the reversed list. 5. get_item(sll,k) - returns the k'th item of the list. If k is negative returns the k’th item from the end of the list (same behavior as using list[k] in python lists). 6. slice(sll, start, stop, step) returns a new list after slicing out items according to the given arguments (same as using list[start:step:stop] in python lists). For example: sll = {10,11,12,13,14,15,16,17,18,19,20} sliced_sll = slice(sll, 4, 8, 2) The new list = {14,16} 7. merge_lists(first_list, second_list) - takes two sorted lists (in ascending order) and returns a new sorted list that merges the two input lists. 8. merge_sort(sll) - sorts the list into ascending order using the merge-sort algorithm learnt in class. Make sure that you use the merge-sort algorithm and not any other sorting algorithm. Important notes: Your implementations should be efficient. Non-efficient implementations will not grant full grade.

Subscribe to view the full document.

You may assume the list contains no cycles in all functions except the contains_cycle() function. In functions 1, 2, 3 and 5 you should not change the values stored in any of the nodes or replace any node in the list. In the functions reverse() and merge_sort () you should modify the original list. In the functions slice() and merge_lists () you should create a new list. In all functions you should use extra O(1) space (meaning that you are not allowed to create more than a fixed number of new nodes), excluding new nodes which will be part of a new list returned by the function. You should not submit the file sllist.py , and thus you may not make any changes to the file. You must explain the complexity of your implementation for each of the above functions in a README file. A non-efficient implementation will not get a full grade. Part 3 - Implementing a special linked list In this part, you will implement a special linked list, called a SkipiList . SkipiList is a special variant of a doubly-linked list, where each Node has a reference to the next Node in the list, and another reference to the Node two positions before (prev-prev) in the list, which is called the skip_back reference (hence the prefix “skipi”) . In addition, a SkipiList has references both to the head of the list and to the tail of the list. Initially, the list is created empty with both of these references set to None . The tail node’s next pointer is always
• Spring '14
• Avraham

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern