Algorithms for Work: Data Type - Small Things Matter.
happy to be here

Algorithms for Work: Data Type - Small Things Matter.

tl;dr

It's about space complexity. Use what you need.


Let start with Java.

We create many data types to store values and represent something in life.

For true or false, we have booleans.

For numbers we have byte, short, int, and long. I have to stop here and ask: "Why we need 4 type for just integer number? We even had float and double."

And look at it—it's different in size. byte (1), short (2), int (4), and long (8). Those numbers can be different when it comes to really big problems. The size matters. It's not when the problem is small, but when the problem grows bigger, for example, when you store the score of students with the type of long (8). For the class with 100 students, you spend 8B * 100 = 800B, which is really small.

Compared to using a byte to store, it's 1B * 100 = 100B. Yeah it's small. But it's 8 times larger than the minimum option. So imagine the case when this applies to 8T of data. If you select the minimum data type option, you already save 7T if you do so.

You can call it "b*ll sh*t" for this simple example. But when you're doing an actual problem, it's easy to select int to store data (even when it doesn't use all the value ranges of short or byte). When you create a DataBase table, you overexpand the use of datatypes. This example above can happen even worse.


So that's why small thing matter. You learn about algorithms and understand the basics of them.

Normally, when you solve a problem, they give you 2MB of stack and 256MB of heap.

If you select the optimal data type, you can expand your limit 2, 4, 8 times. Or even more of you apply some compression solution or this kind of idea when doing with bit (the idea of SnowFlake).

It's important when you have limited resources, so be mindful of it.


More ideas come from it: Collection / Wrapper.

Eventually, all the data comes back to be a set of data, and action comes with it. We are using the knowledge of other developers and sometime/somehow forgot why we use it; it's become the norm. It's okay, but still, we need to know the basic mindset behind it.

You can make use of HashMap, Queue, Stack, Heap... or everything! They make a really good version of it for us to re-use.

But, but, but...

From time to time, we use a framework and make our own class. Remember to have a checklist and remind yourself about data size, it's important.

One day, you will be the one who makes the base for the feature/ system, and let's practice from now on.


We only cover datatypes today; the BigO about time complexity will come later.

Helpful resource:

https://en.wikipedia.org/wiki/Space_complexity










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

Nam Nguyen的更多文章

  • 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…

    2 条评论
  • 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…

    9 条评论
  • 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…

    4 条评论
  • M?y ??a ??c truy?n làm sao mà 'l?n' ???c? ??c sách ?i!

    M?y ??a ??c truy?n làm sao mà 'l?n' ???c? ??c sách ?i!

    Mình ng?i ??c sách. Mình v?n ng?i ??c sách.

    7 条评论
  • Wecommit m?t hành trình

    Wecommit m?t hành trình

    R?t vui ???c có c? h?i làm quen v?i các b?n. Mình là m?t l?p trình viên yêu thích thu?t toán và thích hi?u b?n ch?t c?a…

    30 条评论

社区洞察

其他会员也浏览了