Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 3..please help and explain.. class Node: class LinkedList: def init (self, value) def init (self) : self. value = value self, next = None

PYTHON 3..please help and explain..

image text in transcribed

class Node: class LinkedList: def init (self, value) def init (self) : self. value = value self, next = None self. head None def add(self, new) def get_next (self): new. next self. head return self. next self. head -newW def get_head (self): return self. head [5 points ] Using the class definitions above for LinkedList and Node objects write a function compare (A, B) that takes linked lists A and B as arguments and returns the following 4. -1 if A is shorter than B 1 if B 1s shorter than A 0 if the lists are the same length Your solution must not simply count the lengths of the lists and compare them, since the complexity would be proportional to the sum of the lengths of the lists Instead, the complexity of your solution must be proportional to the length of the smaller list. You do not need to use recursion

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions