(a) Node reverseWIthoutDynamic(Node node) {
Node prev = null;
Node current = node;
Node next = null;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
node = prev;
return node;
}
// Time complexity = O(N)
(b) Node reverseWIthDynamic(Node node) {
Node newList = null;
Node current = node;
while (current != null) {
Node newnode = new Node(current.data);
newnode.next = newList;
newList = newnode;
}
return newList;
}
// Time complexity = O(N)
(c)
We can find minimum element in O(Logn) using Binary Search.
The minimum element is the only element whose previous is
greater than it. We check this condition for middle element by
comparing it with (mid-1)’th and (mid+1)’th elements.
If minimum element is not at middle (neither mid nor mid + 1), then
minimum element lies in either left half or right half.
If middle element is smaller than last element, then the minimum
element lies in left half.
Else minimum element lies in right half.
ngu Cons eY Ja Question 1 a) Write pseudo code to output a singly-linked list in...
Write a program void reverse_list(list **l)in pseudo-code or C++ to reverse the direction of a given singly-linked list. In other words, after the reversal all pointers should now point backwards. Your algorithm should take linear time. The node of this singly-linked list is defined as typedef struct list { item_type item; struct list ∗ next ; } list; void reverse_list(list **l){ } Remark: 15 points for completely correct. 10 points for correctly reversing the list with minor errors.
Write a Python function to implement the quick sort algorithm over a singly linked list. The input of your function should be a reference pointing to the first node of a linked list, and the output of your function should also be a reference to the first node of a linked list, in which the data have been sorted into the ascending order. (You may use the LinkedQueue class we introduced in the lecture directly in your program.)
Write a method max() which take a generic singly linked list as an argument and returns the maximum element reference in the list. If the list is empty, please throw an empty collection exception. The method prototype is defined as follows. Please write down your code in the method body enclosed in braces: public static <T extends Comparable<T>> T max(SingleLinkedList<T> list) throws EmptyCollectionException { } 2) What is the big O notation of the max method? a) O(N)...
Q.(1)Describe the algorithm and java implementation for the following operations A. Create a singly linked list L1 with 4 nodes. You can use insert operation to add nodes to the list. Each element represent an airport code (e.g. BOS, ATL, JFK, MSP, etc.). Display the list L1 after it is created. B. Given singly linked list L1, create another singly linked list L2 that contains the same elements but in the reverse order. Display the content of both L1 and...
Submit the pseudo code. Write a member function PrintReverse that prints the elements on a list in reverse order. For instance, for the list X Y Z, list. PrintReverse() would output element in the list. You may assume that the list is not empty.
Arrays, Lists, Stacks and Queues: 1) Write C++ code to reverse a singly-linked list L using only a constant amount of additional storage and no recursion. Assume the list object has a head pointer _head and consists of Node objects; a Node object has a pointer Node* _next
IMPLEMENT AN IMMUTABLE SINGLY LINKED LIST IN JAVASCRIPT ------------------------------------------------------------------------------------------------------------------------- So I am trying to implement a singly linked list that given the below function will pass the bottom four tests when ran. Please help me generate the singly linked list that will work and pass the tests. I will only use this as a reference so please add comments to explain what you are doing so I can understand and write this myself. I think a join method may need...
In Java: Assume the "ferrets" variable points to a linked list of "LLNode." Write code that traverses the list and prints the following. Do not forget to consider the case where the list is empty. The "LLNode" class is given: public class LLNode { protected T info; protected LLNode link; public LLNode(T info) { this.info = info; link = null; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode...
Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic singly linked list that can hold any data type. The interface has been specified and provided to you in a header file called mylist.h. So your job is to write mylist.c that implements each function whose prototype is included in mylist.h. Specifically, you are asked to write the following functions: struct Node *addFront(struct List *list, void *data) void traverseList(struct List *list, void (*f)(void *))...
3 Programming Question (45 points) 3.1 Instructions You need to write the code by yourself. Your implementation must use C/C++ and your code must run on the Linux machine general.asu.edu. Please refer to the programming guide (available under the Assignments folder on Blackboard) for using the general.asu.edu server, as well as compiling and running C/C++ code under Linux For this question, you need to provide a Makefile that compiles your program to an executable named a3 that runs on the...