DataStructures Series #1 – Intro

Originally posted on my medium page: https://medium.com/@otarutunde

Introduction

Imagine giving you a dictionary not arranged alphabetically and then I ask you to find a random word in it. The worst case scenario would be to scan the whole dictionary to find the word. It could take you many hours or even days depending on how big the dictionary is.

Now, imagine when the dictionary is arranged alphabetically. It will for sure take just a few minutes or even seconds depending on how fast you are.

The same applies to computer programs and data-structures. Using inappropriate data-structures can take your programs minutes/hours or even days to execute. Hence, the need to study data-structures and understand what scenarios to use them .

Over the course of this series, we will discuss the different data-structures and hopefully find real examples where they can be used. There are three types of datatypes as far as I know:

  • Primitives: e.g Strings, Integers etc.
  • Composite: e.g Structs, Classes e.t.c. to store a group of data
  • Abstract: They are just concepts explaining the behaviour of the data type. The implementations are called Data-Structures, how they are implementation vary across different programming languages.

Let us start from the basics….

What is Data?

In computing, the smallest unit of data is a bit (1 or 0)

And we can build up from there to have:

  • a nibble — 4 bits
  • a byte — 8 bits
  • a kilobyte — 1000 * 8 bits

and so on…

Most modern computers use 8 bits — a byte as the smallest unit of memory today.

What is a Data type?

data type is a classification of data which tells compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data.

Let us look at some very well known programming languages and their primitive datatypes:

  • Java
    – Integer (byte — 1 byte, short — 2 bytes, int — 4 bytes, long — 8 bytes)
    – Character (char — 2 bytes)
    – Boolean (bool — uses 1 bit, but 8 is our smallest unit, so 1 byte)
    – Floating Point (float — 4 bytes, double — 8 bytes)
  • C# 2010
    – Boolean (bool — 1 bit, but 8 is our smallest unit, so 1 byte)
    – Integer (byte —1 byte, int — 4 bytes, long — 8 bytes, sbyte, uint etc.)
    – Floating Point (decimal — 16 bytes, float — 8 bytes)
    – Character (char — 2 bytes)

Going back to the earlier definition:

data type is a classification of data which tells compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data.

If an int data type is defined for a value in the Java programming language. The java programming language compiler knows how many bytes is needed to store this value and then it creates this space in the computer to store this value.

You can check the primitive datatypes of your favourite language(s) too and their corresponding memory units.

REFERENCES: