Selasa, 27 Februari 2018

2-Chandra Delon-2101662013

2-Chandra Delon-2101662013

Linked List:
-        Single Linked List
-        Polynomial Representation
-        Circular Single Linked List
-        Doubly Linked List
-        Circular Doubly Linked List
-        Header Linked List

Single Linked List
untuk membuat sebuah list , kita pertama-tama harus mendefinisikan sebuah struktur node untuk listnya. 
Bila kita mau membuat sebuah list type integer
struct tnode {
               int value;
               struct tnode *next;
};
struct tnode *head = 0;

Single Linked List: Insert

Untuk insert value yang baru, kita harus dynamically allocate a new node dan memasukan valuenya kedalam dan menghubungkannya dengan linked list yang tersedia.
Bila kita mau menambahkan node baru ke dalam head.
struct tnode *node =
               (struct tnode*) malloc(sizeof(struct tnode));
node->value = x;
node->next  = head;
head = node;

Untuk menghapus sebuah value, kita harus mencari lokasi dari node dimana value yang ingit kita delete tersimpan, lalu di delete, kemudian sambungkan ke sisa linked list.
Bila value yang kita mau delete adalah x dan misalkan x itu berada didalam linked list dan kondisinya unik.
Ada 2 kondisi yang kita harus perhatikan:
Jika x di dalam head node atau tidak ada didalam head node.

Single Linked List: Delete
struct tnode *curr = head;
// if x is in head node
if ( head->value == x ) {
               head = head->next;
               free(curr);
}
// if x is in tail node
else if(tail->value == x){
               while(curr->next!=tail) curr = curr->next;
               free(tail); tail = curr;
               tail->next = NULL;
}
// if x is not in head node, find the location
else {
               while ( curr->next->value != x ) curr = curr->next;
               struct tnode *del = curr->next;
               curr->next = del->next;
               free(del);
}
Single Linked List: Delete
Deleting 31 (located at head)
Single Linked List: Delete
Deleting 35 (not located at head)
Polynomial Representation
        Polynomial is given as 6x3 + 9x2 + 1
        Every individual term in a polynomial consists of two parts, a coefficient and a power
        Here, 6, 9, 7, and 1 are the coefficients of the terms that have 3, 2, 1, and 0 as their power respectively.
        Every term of a polynomial can be represented as a node of the linked list.
Circular Single Linked List
        In circular, last node contains a pointer to the first node
        We can have a circular singly linked list as well as a circular doubly linked list.
        There is no storing of NULL values in the list
Doubly Linked List
Doubly linked list or two-way linked list is a linked list data
structure with two link, one that contain reference to the next data
and one that contain reference to the previous data.
struct tnode {
               int value;
               struct tnode *next;
               struct tnode *prev;
};
struct tnode *head = 0;
struct tnode *tail = 0;
Doubly Linked List: Insert
Just like in a single linked list, first we should allocate
the new node and assign the value to it, and then we
connect the node with the existing linked list.
Supposed we want to append the new node behind the tail.
struct tnode *node =
               (struct tnode*) malloc(sizeof(struct tnode));
node->value = x;
node->next  = NULL;
node->prev  = tail;
tail->next  = node;
tail = node;
Doubly Linked List: Insert
Supposed we want to insert a new node in a certain position (any
location between head and tail)
struct tnode *a = ??;
struct tnode *b = ??;
// the new node will be inserted between a and b
struct tnode *node =
               (struct tnode*) malloc(sizeof(struct tnode));
node->value      = x;
node->next        = b;
node->prev        = a;
a->next = node;
b->prev               = node;
Doubly Linked List: Delete
There are 4 conditions we should pay attention when deleting:
        The node to be deleted is the only node in linked list.
        The node to be deleted is head.
        The node to be deleted is tail.
        The node to be deleted is not head or tail.
1.  If the node to be deleted is the only node:
free(head);
head = NULL;
tail = NULL;
Doubly Linked List: Delete
  1. If the node to be deleted is head:
               head = head->next;
               free(head->prev);
               head->prev = NULL;
  1. If the node to be deleted is tail:
               tail = tail->prev;
               free(tail->next);
               tail->next = NULL;
Doubly Linked List: Delete
  1. If the node to be deleted is not in head or tail:
              
               struct tnode *curr = head;
               while ( curr->next->value != x ) curr = curr->next;
               struct tnode *a   = curr;
               struct tnode *del = curr->next;
               struct tnode *b   = curr->next->next;
               a->next = b;
               b->prev = a;
               free(del);
