Close Menu
Technotification
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Technotification
    • Home
    • News
    • How To
    • Explained
    • Facts
    • Lists
    • Programming
    • Security
    • Gaming
    Technotification
    Home › Programming › Creating Singly Linked List in Python Programming Language

    Creating Singly Linked List in Python Programming Language

    By Harshit SatyaseelDecember 3, 2022
    Facebook Twitter Reddit LinkedIn
    python programming

    Data structures and Algorithms are the backbones of computer programming. As a programmer, it is very important to have a good command over them. This article is about what is a Linked list? and implementation of Singly linked list using Python programming language.

    Also Read: Implementation of Dynamic Arrays in Python Programming

    Contents

    • What is Linked Lists?
    • Singly Linked List & its implementation through Python language
    • Basic Operations in the Singly Linked List
      • Push Operation
      • POP Operation
    • Pros and Cons of Singly Linked List
      • Pros
      • Cons
    • Code

    What is Linked Lists?

    Linked List is a linear data structure. Basically, these are the links in a chain that can be very long, and these chains are nodes that together form a linear sequence. The diagram representation is shown below.

    Screen Shot at . . PM

    In a linked list, each node contains two elements i.e a value of any type since it is a kind of an array and reference to the next element in the sequence as shown in the figure above.

    Singly Linked List & its implementation through Python language

    A singly linked list is also a collection of nodes and has a starting point called as HEAD and an endpoint called TAIL.

    • Head is the pointer that simply points or identifies to the first element in the singly linked list.
    • Tail identifies to the last node in the singly linked list and in this case, the reference part of the node points to nothing or nil.

    Screen Shot at . . PM

    This is what a single list liked looks like diagrammatically. Each node has a Key/Value which are strings in the case shown above, and a reference i.e. a next pointer that points to the next element. Basically, the first node is the head and the last node is the tail in the list. The movement from one node to other is called traversal in the list.

    NOTE: A singly linked list does not have a predetermined size so it uses space proportionally according to the number of elements present in the list and unlike arrays, it does not have the contiguous memory allocation i.e. they are not allocated one after another, rather, distributed in memory and attached through pointer that we call the reference part.

    Basic Operations in the Singly Linked List

    There are basically two operations that we usually perform with the singly linked list.

    1. Push i.e. inserting a new element.
    2. Pop i.e. deleting/removing an element from the list.

    Push Operation

    In the push operation, we simply take a new key/value and add that to the existing list. The push operation can be performed in different cases.

    1. Inserting the element at the beginning.
    2. Inserting the element at the end.

    Inserting the element at the beginning

    Screen Shot at . . PM

    Inserting the element at the end

    Screen Shot at . . PM

    POP Operation

    The removal of an element from the head of the list is the opposite process of insertion of elements at the head side but, deletion of the last node is a tiresome operation and it is not an easy task. You must be wondering Why?

    Well, suppose there is a singly linked list containing 20 values and we want to delete the last element, in that case, we have to traverse to the last node then only we can delete it, and this is not an efficient method. In Computer Science, solving a given problem with efficiency is a major concern and the above-described traversal method is not the proper solution we can go for.

    Pros and Cons of Singly Linked List

    Pros

    • They have constant time insertion and deletions in any case.
    • Its size is not fixed and is flexible

    Cons

    • The accessibility of the elements in the linked list is not easy and is a lengthy process and the time in the form of Big O notation is given by O(k) for traversal from head to the (kth) element of the list.

    Code

    You can use any text editor and try out this code.

    Screen Shot at . . PM

    OutPut:

    Screen Shot at . . PM

    For a detailed study, review and practice problems, you can check out this course:  Complete Python Bootcamp: Go from zero to hero in Python on Udemy.

    Share. Facebook Twitter LinkedIn Tumblr Reddit Telegram WhatsApp
    Harshit Satyaseel
    • Website
    • LinkedIn

    Research Intern, INSA Rouen | Technical Writer, Self-learner and Tech exuberant person.

    Related Posts

    The Best Python Libraries for Data Visualization in 2025

    April 1, 2025

    Is C++ Still Relevant in 2025 and Beyond?

    February 20, 2025

    5 Best Programming Languages for Machine Learning in 2025

    February 18, 2025

    10 Must-Have Chrome Extensions for Web Developers in 2025

    February 17, 2025

    Difference Between C, C++, C#, and Objective-C Programming

    February 16, 2025

    How to Learn Programming Faster and Smarter in 2025

    February 14, 2025
    Lists You May Like

    5 Best Torrent Sites for Software in 2025

    January 2, 2025

    10 Best Torrent Search Engine Sites (2025 Edition)

    February 12, 2025

    10 Best RARBG Alternative Sites in April 2025 [Working Links]

    April 1, 2025

    The Pirate Bay Proxy List in 2025 [Updated List]

    January 2, 2025

    10 Sites to Watch Free Korean Drama [2025 Edition]

    January 2, 2025

    10 Best Torrent Sites for eBooks in 2025 [Working]

    January 2, 2025

    10 Best GTA V Roleplay Servers in 2025 (Updated List)

    January 6, 2025

    1337x Alternatives, Proxies, and Mirror Sites in 2025

    January 2, 2025

    10 Best Anime Torrent Sites in 2025 [Working Sites]

    January 6, 2025

    15 Best Wallpaper Engine Wallpapers in 2025

    January 6, 2025
    Pages
    • About
    • Contact
    • Privacy
    • Careers
    Privacy

    Information such as the type of browser being used, its operating system, and your IP address is gathered in order to enhance your online experience.

    © 2013 - 2025 Technotification | All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.