This video is unavailable.
Sorry about that.

Data Structures: Arrays vs Linked Lists

Share
Embed
  • Published on Apr 2, 2013
  • See complete series on data structures here:
    thexvid.com/p/PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P
    In this lesson we will compare arrays with linked lists based on various parameters and understand the cost of various operations with these data structures.
    Lessons on big-oh notation can be found in these series on time complexity:
    thexvid.com/p/PL2_aWCzGMAwI9HK8YPVBjElbLbI3ufctn

Comments • 171

  • sl Test
    sl Test 12 days ago

    Thank you very much for all the videos!!
    I have a question, in the linked list, inserting an element at the end and at ith position should be O(1), isn't it? Because only pointers need to be changed..? Only access to elements at the end and at ith position would be O(n)?

  • Kalyani ‘s Kitchen
    Kalyani ‘s Kitchen 28 days ago

    Isn’t deleting the last element in the array always constant time O(1)? We never have to resize the array or shift any elements

  • Konduru Bharath
    Konduru Bharath Month ago

    does a pointer variable require 4 bytes here..?? I heard from some sources that any pointer variable irrespective of the data type consumes 8 bytes..isnt this correct..???

  • Tanmay Kumar
    Tanmay Kumar Month ago

    he has the best playlist on linked list

  • aaron balthaser
    aaron balthaser 2 months ago

    Why is adding a node to the end of the list O(n)? If you maintain a tail you can add nodes to the list in constant time no different than added to the head. I have seen many implementations with both head and tail. Is a linked list with a tail not a valid implementation?

  • arfat inamdar
    arfat inamdar 2 months ago

    Very well explained, but subtitles are irritating a lot

  • Helping Hand
    Helping Hand 2 months ago

    I have a question, lets say in the linked list, if we keep the address of the last memory block then we can save the time of traversing the linked list by O(n) and it can be achieved in constant time.What about this? @mycodeschool

  • stillFLiP
    stillFLiP 4 months ago

    So, linked lists are better the larger the data is, right? For example dealing with strings, specially if you need to add new ones at the start, i.e. todo list.

    • Peterolen
      Peterolen 3 months ago

      Some kind of array-based data structure is often best.

  • Mayukh Biswas
    Mayukh Biswas 4 months ago

    one doubt. If we store the start and end nodes in separate pointers, then adding a new element at the end should take O(1), shouldn't it?

    • bipin singh
      bipin singh 3 months ago

      to Reach the end node in Linked List you have to start from head and reach till tail (Traverse across the list ) , so the time complexity is O(n)

  • Cindy Shi
    Cindy Shi 4 months ago

    So tremendously helpful. Thank you so much!

  • Fatima Kashif
    Fatima Kashif 4 months ago

    oop java pey karain ye program linklist k programs

  • Drumpf Cheeto
    Drumpf Cheeto 4 months ago

    IN-TEE-YERS

  • Abdelghani Draoui
    Abdelghani Draoui 4 months ago

    Awesome course thanks for sharing !

  • Alireza Ghodsipoor
    Alireza Ghodsipoor 6 months ago +6

    I can watch your videos as a movie and not get bored :) Awesome!

  • Ayeman Bin Salauddin
    Ayeman Bin Salauddin 6 months ago +1

    amazing, i am preparing for googles kickstart.
    btw im 15 and python programmer ,web developer.

  • ahmed zahid
    ahmed zahid 6 months ago

    Thanks sir well done job

  • Sakshi Soni
    Sakshi Soni 8 months ago +1

    Can someone tell me that these videos are helpful for the gate (for data structure) preparation or not?

  • Jakub Lorenc
    Jakub Lorenc 9 months ago

    i think deleting at the end of array is O(1), not O(n) so deleting times are not the same

  • Aritra Das
    Aritra Das 10 months ago +7

    The way you explain, I could listen to these videos for hours and not get bored. Absolutely mindblowing content man, keep doing the good work.

  • Belal Abdulnasser
    Belal Abdulnasser 11 months ago

    Good explanation, I think you have error at the point of adding item in the end and middle of linked list

  • Toufique Hasan
    Toufique Hasan 11 months ago

    Apne liKh rhe aur khud samj rhe ho

  • Shadow Monarch
    Shadow Monarch 11 months ago

    dude,you basically just saved me my whole semester studying with difficult lecture before,now all is ez

  • Nagalakshmi Duvvuri

    These are very helpful, Thanks so much for making the videos

  • AdiTya Dev
    AdiTya Dev Year ago

    awesome

  • Amit Chhetri
    Amit Chhetri Year ago

    Why do we always write as
    Struct Node {
    int data;
    Node* next;
    }
    and not as
    Struct Node {
    int data;
    int* next;
    }
    What difference does this make?

    • Adarsh Todi
      Adarsh Todi 7 months ago

      (1)Node* next basically means a pointer next to a type of Struct Node.
      (2) int* next means a pointer next to a type int.
      The second implementation is completely wrong as we need a pointer to a next node(comprising of data and next pointer) and not an int type.

  • Samvit Agarwal
    Samvit Agarwal Year ago +1

    Hey this was a great video! Since I use Python, which uses dynamic arrays(arrayLists) by default, could you explain how exactly these work and the time/space complexity for these? Thanks

  • John Rhaenys
    John Rhaenys Year ago

    The time complexity to insert an element at the end of the linked list is O(n), since we only have the reference to the head and we have to traverse it until we get to the end of it. However, if we add another pointer that points to the last element of the list, the insertion at the end will be O(1), constant time. That being said, is it a good trade to use 4 more bytes to store the memory address of the last element and get a faster insertion?

  • Usama Iftikhar Butt

    thank u sir for such an amazing playlist

  • aditya verma
    aditya verma Year ago

    hi what about self referential pointers in a structure what amount of memory would they take?

  • Xavy Aly
    Xavy Aly Year ago

    can we get the same ppt in my mail id please: wellboy.alam13@gmail.com

  • KV M
    KV M Year ago

    Can't appreciate your videos enough. Following it religiously for my data structures journey. I have a question. seeing the comparision though, I don't see any good benefit of linked list at all. Mostly it is either comparable to arrays or it falls behind arrays and yeah, implementation is more time consuming and hard as well. Then why do we even use it? Just for one case of inserting at beginning where it scores better? Arrays are almost better or at par I mean! Sure we can compromise that one case. Memory these days should be not be an issue. So just why???

    • KV M
      KV M Year ago

      After my research, I feel very fine grain control over memory ( dynamic memory and implementation of stacks and queues ought to be the reason for it. Otherwise insertion and deletion are easy but have same time complexity.

  • MURALI KRISHNA
    MURALI KRISHNA Year ago +2

    The way you are teaching is superb and do you have pdf version or any other format notes for quick revise.thanks...;

  • ronald abellano
    ronald abellano Year ago +6

    I dont get the Memory requirements part. How does Linked List consume lot less memory if it uses more memory because of its pointer?

    • Amar bhardwaj
      Amar bhardwaj 3 months ago +3

      Because there is no unused memory in linked list.

  • ronald abellano
    ronald abellano Year ago

    Im confused. How does the array win over linked list in time complexity for accessing its elements?
    Linked List node uses its next pointer and how about array? How does array access its elements if Linked List always starts at the head?
    What are the operations for array if Linked List is Head links to next node? Head.Next

    • confidential303
      confidential303 6 months ago

      Array is simple, you know the size of an array.. if you want to read the 10th element, you just calculate begin memory address(200) + 10*(x bytes ..for int..we assume x=4)= 200 +40= so 10th element is at memory location 240.
      with linked list, you have to cycle through 10 times to get your memory address.., now the question is now the question is how long does 1 step take. In my opinion arrays wins almost in performance. since memory operations are slow..

  • Sambit Pati
    Sambit Pati Year ago

    please make videos on GATE entrance for computer science branch

  • Archit Atrey
    Archit Atrey Year ago

    Sir make a video on unrolled link lists

  • Youyi Liu
    Youyi Liu Year ago

    NEW BOOK: The Art of War by Sun Tzu, the first copy in the world to have those ancient words correctly reflected. Read it and get the job done!
    www.amazon.com/ART-WAR-Sun-Tzu/dp/1521303002/ref=sr_1_1?ie=UTF8&qid=1526481164&sr=8-1&keywords=the+art+of+war+Youyi+Liu
    Chinese-English version
    www.amazon.com/ART-WAR-Sun-Tzu/dp/1521311838/ref=sr_1_1?s=books&ie=UTF8&qid=1526481967&sr=1-1&keywords=youyi+liu+the+art+of+war

  • Akhil Jain
    Akhil Jain Year ago

    These videos are really helpful. You are doing a great job.!!!!! Please keep making more such videos.

  • Ashwin Karthikeyan

    All these videos on data structures are very useful. Thanks a lot. But can you upload videos of OOP using JAVA too please.

  • saurav yadav
    saurav yadav Year ago +1

    Your videoes are great. very useful for weak students like me .

  • Yashkirat Singh
    Yashkirat Singh Year ago +3

    When insetring an element at the end of a linked list why we will be needed to traverse whole memory.
    It can be done by changing the last pointer.

  • Aqib Mulla
    Aqib Mulla Year ago

    Hello bro plz remove that text when u speak it's not visible to us to note it down .
    Thanks

    • Tirth Patel
      Tirth Patel 4 months ago

      It's captions, u can turn it off from options.

  • Arghyadip chakraborty

    Sir please remove subtitles ..with the subtleties it's more difficult to read what you are writing at the time of teaching.

  • Sanket Ray
    Sanket Ray Year ago

    I have question....I dont really understand what he says regarding Arrays. He says that Arrays have a fixed length and we need to specify them in the beginning? I use Swift to code. We don't specify number of elements while initializing. Array can be initially empty and you can perform any logic you want. Am I missing something? Someone please clarify :(

    • Sanket Ray
      Sanket Ray Year ago

      oh...thanks for answering

    • ANKUR SATYA
      ANKUR SATYA Year ago

      The arrays referred to in the above video is the data type as used in C++. Different languages may have different data types. The data type you are referring to in Swift is also present in C++ but under the name "Vector".

  • Shivraj Sharma
    Shivraj Sharma Year ago

    4:10 ....why the time complexity in avg case is given as n instead of n/2

    • Peterolen
      Peterolen Year ago

      Constant factors are ignored so O(n/2) = O(n)

    • John
      John Year ago

      Worst case scenario. Also, 1/2 becomes insignificant. I think

  • Dhruv garg
    Dhruv garg Year ago

    awesome!! really well explained, but what about dynamic array or vector in c++

  • Larissa Ford
    Larissa Ford Year ago

    I thought arrays had O(n) and not O(1)? because isn't big-O concerned with worst case scenarios where we may have to iterate through the entire array before finding our element, and would thus need n-time for an array of size n? I thought this because I understood hash tables to be special because they had a faster run-time than arrays, having a general case of O(1) run-time. Am I mistaken somewhere in there? Thanks for the amazing lecture!

    • Larissa Ford
      Larissa Ford Year ago +4

      oh wait, it would be constant time if we knew ahead of time where in the array (which index) an element is found. I think my question is still valid in terms of finding an element, but is that not what big-O is concerned with? is big-O concerned only with look up for a particular known element?
      *EDIT* gosh, I missed the part that said "Cost of accessing an element". this all makes sense now.

  • Suman Chakrabarti

    This is honestly better than watching the MIT presentations. Thank you!

  • Jayanth Ram K.V
    Jayanth Ram K.V Year ago +10

    Inserting node at end of linked list would be constant time if we have tail pointer!

    • Dillon Cote
      Dillon Cote 7 months ago

      @Nuril Ahmed Tail pointers are optional and can be made the same way as a head pointer. He just didnt use it in the video.

    • Nuril Ahmed
      Nuril Ahmed 7 months ago

      But why is there no tail pointer?

  • Jonathan H
    Jonathan H Year ago

    thanks!

  • Jaider Ariza
    Jaider Ariza Year ago

    The cost of inserting an element at the end 10:24 could be a constant O(1) if you use doubly linked list :)

  • Vishwjaeet Singh
    Vishwjaeet Singh Year ago +3

    mycodeschool you're the best

  • Venkataraghavan Yanamandram

    Thank you for the great explanation!! I'd a doubt on linked list, when we insert a data at the end of linked list or in between linked list the time consumption is proportional to O(n). I thought however we're going to add it and just have to change the address of last one O(1). but we've to iterate from the first to find the tail node address so it comes to O(n) am I right?

  • nikhil gaikwad
    nikhil gaikwad 2 years ago

    Nice explains

  • Ayush Gupta
    Ayush Gupta 2 years ago

    well explained

  • KISHLAY SINGH
    KISHLAY SINGH 2 years ago

    is this is a movie if not then why hell hell is subtile here ..

    • Peter Fish
      Peter Fish 2 years ago +1

      So people can easily understand what he is saying. Some people are hearing impaired, and others struggle with his accent.

  • Abhijeet Saxena
    Abhijeet Saxena 2 years ago

    What's the time complexity of deletion at i'th position in a linked list?

  • vijay pawar
    vijay pawar 2 years ago

    awesome explanation

  • SONALI PUROHIT
    SONALI PUROHIT 2 years ago

    Can you make a video on how to calculate address of 3-d array?

  • Radhieka Nagpal
    Radhieka Nagpal 2 years ago

    Easy to understand and quite precise in flow of learning. Amazed.