Selasa, 27 Februari 2018

Pertemuan 2-Linked List: Implementation I-2101640952-Stephanus Nico Budiarso

Linked list is a linear collection of nodes. Nodes consist of data and pointer that points to the other nodes.

Single Linked List
Single list consists of nodes which contain only one pointer and a data.
To insert the nodes, we can use 4 methods:

  1. The new node is inserted in the beginning
  2. The new node is inserted in the end
  3. The new node is inserted after given node
  4. The new node is inserted before given node.
This is the logic example of the new node that is inserted in the beginning assuming that there is a linked list containing 10,35,27. We want to insert 31.



To delete a value, first we need to find the location of node which store the value we want to delete, remove it, and connect the remaining linked list.
This is the logic example of deleting the node in the beginning. In this example, we want to delete 31.


Circular Single Linked List
In circular, last node contains a pointer to the first node. There is no storing of NULL values in the list.

Double Linked List
Double linked list is also known as two-way linked list, because the nodes contain two pointer, one pointer points to the next node, the other one points to the previous node.
The way to insert data is the same like in single list, first we should allocate the new node and assign a value to it, then we connect the new node with the existing linked list.


To delete a value, there are 4 things that we need to pay attention :
  1. The node to be deleted is the only node in the linked list
  2. The node to be deleted is head
  3. The node to be deleted is tail
  4. The node to be deleted is not head or tail
Circular Double Linked List
In circular, the first node contains a pointer to the last node and the last node contains a pointer to the first node.




Selasa, 20 Februari 2018

Pertemuan 1-Pointer, Array and Introduction to Data Structure-2101640952-Stephanus Nico Budiarso

Array

Array is a collection of similar data elements (homogenous data type). Value of array stored in consecutive memory locations and are referenced by an index. Index starts from zero (0) and ends with index-1.


  • One Dimensional Array
Syntax: type var[index];

Declaration: int a[10];

Accessing:
a[0] = 8;
a[1] = 10;
a[2] = 6;
a[3] = 2;
  • Two Dimensional Array
Syntax: type var[index1][index2];

Declaration: int a[10][20];

Accessing:
a[0][12] = 8;
a[1][2] = 10;
a[2][11] = 6;
a[3][8] = 2;

  • Multi Dimensional Array
Syntax: type var[index1][index2][index3][...];

Declaration: int a[10][20][12][9];

Accessing:

a[0][12][0][5] = 8;
a[1][11][6][8] = 10;
a[2][14][5][2] = 32;
a[3][2][7][5] = 24;

The maximum dimension of multi dimensional array is nineteen (19).

Operations that can be performed on arrays are: traversal, insertion, searching, deletion, merging, and sorting.

Pointer

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

The two most important operators used with pointer type are:

&  the address operator
*   the dereferencing operator

The difference between single pointer and double pointer:
Variable with single pointer points to the value of another variable which address it
stores. Meanwhile, variable with double pointer points to the value of another variable
which address is already being stored in other variables.

Introduction to Data Structure

Array
The lack of using array: memory that needed is much bigger.

Linked lists
The benefit of using linked lists is dynamic allocation. With dynamic allocation, the memory that used will be added as soon as it used.

The difference between queue and stack:
queue: first in, first out.
stack: first in, last out.

The elements that added at one end called the rear and removed on the other end called the front.

Binary trees will be disscussed after the midterm exam.

Why we should learn data structure?

Social media holds the important role in these days on the internet. The basic of social media is data.
When we use the search engine, such as google, then the ads that shows up are based on what we search, our interest. This happens because our search data were stored using data structure.