Question

Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE

Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE

Homework Answers

Answer #1

This is the pseudocode for the algorithm. We assume that each node of the linkedlist is of the form (data,next), where data is the value of that node and next contains the pointer to the next element of the linkedlist.

Our function returns false is the two linked lists are not equal else we return true.

We first check if the length of both the lists are 0, if they are 0 then we return true.

Then we iterate over each node to check if they are equal. Finally we check if both the linkedlist has the same end point. If they don't have the same endpoint, we return false.

function check_equality(list1, list2){
     if( list1 == none and list2 == none):
         return true
     
     head1 = list1
     head2 = list2

     while( head1 != none and head2 != none):
          if( head1.data != head2.data):
                return false
          else:
                head1 = head1.next
                head2 = head2.next
     
     if( head1 != none or head2 != none):
          return false

     return true
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in...
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in O(N) time. You can use as much extra space as you need. The original list pointers CAN NOT BE MODIFIED. State in big-O notation how much extra space is used by this algorithm. Write another iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse using O(1) extra space. The original list pointers CAN NOT BE MODIFIED. This algorithm can have...
Please show the java code and pseudocode as well Describe and implement a recursive algorithm for...
Please show the java code and pseudocode as well Describe and implement a recursive algorithm for reversing a singly linked list L, so that the ordering of the nodes becomes opposite of what it was before. What is the running time of your algorithm on a list of n values? Provide both the growth function and BigOh complexity. Create a driver class to test your implementation.
Write a program that uses Standard Library algorithm to merge two ordered lists of strings into...
Write a program that uses Standard Library algorithm to merge two ordered lists of strings into a single ordered list of strings, then displays the resulting list.
Write an algorithm (in pseudocode, with proper indentation for blocks of code in loops or conditional...
Write an algorithm (in pseudocode, with proper indentation for blocks of code in loops or conditional statements) that finds and returns the location of the first negative integer in a sequence of integers.
write an algorithm ( pseudocode in c) which counts the number of element larger than P...
write an algorithm ( pseudocode in c) which counts the number of element larger than P bit smaller than Q.
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Write pseudocode for a simple algorithm for addition of two n-digit numbers (one of them could...
Write pseudocode for a simple algorithm for addition of two n-digit numbers (one of them could be < n digits with 0's appended to the left) in base-10, as follows. Assume the digits are stored in arrays A and B, with A[1] and B[1] being the rightmost digits and A[n] and B[n] being the leftmost digits. Use a for loop to go from right to left adding the digits and keeping track of the carry. Now, here's the real task:...
Write a pseudocode algorithm for giving all employees in a company a cost-of-living wage increase of...
Write a pseudocode algorithm for giving all employees in a company a cost-of-living wage increase of 3.2%. Assume that the payroll file includes all current employees.
Write the algorithm in pseudocode for scan-converting (filling in the interior) of an axis-aligned right triangle...
Write the algorithm in pseudocode for scan-converting (filling in the interior) of an axis-aligned right triangle (the base is aligned with the x-axis and the orthogonal leg is aligned with the y-axis).
{ "array": [ "52", "26", "39", "15" ] } Pseudocode Program Write the pseudocode for our...
{ "array": [ "52", "26", "39", "15" ] } Pseudocode Program Write the pseudocode for our sort algorithm. Note that your pseudocode must match the algorithm described above. Not just any sorting algorithm will work! Your program must do the following: Prompt the user for a file containing a collection of words. Read the file in JSON format. Perform a sort on the list of words. Display the contents of the list on the screen.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT