Linked List – Data Structures & Algorithms Tutorials in Python #4




[ad_1]

Linked list is a data structure similar to array in a sense that it stores bunch of items. But unlike array, linked lists are not stored in contiguous memory locations. They are instead chained by an element storing address location of next element. This makes insertion very easy. Also unlike dynamic arrays you don’t have to pre-allocate some memory capacity. In this tutorial we will go through some theory first and then write python code to implement linked list. In the end we have an interesting exercise for you to solve.

Code: https://github.com/codebasics/data-structures-algorithms-python/tree/master/data_structures/3_LinkedList/3_linked_list.py
Exercise Link: https://github.com/codebasics/data-structures-algorithms-python/tree/master/data_structures/3_LinkedList/3_linked_list_exercise.md

Topics
00:00 Introduction
00:18 Issues with arrays that linked list solves
05:54 Doubly linked list
06:37 Big O analysis (array vs linked list)
08:02 Python implementation
26:00 Exercise

#datastructures #algorithms #python

Next Video: https://www.youtube.com/watch?v=ea8BRGxGmlA&list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12&index=5
Previous video: https://www.youtube.com/watch?v=gDqQf4Ekr2A&list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12&index=3
Complete playlist:https://www.youtube.com/playlist?list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12

Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Patreon: https://www.patreon.com/codebasics

Source


[ad_2]

Comment List

  • codebasics
    November 22, 2020

    I implemented remove_by_value method but when I compared with your solution I found that you have used "while itr.next" in the loop. Can you please clarify when we use itr and when we use itr.next?
    My solution:
    def remove_by_value(self, data):
    if self.head is None:
    return
    if self.head.data == data:
    self.head = self.head.next
    return
    itr=self.head
    while itr:
    if itr.next.data == data:
    itr.next=itr.next.next
    break
    itr=itr.next

  • codebasics
    November 22, 2020

    I use Linux no chance of virus 😀

    Great Video Sir

  • codebasics
    November 22, 2020

    the way u explained is superb

  • codebasics
    November 22, 2020

    Thank You for the amazing insights for all the topics you have covered in this playlist. Thanks a lot! Highly appreciate your efforts.

  • codebasics
    November 22, 2020

    You look and talk like Dinesh from Silicon Valley series 😀

  • codebasics
    November 22, 2020

    Hey, thank you very much for this. I have a question: why you can do itr.next? I'll guess that next is the second argument of the Node class, but why can you call it on a variable but not on self.head?
    Thanks!

  • codebasics
    November 22, 2020

    Can we use print user defined function without overloading it?

  • codebasics
    November 22, 2020

    Awesome Job sir Your videos will helps a lot.

  • codebasics
    November 22, 2020

    "Best way to learn something is by teaching it. "
    "One can't teach a subject which he don't understand well."
    Now the thing is you are amazing. And love from Bangladesh.
    Preparing for interviews pray for me.

  • codebasics
    November 22, 2020

    Excellent tutorial! Highly recommended!
    Sir your code for doubly linked list is not completely correct. If you run the method of insert_at_beginning at initial stage when self.head is None then it will not work.
    Instead we can write
    def insert_beginning(self,data)
    If self.head ==None:
    node = Node(data,self.head,None)
    self.head = node
    else:
    node = Node(data,self.head,None)
    self.head.prev = node
    self.head = node

    Thankyou for your lectures sir!

  • codebasics
    November 22, 2020

    Great video thank u so much

  • codebasics
    November 22, 2020

    truly found a gem of channel for upskilling my data structures and algorithms and python skills. you have a long way to go sir.

  • codebasics
    November 22, 2020

    Plz start Java data structure also sir

  • codebasics
    November 22, 2020

    @codebasics can you please correct if my understanding is right in saying that "itr = self.head" this implies that the variable itr is pointing to a data location of the objected created by the Node class..?

  • codebasics
    November 22, 2020

    thank you so much for the well explained video and exercises are the best part.

  • codebasics
    November 22, 2020

    sir please use light mode in py charm. Dark mode is not visible.

  • codebasics
    November 22, 2020

    Sir, Thanks for the video. I have a doubt, inside the insert_at_begining function when we create an object for the Node class, the init function inside the Node class will be called and that will set self.data to None inside the argument right?How will it proceed further?

  • codebasics
    November 22, 2020

    Thanku so much for this video sir 🙏🙏 and its my request please make a video on web scraping by using python 🙏🙏

  • codebasics
    November 22, 2020

    Hi , How does the .next attribute know to store the address without being explicitly told? This has been bugging me for a while, Please help me out

  • codebasics
    November 22, 2020

    I was coding along until at some point it got complex, so I decided to watch the whole thing first..but I dosed while watching..then for some reason I got up towards the end and heard @codebasics say…if you won't practice..forget it, you are wasting your time.. ouch, now I will have to start the video again *slapping my face*

  • codebasics
    November 22, 2020

    Dear Codebasics,

    Thank you for this amasing video. The example shown depicts exactly the theory.

    Nevertheless, I got confused about one major aspect of the code implemented in Python for creating the linked lists.

    I understood that the building block of the Linked List class (LLC) is an iterator containing an instance of a base classe (the class Node).

    In python, I am used to see iterator objects being defined in the body of the user's class. Therefore, I was expecting to have an internal method (i.e.: __iter__) in the Node class. Nevertheless, the provided example does not have it, and yet, the iteration of the Node class occurs nicely within the LLC own methods.

    Why does it happen? Shouldn't a '__iter__' method be defined in the Node class?

    Finally, shouldn't the instance of the Node be deleted/rewrited every time the "LLC.add_at_begining", or the "LLC.add_at_end" methods be called? After all, the LLC is instanciating a new Node in its own "self.head" attribute.

    Sincerely,

    Philipe Riskalla Leal

  • codebasics
    November 22, 2020

    When we remove the element from the list. It is still located at that particular memory right ?

  • codebasics
    November 22, 2020

    The way you teach is really good. Btw I'm also an big fan of Jack fruit.

  • codebasics
    November 22, 2020

    Your monitor too small… plz solve this problem

Write a comment