Array

Array stores a fixed-size sequential collection of elements of same type
each data is correspond to an index
By index, direct access to data is possible
Sequentially process the same type of data

Advantages of Arrays

  • Quick access using index

Disadvantages of Arrays

  • It is not easy to add or delete data if data is variable.
    • Since the fixed amount of memory space is declared, it is difficult to add new data unless you know the maximum length of the array.
    • After deleting the data, there is a problem to pull the data that was existing behind
  • When declaring data of array type, size of maximum length must be declared in advance

Example (C++)

Count frequency of how many ‘M’ has been appeared inside the dataset

#include<stdio.h>

int main()
{
	char dataset[][70] = {"Jennifer Anniston, Ms. Jen",
		"Courtney Cox, Ms. Cox",
		"Lisa Kudrow, Ms. Kudrow",
		"Matthew Perry, Mr. Perry (Metthew)",
		"David Schwimmer, Mr. Schwimmer",
		"Matt LeBlanc, Mr. LeBlanc (Matt)"};
    int m = 0;
    
  	for(char* data : dataset)
    {
    	for(int i = 0; data[i] != '\0' ; i++)
    	{
			if( data[i] =='M')
			{
				m++;   		
			}
		}
	} 
	printf("%d\n", m); //10

	return 0;
}

1. Data Structure

Efficiently manage large amounts of data
In order to manage data efficiently in code, data must be structured systematically

  • Main Representative Data Structure
    Array, Stack, Queue, LinkedList, HashTable, Tree, Heap .etc

2. Algorithm

Procedure / Method to solve the problem
Programming to get the desired ‘output’ by putting a certain ‘input’ for a problem

c++ data type range

Type name Bytes Range of Values
bool 1 true or false
char 1 -128 to 127
short 2 -32,768 to 32,767
unsigned short 2 0 to 65,535
int 4 -2,147,483,648 to 2,147,483,647
unsinged int 4 0 to 4,294,967,295
long 4 -2,147,483,648 to 2,147,483,647
unsigned long 4 0 to 4,294,967,295
long long 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long long 8 0 to 18,446,744,073,709,551,615
float 4 3.4E +/- 38 (7 digits)
double 8 1.7E +/- 308 (15 digits)

cpp data type ranges.