Circular Doubly Linked List
It is similar with circular single linked list, but total
pointer in each node here is 2 (two) pointers.
Header Linked List
        A header linked list is a special type of linked list which contains a header node at the beginning of the list.
        So, in a header linked list, START (L) will not point to the first node of the list but START (L) will contain the address of the header node.
Summary
               Linked list is a data structure that consists of a sequence of data records such that each record there is a field that contains a reference to the next record in the sequence

Selasa, 20 Februari 2018

1-Chandra Delon-2101662013

1-Review Array, Pointer, Data Structure & Linked List
          Array adalah kumpulan elemen data yang memiliki tipe data yang sama contohnya : seperti data yang dideklarasi pada variable abc berikut
int x[5] ; maka variable x itu memiliki 4 buah array yang memiliki tipe data yang sama yaitu integer.
Bebek
Berikut jenis-jenis Array:
-One Dimensional Array
Declaration:
int arr[5];
Accessing:
arr[0] = 7;
arr[1] = 2;
arr[2] = 13;
arr[3] = 13;
arr[4] = 13;
          -Two Dimensional Array
          Declaration:
int arr[3][6];
Accessing:
arr[0][2] = 2;
arr[2][1] = 9;
arr[1][5] = 13;
arr[2][4] = 10;
-Multi Dimensional Array
Declaration:
int arr[4][3][7][10];
Accessing:
arr[0][2][2][9]= 2;
arr[2][1][6][0]= 9;
arr[3][0][0][6]= 13;
arr[2][1][3][8]= 10;
Pertanyaan Dosen Kelas Besar : Berapa maksimal dari dimensi array?
Jawaban dari saya : Maksimal dimensi dari array itu tergantung dari seberapa kuat CPU kita untuk memproses array-array tersebut.
Pointer adalah tipe data yang nilainya diambil dari nilai address yang terletak di memori komputer
Berikut contoh-contoh pointer :
If we have the declaration:
          int x;
          int *px;
then x is an integer and px is a pointer to an integer. If we say:
          px  = &x;
then &x returns the address of x and assigns it as the value of px.
To assign a value of x we can say
          x = 10;
or
          *px = 10;
Pertanyaan Dosen Kelas Besar : Apa fungsi dari single pointer dan double pointer dan apa maksimal dari pointer? Single Pointer digunakan untuk menyimpan alamat selanjutnya dari sebuah data, sedangkan Double pointer digunakan untuk menyimpan alamat sebelumnya dan juga yang selanjutnya.
Maksimal dari pointer itu tak terhingga.


Data Structure adalah data yang diatur didalam memori computer atau disk storage.
Beberapa contoh data structure yang sederhana :
-Arrays
-Linked lists
-Queues
-Stacks
-Binary Trees
-Hash Tables

-Array :

-Linked Lists (Data structure yang dinamis yang elemennya dapat di tambah atau dihapus sesuai dengan keinginan):

-Queue(First in First out[FIFO])



-Stacks(Last in First Out[LIFO] / First In Last Out[FILO])


-Binary Trees(Data structure yang di artikan sebagai kumpulan elemen yang dipanggil the Nodes.
















Data Type is a collection of objects and a set of operations that act on those objects.
For example, the data type int consists of:
objects  : 0, +1, -1, +2, -2, etc
operations  : +, -, *, /, %, etc
Example of predefined data types are int, char, float.
Abstract Data Type (ADT) is a data type that is organized in such a way that the specification of the objects and the specification of the operations on the objects is separated from the representation of the objects and the implementation of the operations.
C/C++ has a concept called class and struct which assist the programmer in implementing abstract data type.


Introduction to Linked List
Structure is basically a user-defined data type that can store related information (even of different data types) together, while an array can store only entities of same data types.
It is a collection of variables under a single name.
The variables within a structure are of different data types and each has a name that is used to select it from the structure.
Structure Declaration :
struct tdata {
  int   age;
  char  name[100];
  float score;
};
The code above defines a structure named tdata which has three members: age (int), name (char[]) and score (float).
Creating a variable of structure is similar to create a variable of primitive data type.
  tdata x;    // a variable of tdata
  tdata arr[100];  // an array of tdata


Rangkuman dari presentasi pembicara :
Menjelaskan pentingnya data struktur, dan apa saja manfaat dari data struktur, dan cara pakai data struktur untuk dalam berbisnis / investasi.
Contohnya : Mengambil data-data dan menjualnya dan juga bisa digunakan untuk membuat suatu cryptocurrency, cryptocurrency yang paling terkenal saat ini bernama bitcoin ternyata juga menggunakan ilmu data struktur.