Kavya Elemati

Kavya Elemati

4 Articles Published

Articles by Kavya Elemati

4 articles

Python Program To Detect A Loop In A Linked List

Kavya Elemati
Kavya Elemati
Updated on 24-Apr-2023 1K+ Views

A linked list is said to have a loop when any node in the linked list is not pointing to NULL. The last node will be pointing to one of the previous nodes in the linked list, thus creating a loop. There will not be an end in a linked list that has a loop. In the below example, the last node (node 5) is not pointing to NULL. Instead, it is pointing to the node 3 and a loop is established. Hence, there is no end to the above linked list. Algorithm Take two pointers fast and slow ...

Read More

Python Program To Get The Middle Element Of A Linked List In A Single Iteration

Kavya Elemati
Kavya Elemati
Updated on 24-Apr-2023 2K+ Views

Linked list is used for storing the data in non-contiguous memory locations. The nodes containing the data items are linked using pointers. Each node consists of two fields. The first field is used for storing the data and the second field contains the link to the next node. Brute Force Technique To find the middle element of a linked list, the brute force technique is to find out the length of the linked list by iterating the entire linked list till NULL is encountered and then the length is divided by 2 to get the index of the middle element. ...

Read More

Python Program To Convert An Array List Into A String And Viceversa

Kavya Elemati
Kavya Elemati
Updated on 24-Apr-2023 312 Views

Converting a list into a string One method for converting a list into a string is to iterate through all the items of a list and concatenate them into an empty string. Example lis=["I", "want", "cheese", "cake"] str="" for i in lis: str=str+i str=str+" " print(str) Output I want cheese cake Using Join Function Join is an in-built function in python which is used for joining the items of an iterable object (ex: list) using a separator which will be specified by the user. We can use the join ...

Read More

Python Program To Add Elements To A Linked List

Kavya Elemati
Kavya Elemati
Updated on 24-Apr-2023 1K+ Views

What is a Linked List When data is not stored in continuous memory locations, it takes a lot of time to search all the memory locations to get the required data. To prevent this, we use Linked Lists. A linked list in Python is a data structure that stores items in an ordered sequence. It consists of nodes, where each node contains the item and a reference to the next node in the list. The first node is known as the head, while the last one is referred to as tail. Linked lists are used for efficient insertion and deletion ...

Read More
Showing 1–4 of 4 articles
« Prev 1 Next »
Advertisements