Algorithms for work - Array

Algorithms for work - Array

#sharing

I want to borrow this picture to start sharing about arrays in Java (or any other language) and leave an open question at the end.

We somehow know that we can define an array with the ????????-???????? and the ???????? of the array.

for example: int[] array = new int[7];

example array with data

And we have the name of the array holding the starting point / address of it.

and with the ?????????? we can direct access to it. But how? Okay, it's all laid down on "how you created it".

You already gave it the data-type which is the same as telling the computer that we have a block with a fixed size (in this example, it's 1 integer size of 4 bytes).

And you give it the size so the computer knows that they need to find a ?????????? for you to put the block next to each other.

So when we access the array (starting point 2000), and we want to go to the index of 3. The machine knows that you want to get the data at location 2000+3*4 = 2012. It go there, reads the data block with a size of 4, and converts the bytes/bits into the data type so we get ?? out.

go to 2012 and get 7

Same goes for when you update array[2] = 11;

direct access to modify

Fun fact / bonus: In Java we have IndexOutOfBoundsException to catch the action of accessing the 'invalid' index.

But when you work with C/C++, those exception don't happen and it still read data with the same rule.

So if you try to access array[-1] you still get the data out. So if you are using this, please be aware of it, It can OVERWRITE the data of an existing value if you modify the memory they are using.


So the idea can apply to the static array of all data types (with all kinds of sizes), and you can somehow understand direct access, which makes the array really fast when it comes to accessing and modifying the data.



Open question:

  • Why do we need arrays?
  • From which problem do we create arrays? And what if we don't have array?



#sharingWithCS

#ChjnSu

要查看或添加评论,请登录

Nam Nguyen的更多文章

  • Weekly NewsLetter: ?i làm kh?ng vì ti?n

    Weekly NewsLetter: ?i làm kh?ng vì ti?n

    ?i Làm Kh?ng Vì Ti?n – M?t Cau Chuy?n Ngh?ch Ly ?ay là m?t tiêu ?? gay tò mò. ??c ??n cu?i, b?n s? th?y nó th?t s? ?úng…

    33 条评论
  • Weekly Newsletter: Th?i h?c 1 l?n dùng 1 ??i ?? h?t?

    Weekly Newsletter: Th?i h?c 1 l?n dùng 1 ??i ?? h?t?

    S? h?c Trong l?n ng?i chia s? v?i các anh, mình có nghe ???c m?t cau ?úc rút r?t hay. Th?i x?a các c? h?c 1 l?n ?? dùng…

    18 条评论
  • Weekly Newsletter: Relearn | Unlearn

    Weekly Newsletter: Relearn | Unlearn

    V? tay nhanh nh?t th? gi?i G?n ?ay mình ?i h?c nói m?i nh? l?i m?t video t? x?a: K? l?c v? tay nhanh nh?t th? gi?i…

  • Weekly NewsLetter: C?m ?n nh?ng l?i nh?n xét

    Weekly NewsLetter: C?m ?n nh?ng l?i nh?n xét

    Bài h?m nay mu?n nói v? hành trình mình ?i tìm nh?ng l?i nh?n xét ti?p theo ?? thay ??i b?n than mình t?t h?n. Ph?n ??u…

    4 条评论
  • Weekly NewsLetter: L?a ch?n ? tu?i 30 - Th?c t?

    Weekly NewsLetter: L?a ch?n ? tu?i 30 - Th?c t?

    ??u tiên là quay l?i Part 1: 4 ni?m tin c? s? 1 chút cho t? duy này 1. Cu?c ??i là m?t chu?i các l?a ch?n.

    20 条评论
  • Weekly NewsLetter: L?a ch?n ? tu?i 30 Part 2

    Weekly NewsLetter: L?a ch?n ? tu?i 30 Part 2

    N?u ph?i ?úc k?t c? qu?ng th?i gian mình h?c h?i và tìm cho mình ???c các b?n ch?t c?a v?n ?? thì th?t s? r?t dài…

    24 条评论
  • L?a ch?n tu?i 30 - Part 1 Ni?m tin

    L?a ch?n tu?i 30 - Part 1 Ni?m tin

    Ni?m tin s? 1 Cu?c ??i là m?t chu?i các l?a ch?n. Cu?c s?ng c?a m?i ng??i th?c ch?t là k?t qu? c?a nh?ng l?a ch?n chúng…

    8 条评论
  • Weekly NewsLetter: IT H?c nói P1: H?t h?i

    Weekly NewsLetter: IT H?c nói P1: H?t h?i

    Góc nhìn t? podcast v?i Tr?n Qu?c Huy H?m v?a r?i, khi tham gia podcast cùng anh Tr?n Qu?c Huy , mình nh?n ra r?ng c?ng…

    20 条评论
  • PDCA - Plan Do Check Act - H?c 1 bi?t nhi?u

    PDCA - Plan Do Check Act - H?c 1 bi?t nhi?u

    Trong chu?i bài vi?t n?u t?i bi?t tr??c khi 30, th?c ra ?i?u này v? ly thuy?t thì mình bi?t r?i, nh?ng nó l?i chính là…

    1 条评论
  • MVP Hành trình h?c nói - Step 7/7

    MVP Hành trình h?c nói - Step 7/7

    Xin chào mn 7 b??c rèn luy?n t? duy nói chia làm 3 ph?n chính là: Ti?p nh?n ki?n th?c ??nh ngh?a L?a ch?n th?ng tin…

    7 条评论

社区洞察

其他会员也浏览了