Arrays - Data Structures & Algorithms Tutorials in Python #3

Sdílet
Vložit
  • čas přidán 9. 06. 2024
  • Arrays are most commonly used data structure in any programming language. In this video we will cover what arrays are using python code, look at their memory representation and also cover Big O analysis for various operations such as look up using index, lookup using value, array traversal etc. We will also see difference between static and dynamic array. In the end I've an exercise for you to solve. Here is the link for exercise:
    Exercise: github.com/codebasics/data-st...
    Topics
    00:00 Introduction
    00:15 Array introduction
    03:26 Big O Analysis
    08:03 Static vs Dynamic Array
    13:02 Exercise
    #arrays #pythonarrays #arrayspython #arraysdatastructures #array #arraydatastructure #datastructures #algorithms #python
    Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
    Next Video: • Linked List - Data Str...
    Previous video: • Big O notation - Data ...
    Complete playlist: • Data Structures And Al...
    🌎 My Website For Video Courses: codebasics.io/?...
    Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
    #️⃣ Social Media #️⃣
    🔗 Discord: / discord
    📸 Dhaval's Personal Instagram: / dhavalsays
    📸 Codebasics Instagram: / codebasicshub
    🔊 Facebook: / codebasicshub
    📱 Twitter: / codebasicshub
    📝 Linkedin (Personal): / dhavalsays
    📝 Linkedin (Codebasics): / codebasics
    🔗 Patreon: www.patreon.com/codebasics?fa...

