Question

In: Computer Science

Implement a CircularDoubleLinkedList.The removelast method should be implemented with O(1) complexity. There rest is just to...

Implement a CircularDoubleLinkedList.The removelast method should be implemented with O(1) complexity. There rest is just to keep all pointers correct. (Implement in Java pls)

Solutions

Expert Solution

With a time complexity of O(n)

and space complexity of O(1)

class remLast { 
    static class Node { 
        int data; 
        Node next; 
    }; 
  
    static Node remLNode(Node head) 
    { 
        if (head == null) 
            return null; 
  
        if (head.next == null) { 
            return null; 
        } 
  
      
        Node sec_Last = head; 
        while (sec_Last.next.next != null) 
            sec_Last = sec_Last.next; 
  
       
        sec_Last.next = null; 
  
        return head; 
    } 
    static Node push(Node head_Ref, int new_Data) 
    { 
        Node new_Node = new Node(); 
        new_Node.data = new_Data; 
        new_Node.next = (head_Ref); 
        (head_Ref) = new_Node; 
        return head_Ref; 
    } 
  
    // driver code 
    public static void main(String args[]) 
    { 
        Node head = null; 
        head = push(head, 12); 
        head = push(head, 29); 
        head = push(head, 11); 
        head = push(head, 23); 
        head = push(head, 8); 
  
        head = remLNode(head); 
        for (Node temp = head; temp != null; temp = temp.next) 
            System.out.print(temp.data + " "); 
    } 
}

Related Solutions

Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN)...
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN) B. Evaluate the following postfix expression. 2 3 4 + * C. In an array representation of heap, what are the parent node of a node a[10]? a[9] a[11] a[5] a[20] There is no easy way to access parent node in such representation. D. In an array representation of heap, what are the children nodes (if any) of a node a[10]? a[11] and a[12]...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java program to reverse a stack of characters. Make your own assumption and your own design on the methods signature, inputs, outputs, and the full main program.
discussing experience with dealing Dynamic complexity, with describing the situation and the solution that was implemented
discussing experience with dealing Dynamic complexity, with describing the situation and the solution that was implemented
What is the time complexity of the following code? (in big-O notaion) sum = 0 var...
What is the time complexity of the following code? (in big-O notaion) sum = 0 var = 0 product = 0 for i = 1 to (n+2){ sum = sum + 2i for j = i to [(n*n)+i]{ var = sum + var for k = sum + var{ product = var++ } } } for m + 1 to (j*i){ sum = sum + product }
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 +...
Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 + n)(n ^2 + π/2 ) 3. 1 + 2 + 3 + · · · + n − 1 + n
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of...
Using a single queue (linkedQueue), re-implement the concept of Stack ADT, what is the complexity of the method push, pop, top, isEmpty, and size. You should not use any extra data structure. Related codes: public interface Stack<E> { int size( ); boolean isEmpty( ); void push(E e); E top( ); E pop( ); } public class LinkedStack<E> implements Stack<E> { private SinglyLinkedList<E> list = new SinglyLinkedList<>( );    public LinkedStack( ) { }    public int size( ) { return...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis of the Algorithme lecture
Copy the program Stats.java to your computer and implement the TBI (To Be Implemented) stats() and...
Copy the program Stats.java to your computer and implement the TBI (To Be Implemented) stats() and checkIfSorted() methods following the instructions given in their method comment blocks. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Stats.java import java.util.*; /* * This Java application calculates some statistics * given an array of integers. * * @creator gdt * @created 02017.12.15 * @updated 02019.01.21 morphed the assignment */ interface StatsConstants { // used by print() to format output... String PRINT_BEGIN = "["; String PRINT_END = "]"; String PRINT_SEPARATOR =...
how do i find a peak in time complexity of O(log(n)) in a list? input: a...
how do i find a peak in time complexity of O(log(n)) in a list? input: a list of numbers or integers output: a possible local peak in the list for an example: calling function [2,3,8,9,5] would return 3 im thinking about using binary search but it would require a sorted list.
An observer (O) is standing on a long tunnel that has a rest length of 12...
An observer (O) is standing on a long tunnel that has a rest length of 12 c.µs.  O sees a long train that he measures to be 12c.µstravel through the tunnel at a speed of 0.600c. The front and back of the tunnel are mounted with strobe lights so that when the front or end of the train reaches the end of the tunnel the light flashes.  So we have 4 events (flashes). Event 1:  Front of train enters tunnel. Event 2:  Front of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT