Data Structure Rangkuman Pertemuan 1 & 2

Nama : William Wijaya
Nim    : 1901475841

Session 1

Array
1. Collection of Similar data Elements
2. Has same data type
3. Referenced by an Index
4. Index start from Zero

Array Type
1. One Dimensional Array (Ex : array[10])
2. Multi Dimensional Array (Ex : array[100][10][20])

3 Ways to Store Values in Array
1. Initialize the Elements
(Ex : int arr[2] ={1,2,3})
2. Input Values
(Ex : int i,int number[10]
for(i = 0;i<10;i++)
scanf(“%d”,&number[i];)
3. Assigning Values
(Ex : int i,int number[10],int number2[10]
for(i = 0;i<10;i++)
number[i]=number2[i];)

List of Operation available for Array
1. Traversal
2. Insertion3. Searching
4. Deletion
5. Merging
6. Sorting

 

Pointer
Pointer is a data type whose value refer to another value stored elsewhere in computer using its address

Important operator for pointer >>> &(address operator) and *(dereferencing operator)

For Example:
if we have

int x;
int *px; then x act as integer and px act as pointer to integer

 

Data Structure
Data Structure is an arrangement of data,either in computer storage or in the disk storage

Common example for Data Structure
1. Array
2. Linked List3. Queues
4. Stack
5. Binary Tree
6. Hash Tables

Array
1. Collection of similar data elements
2. Data elements have  the  same data type

Linked List
1. A very dynamic data structure in which the elements can be added to  or deleted from anywhere at will2. Each elements is called a node

Queue
1. The elements that was inserted at first is the first one to be taken out
2. The elements in a queue are added on end called rear and removed from front

Stacks
1. Linear Array
2. Every stack has a TOP
3. LIFO/FILO(Last in First Out/ First in Last Out)

Binary Trees
1. A Data Structure which is defined by collection nodes2. Every node contains a left pointer, right pointer and data element

Session 2

Structure
basically a user defined data that can store different data type

Example:

struct data{
int age;
char name[100];
};

where data act as structure name , age and name act as structure member

Creating a variable of structure is similar to create a variable of primitive data type (Ex : data x; datax[100])

You can use operator . (dot) to access member of x
(Ex : x.age;x.name)

You can also use array on struct
(Ex : data x[100];
x[0].age;
x[1].age;
etc.

 

Memory Allocation : Dynamic
If you need to allocate memory dynamically (in runtime), you can
use malloc in C/C++. To de-allocate you can use free.

Linked List
Is a data structure that consist of a sequence  of data  records such that  each record there  is a field that contains a reference  to the next record sequence

Linked List Vs Array

Array
1. Linear Collection of data elements
2. Store value in consecutive memory locations
3. can be random in accesing data

Linked List1. Linear Collection of nodes
2. Doesnt store its nodes in consecutive memory locations
3. can be accessed only in a sequential manner.