Komentáře • 295

  • @codebasics
    @codebasics  Před 2 lety +10

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

    • @101aayush4
      @101aayush4 Před 11 měsíci

      Another Correction I would like to tell:
      When we inserts more elements it's size increase twice only!
      Not 3 times as you said....eg. if 5 is initial capacity then it's final Total capacity would be 10 not (5+10)!

  • @codebasics
    @codebasics  Před 3 lety +69

    Minor correction: At 7:36 the slide should be stock_prices.remove(305) The argument is the actual element that you want to remove and not the index.

    • @ch.prashantnagar7514
      @ch.prashantnagar7514 Před 3 lety +3

      At 7:36

    • @suhasbn44
      @suhasbn44 Před 3 lety +2

      It would’ve been better if the syntax was similar to insert with the position and the value or at least the position. This is because, there may be multiple 305 values and we may want to remove the second instance.

    • @sameershaikh-lb8yp
      @sameershaikh-lb8yp Před rokem +2

      @KAMYA SINGHI pop takes no argument right? it simply removes the last element from the list. We can use del stock_prices[1] to remove element from index 1

    • @hrushikeshkulkarni7353
      @hrushikeshkulkarni7353 Před rokem

      That's what I thought 😅

    • @101aayush4
      @101aayush4 Před 11 měsíci

      Another Correction I would like to tell:
      When we inserts more elements it's size increase twice only!
      Not 3 times as you said....eg. if 5 is initial capacity then it's final Total capacity would be 10 not (5+10)!

  • @manishitadey6218
    @manishitadey6218 Před 2 lety +90

    list.remove() uses value rather than index. To delete value by index use pop() or del(). Just a small correction. Great video! Helps a lot.

  • @lipsapatro2353
    @lipsapatro2353 Před 2 lety +4

    I am from absolute non-tech background switching my field to tech field(data analytics) and your videos are the greatest help in my learning journey thank s you so so much.

  • @c0nsumption
    @c0nsumption Před 2 lety +2

    Just finished this one, very solid teaching skills. Blessing 🙏🏽 Thank you for sharing this information so professionally

  • @tharindusathsara3414
    @tharindusathsara3414 Před rokem +3

    Really very happy about finding such an obvious and understood funny video series about data structures and algorithms. Everything is 100% clear with deeply explained theories and well-understood practicals. Also, the exercise series with the videos are highly appreciated. Dear sir thank you so much for the fantastic video series. ❤💖

  • @sejalanand23
    @sejalanand23 Před 2 lety +37

    Listening to you makes me feel I can learn everything. You are really blessed with the art of teaching and we are blessed to have someone like you. 😇
    Please make more DSA videos.

  • @alishakatyayani7910
    @alishakatyayani7910 Před 3 lety +5

    I have read this many times but never got it , this is so precise and simple. Thanks a lot for providing such good content and that too for free

  • @sachinladhad5463
    @sachinladhad5463 Před 2 lety

    Dear Dhaval Sir,
    Your teaching methodology is very simple, it helps in understanding quickly and it gets registered in Mind permanently

  • @sushil1200
    @sushil1200 Před 3 lety +3

    Thanks codebasics. This is perfect tutorial for Data Structures and Algorithms.

  • @sourabhpatil4002
    @sourabhpatil4002 Před 3 lety +9

    I am Non-CS background and struggling to learn data structures. But I am found it very easy and simple because of this playlist. Thanks a lot for playlist, Sir

    • @codebasics
      @codebasics  Před 3 lety

      Sourabh I am glad it was helpful 😊👍

  • @kapzb
    @kapzb Před 3 lety

    Ultimate Clarity, Hats off and thank you 👍

  • @nadimhayat3412
    @nadimhayat3412 Před rokem

    such an impressive way of explanation! Thank you for these tutorials

  • @satyaprakash4598
    @satyaprakash4598 Před 4 lety +1

    Great sir
    Simply you are all-rounder and awesome

  • @hrushikeshkulkarni7353

    Such easy explanations and such awesome content... Thank you ! May God bless you 😇

  • @meralmaradia4774
    @meralmaradia4774 Před 2 lety

    sir, you explain in very strait forward manner, thanks,

  • @vrushaliprakashsalvi6167
    @vrushaliprakashsalvi6167 Před 2 lety +24

    best tutorial ....tired finding some tutorials and I literally cried because of happiness when I found this....🥺 well explained ....no need to study extra interview questions when we are clear with the concept well....😊

  • @pervezansari9533
    @pervezansari9533 Před 4 lety +13

    Simply perfect: Thank you very much for your great presentation. This helps a lot!!

  • @sepehrnem9773
    @sepehrnem9773 Před 3 lety

    Thanks for the great teaching! You're amazing!

  • @haris1558ssss
    @haris1558ssss Před 4 lety +2

    Great explanation and tutorial. Thank you very much. :)

    • @codebasics
      @codebasics  Před 4 lety +1

      Glad to hear that. I hope you are doing enough practice for the subject.

  • @allencymba6207
    @allencymba6207 Před 2 lety +3

    thank you very much, sir, I learned a lot in your video. that's my code below.
    exp = [2200,2350,2600,2130,2190]
    month = ["janaury","February","March","April","may"]
    data=dict(zip(month,exp))
    print(data)
    print("extra dollars spented:", exp[1]-exp [ 0] )
    print("total expensise in first quarter:", exp[0]+exp[1]+exp[2])
    data["june"]= 1980
    print(data)
    print("Did i spent 2000 in an Month:", 2000 in data)
    exp[3] = exp[3]-200
    print("What you get after $200 returned in the month of April:", exp[3])

  • @devankdhingra7419
    @devankdhingra7419 Před 3 lety +1

    Amazing work sir. And really liked your idea of giving exercises at the end of the video. That excercise helped me a lot.

  • @siddhigolatkar8558
    @siddhigolatkar8558 Před 3 lety +1

    Thank you so much for this playlist

  • @kiplimocollins
    @kiplimocollins Před 2 lety

    Thank you so much, you're a great teacher.

  • @mohit7717
    @mohit7717 Před 3 lety

    Great you describe many concept in much simpler way, Thank you so much.

  • @subhasreegupta3937
    @subhasreegupta3937 Před 3 lety +1

    One of the best tutorial ever....thanks for guiding us...

  • @Hariom_143-
    @Hariom_143- Před 2 lety

    Adding exercise in the last is very helpful..thank you ❤

  • @cusatankur296
    @cusatankur296 Před 3 lety +3

    Great video. Memory management taught is great. Please continue to provide us with awesome content.

  • @sheikhakbar2067
    @sheikhakbar2067 Před 2 lety

    Wonderful series of lessons.

  • @ThaoPhuong-ln9vc
    @ThaoPhuong-ln9vc Před 2 lety

    Thank you for providing all these contents for free!

  • @Ankurkumar14680
    @Ankurkumar14680 Před 4 lety

    Very informative sir, thanks a lot for sharing :)

  • @brannstrom12
    @brannstrom12 Před rokem

    Thank you so much sir for this wonderful class.

  • @rakibmarak3493
    @rakibmarak3493 Před 3 lety

    Thank you so much sir for this exceptional tutorial playlist.

  • @simarjitkaur2864
    @simarjitkaur2864 Před rokem

    Thankyou very much... very well explained

  • @binuvarghese5507
    @binuvarghese5507 Před 2 lety +2

    Thank you for the great tutorial. I tried all exercises and I could write the solution 3 using list comprehension. Not at all a big thing but it is after a very long time that I am writing a programing code. It increased my confidence. Thank you for the exercise.

  • @moviehack4377
    @moviehack4377 Před 4 lety +1

    Great way of learning Data Structure .. thanks @codebasics

  • @ArshdeepSingh-nc3qk
    @ArshdeepSingh-nc3qk Před 3 lety +2

    May I know which book u used for understanding these concepts, and if u can tell any book for DSA in "PYTHON".

  • @danishuddin9752
    @danishuddin9752 Před 2 lety

    wow this is so clear.Thank you.

  • @gregoryogunna9527
    @gregoryogunna9527 Před 11 měsíci

    Thank you for the explanation.

  • @CreativeMastery
    @CreativeMastery Před 3 lety

    Thank you for the great presentation, just one suggestion though the exercise is more amazing if you manipulate data in 2D arrays

  • @vaishalilutade
    @vaishalilutade Před 2 lety

    Must watch series!!!

  • @grimmetal2802
    @grimmetal2802 Před 7 měsíci

    This was a pretty good lesson. Thank you.
    Edit: Also the practice was great.

  • @flovous
    @flovous Před 3 lety

    This is very useful, thank you!

  • @jayanthkoneru7523
    @jayanthkoneru7523 Před 2 lety

    wonderful series...can you plz add more tasks? addicted to your channel

  • @bechirelhosni9646
    @bechirelhosni9646 Před 3 lety

    Thank You very Much for this video. I foud it very helpful. Next Month i'll start my first class in Data Science Master.

    • @codebasics
      @codebasics  Před 3 lety

      Wish you all the best for your class bechir ☺️👍

  • @adipurnomo5683
    @adipurnomo5683 Před rokem

    Such clear explained

  • @tanyipeng3440
    @tanyipeng3440 Před 3 lety +2

    Instructor can I ask u a question? Shouldn't the hexadecimal representation be like 0x00500 and then 0x00520 as 4 bytes is 32 bit and it is represented by a 2 increase and the 2nd from last value

  • @BoltzmannVoid
    @BoltzmannVoid Před 3 lety

    ah man you are beyond great keep going!

  • @srbm
    @srbm Před 2 lety +2

    Excellent knowledge, but in this 1st exercise can we do with set function especially adding an element, or Q4, 5

  • @anjalinaik2844
    @anjalinaik2844 Před 3 lety +2

    I used dictionaries for solving this,
    Felt good :) One step a day :)
    Thank you

  • @oren9rimer
    @oren9rimer Před 3 lety

    thank you so much, great videos!

    • @codebasics
      @codebasics  Před 3 lety +1

      I am happy this was helpful to you.

  • @muhammadumarsotvoldiev9555
    @muhammadumarsotvoldiev9555 Před 11 měsíci

    Thank you very much!

  • @ashwinirai.18
    @ashwinirai.18 Před 3 lety

    Thank you sir.
    Your video helps me a lot.

  • @udaykirangarlapatti1622
    @udaykirangarlapatti1622 Před 5 měsíci

    Excellent Explanation
    Tq

  • @kassimolawale4223
    @kassimolawale4223 Před 3 měsíci

    Thank you very much sir

  • @cseshahriar
    @cseshahriar Před 2 lety

    Excellent😀

  • @muatafaalahmid7467
    @muatafaalahmid7467 Před 4 lety

    Great work thanks

  • @ashishnegi3848
    @ashishnegi3848 Před 2 lety

    Sir, at 4:28, what if the list contains different types of data like float, int, and string. Then how is the address calculated? Does it internally call type() on every element in the list and then use the sizeof function accordingly.

  • @sandhyap3096
    @sandhyap3096 Před 2 lety

    Nicely explained

  • @zulfiqarali-zq1rg
    @zulfiqarali-zq1rg Před 3 lety

    very interesting and nice exercise questions thx sir

  • @FRehan-pe8ww
    @FRehan-pe8ww Před 3 lety +4

    the solutions link to the excercises have been expired
    please check sir and update

  • @erinwolf1563
    @erinwolf1563 Před 4 lety

    Thanks a👍lot sir...it will be great if you add more assignments

    • @blaiserodrigues2990
      @blaiserodrigues2990 Před 4 lety +1

      Once you have solved the assignment go to leetcode and solve more problems related to arrays.

  • @ARTICFR0ST
    @ARTICFR0ST Před 10 měsíci

    What would the runtime be if instead of using a for loop to find an element we use pythons in? If we want to find value 300 in array, we can use if 300 in arr: ... We can then print that items index with arr.index(300) or print false if item not in array. Would this still be linear time or constant?

  • @amandaahringer7466
    @amandaahringer7466 Před 2 lety

    Excellent!

  • @harshalbhoir8986
    @harshalbhoir8986 Před rokem

    Thank you so much

  • @uroojkhan8599
    @uroojkhan8599 Před rokem

    @codebasics sir please continue the series, it's a request i am following your playlist for python DSA it's really helpful. Please also add after recursion that is of dynamic programming and all rest data structure

    • @TheRailHub
      @TheRailHub Před rokem

      how much dsa this playlist has already covered?

  • @quentincazuc7494
    @quentincazuc7494 Před 3 lety

    Hi, I just finished you exercise. But I have some questions. Could you explain the third part of this exercise ? I don't understand the function.

  • @puranjitsingh1782
    @puranjitsingh1782 Před 2 lety

    Amazing video, As you explained that a number is stored in 4 different containers during storage on RAM. I had a quick question that how are the numbers stored when they have a negative value? how is the negative sign initialized or defined during storage (I believe that the number is stored as its 2's complement in the RAM, is it right, if yes you could include that too in your video)

  • @manishanj123
    @manishanj123 Před 3 lety +1

    For removing the array element it's not the index you might want to correct the video too'... if you want to use the index you might want to go with pop instead. Not nitpicking but I'm a huge fan, sir. what you do is a great inspiration.

  • @ifthikaralia8524
    @ifthikaralia8524 Před 2 lety +2

    Thank you so much, You are a great Teacher.
    Till now, I thought that insert operations is O(1) since we are doing one operation that too for specific index, after watching this video only I learnt that whole memory is swaped because of this one opertion.
    Thanks you so much.

  • @lllbenderlll
    @lllbenderlll Před 3 lety

    Good day.
    12:20 C/C++ can store unusual data types in one array/list/tree/vector/etc. But of course, it cannot be happening without tricks. For example, you actually can store an array with a structure that contains some [void*] pointer and the element that describes the contents of the pointer (I mean what is this and how can I do [...(struct some_name*) ptr; ...] ). This code/example is normal for the Linux Kernel. But of course, it is really inconvenient. REALLY!!!
    But newer, the less - good videos, my friend.

  • @meralmaradia4774
    @meralmaradia4774 Před 2 lety

    so here in the python case as it has no static array concept, everytime when a new element is added in the existing list[] it may be possible to reallocate entire list in new memory segment if nearby slot is not available ?

  • @RavinderSaluja
    @RavinderSaluja Před 3 lety +1

    @codebasics Can Tuples in Python be called static arrays?

  • @Januswizard
    @Januswizard Před 3 lety

    3:36 the address of the 301 and 292, in hexadecimal should be 0x0050C and 0x510, correct? Not 50A and 50F?

  • @lakshmanmaddi3763
    @lakshmanmaddi3763 Před 2 lety

    I am also non CS. Your videos are of great help. Please suggest good books on data stuctures and algorithms in python. Aspiring to become data analyst.

  • @GamersArena123
    @GamersArena123 Před 3 lety +1

    Sir Please make a series on Algorithms in python

  • @maulikmadhavi
    @maulikmadhavi Před rokem

    At 5:30, Just in case when we have mixed type data in the list, e.g. list_mixed = [1, 'a', 2, 'b', 3, 'c'], think the lookup complexity is not O(1)? Please correct if I am wrong

  • @arwayusuf79
    @arwayusuf79 Před 2 lety

    In min 3:19 Could you please explain why we assigned location addresses of last two numbers in the list with 0x0050A and 0X0050F? If we give every number four bytes it should be 0X0050C for the first and 0x00510 for the second ? or I did I it wrongly?

  • @indominous1750
    @indominous1750 Před 3 lety

    You are really good in explanation !!

    • @codebasics
      @codebasics  Před 3 lety +1

      Glad it was helpful!

    • @indominous1750
      @indominous1750 Před 3 lety

      @@codebasics You should make a course on udemy or Coursera or EDX!!

  • @ashfakahamed3451
    @ashfakahamed3451 Před 2 lety

    Grate work sir

  • @siddharthdedhia11
    @siddharthdedhia11 Před 3 lety

    Can you explain why is insertion at the end of the dynamic array constant time a.k.a 0(1)

  • @vigneshm7462
    @vigneshm7462 Před 3 lety

    Sir in python it is said that we store the address of each value in a contiguous manner and the value will be stored elsewhere when we access it using index we are actually accessing it through address of the value is it true?

  • @joyguha7944
    @joyguha7944 Před 2 lety

    very informative playlist

  • @sakalagamingyt3563
    @sakalagamingyt3563 Před rokem +1

    Thanks

  • @mohammadkazemsadoughi3880

    Great video. Quick check: remove method should remove element by value, not index.

  • @hamzaqadri5772
    @hamzaqadri5772 Před 4 lety +4

    In 2d array we create stock prices of 1year✨

  • @hkrish26
    @hkrish26 Před 4 lety

    Thanks sir...

  • @ankitshaw2011
    @ankitshaw2011 Před 3 lety

    Awesome tutorial sir

  • @karthikbs8749
    @karthikbs8749 Před 2 lety

    Sir after the new memory created and the old values are copied to the new memory will the old memory be cleared?

  • @tanyipeng3440
    @tanyipeng3440 Před 3 lety +2

    shouldnt the delete part be del stock_prices[1] instead of stock_prices.remove(1) as remove deletes the element by value?

  • @hamzaqadri5772
    @hamzaqadri5772 Před 4 lety +1

    Sir I have question with u in dynmaic array 'x' size of array full then. We insert element it will make '2x' size of array in New memory location then copy x array into 2x size of array after that 'x' array is available in memory or not??? According to my thinking garbage collector remove it . Am I right or wrong reply me?????

    • @codebasics
      @codebasics  Před 4 lety +1

      yes. after it copies to new location old memory area is freed up

  • @late_nights
    @late_nights Před 4 lety +1

    Sir please upload the next videos as soon as possible. Eagerly waiting .

    • @codebasics
      @codebasics  Před 4 lety

      Sure I am uploading on latest by tomorrow.

    • @late_nights
      @late_nights Před 4 lety

      @@codebasics Thank you sir

  • @dragnar4743
    @dragnar4743 Před měsícem

    Timestamp 6:23 it's a linear search, so big O is O(n). If we have used Binary search then it would be O(log n). But, python list has index() function, so is it O(n) for index() ?? or is it different?

  • @akumasdeception
    @akumasdeception Před rokem

    I'm curious what program are you using in 11:50 to diagram the array?

  • @abhishekabhi732
    @abhishekabhi732 Před 4 lety

    that was very easy problems i was based on python language i thought it would have been data structures

  • @vinaykumar-1093
    @vinaykumar-1093 Před 3 lety

    If we insert an element at end of list Is time complexity still O(n) ?

  • @bnatarajan3
    @bnatarajan3 Před 2 lety

    Quick question, to look up an element in array, formula used is [memory location + (index * size of int) ]. As we know in Python we can use list with different object type, if that is the case, how does the above equation will look like to find a specific item using index?

    • @bnatarajan3
      @bnatarajan3 Před 2 lety

      Up on more analysis, python list stores references of int or str or objects not the value itself as you have mentioned in the video.

  • @hamzaqadri5772
    @hamzaqadri5772 Před 4 lety

    If array is unsorted then insertion/deletion take O(1) because in unsorted we can't shiftup one by one elements we simple shift the previous value to last and new to that index.
    If array is sorted then we couldn't do that insertion / deletion like above scenerio which is O(1) in sorted case complexity become O(N).

  • @clayprogrammers1670
    @clayprogrammers1670 Před 3 lety

    sir at @7:52 of this video i am getting an error
    intj.remove(1)
    ValueError: list.remove(x): x not in list
    andthis my code :
    intj=[3,5,6,78.8]
    intj.remove(1)
    print(intj)

  • @pareshrane8610
    @pareshrane8610 Před 3 lety +1

    at 7:39 in python to remove element by index use pop()...we use remove() to remove particular element

    • @vishwasrvibhu6670
      @vishwasrvibhu6670 Před 3 lety

      Yes, remove takes the direct value that has to be removed?