answersLogoWhite

0


Best Answer

In a linked list, there is no way to find the "min element" or any other element with a specific property except by walking through the entire list. Of course, you could store a pointer to the min element and update that each time the list changes (add ing or deleting an element), which makes the list less generic and a tiny bit slower but is worth it if you need this min element often.

Pseudocode for finding the min element (I'm assuming you're storing values and you want the element with the lowest value):

ptr_minelement = null;
ptr_element = ptr_firstelement;
while (ptr_element != null) {
if (ptr_minelement == null) or (ptr_minelement->value > ptr_element->value)
ptr_minelement = ptr_element;
ptr_element = ptr_element->ptr_next;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm for finding min element in a linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

3 Write the algorithm of inserting an element at middle of a linked?

theory part to how u can insert element at middle of link list ?


An algorithm of deleting linked list?

To delete a linked list walk through the list and delete the memory allocated to each element, remembering the next element address, and then iterating or recursing the process using the next element address, until the next element address is null.


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Write an algorithm to search an element in linked list?

To search for an element in a linked list, you iterate the list, looking for the element, and either return the element or an indication that it was not found. for (ptr = first; ptr != null; ptr = ptr.next) if (ptr.value == searchvalue) break; This will either leave ptr with the address of the found element, or null, if not found.


What is the worst case running time of algorithm to delete each element from the linked list?

Linear time. O(n).


How to write an actual algorithm for inserting an element in a linked list?

Insert newNode into a linked list after targetNode Node currentNode = root while currentNode != targetNode currentNode = currentNode.next newNode.next = currentNode.next currentNode.next = newNode


What is the difference between linked list and Ordinary list?

A list is an abstract data structure, usually defined as an ordered collection of data. A linked list refers to a specific implementation of a list in which each element in the list is connected (linked) to the next element.


Which algorithm is efficient for finding an element from a sorted list?

Basically you split the list in two, looking at the element in the middle of the list. If the list is in ascending order, and the element you are looking for is SMALLER than the element in the middle of the list, you repeat this procedure for the FIRST half of the list (again, splitting it in two); if it is LARGER, you repeat for the SECOND half of the list.


Write a algorithm for doubly linked list in c?

sorry


what are the various operations in linked list which can be performed on linked list?

Some common operations that can be performed on a linked list include inserting a node, deleting a node, searching for a specific node, traversing the list, and updating a node's value. Other operations may include reversing the list, merging two lists, sorting the list, and finding the length of the list.


Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.


What is the linklist?

A circular linked list is just a linked list in which the last element of the list is connected to the first element, so if you followed the links, you'd be following them in a circle forever.