Dynamic Array and Linked List

Slides:



Advertisements
Presentasi serupa
LINKED LIST.
Advertisements

QUEUE II. IMPLEMENTASI QUEUE
1 Algoritma Bahasa Pemrograman dan Bab 1.1. Pengertian Algoritma.
PENCARIAN (SEARCHING)
Modul-8 : Algoritma dan Struktur Data
Chapter 10 Linked List (Senarai Bertaut) Program Studi Ekstensi DTE FTUI Slides©2007.
SUBPROGRAM IN PASCAL PROCEDURE Lecture 5 CS1023.
LINKED LIST by Yohana N.
Struktur Data List Linear : Linked List (Double Linkedlist)
ARRAY RUBY. PENDAHULUAN Ruby's arrays are untyped and mutable. The elements of an array need not all be of the same class, and they can be changed at.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
1 DATA STRUCTURE “ STACK” SHINTA P STMIK MDP APRIL 2011.
Linear List.
Struktur Data List Linear : Linked List (Single Linkedlist)
1 Diselesaikan Oleh KOMPUTER Langkah-langkah harus tersusun secara LOGIS dan Efisien agar dapat menyelesaikan tugas dengan benar dan efisien. ALGORITMA.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Pertemuan Linked list jual [Valdo] Lunatik Chubby Stylus.
1 Pertemuan 15 Game Playing Matakuliah: T0264/Intelijensia Semu Tahun: Juli 2006 Versi: 2/1.
Binary Search Tree. Sebuah node di Binary Search Tree memiliki path yang unik dari root menurut aturan ordering – Sebuah Node, mempunyai subtree kiri.
4. Linked List (List Linier)
Induksi Matematika.
Tim struktur data IF UNIKOM
Algoritma dan Pemrograman Searching
STRUKTUR DATA STACK.
Struktur data Oleh: Tim Struktur Data IF ARRAY STATIS.
Tim struktur data IF UNIKOM
Program Studi Teknik Informatika
Program Studi Teknik Informatika
Linked List Oleh: Tim Struktur Data IF - UNIKOM.
Double Linked List.
Tim struktur data IF UNIKOM
LINKED LIST Circular Linked List.
Program Studi Teknik Informatika
BAB IV – ARRAY DINAMIS DAN LINKED LIST (1)
Linked List.
Pointer & Linked List.
STRUKTUR DATA Array Statis.
STRUKTUR DATA Array Statis.
LINKED LIST Oleh: Tim Algoritma & Pemrograman IF Double Linked List.
STRUKTUR DATA STACK.
Linked List Oleh: Tim Struktur Data IF - UNIKOM.
Pertemuan 24 Teknik Searching
Tim struktur data IF UNIKOM
Double Linked List.
LINKED LIST Oleh: Tim Algoritma & Pemrograman IF Circular Linked List.
STRUKTUR DATA Array Statis.
Menghapus Simpul dan Travelsal
Algorithms and Programming Searching
Linked List Oleh: Tim Struktur Data IF - UNIKOM.
SEARCHING (PENCARIAN)
STRUKTUR DATA Array Statis.
Linked List Oleh: Tim Struktur Data IF - UNIKOM.
Tim struktur data IF UNIKOM
SENARAI BERANTAI (LINKED LIST)
ARRAY STATIS Sri Nurhayati, MT.
Algoritma dan Pemrograman Searching
Tim struktur data IF UNIKOM
STRUKTUR DATA LINKED LIST
Tim struktur data IF UNIKOM
Linked List Oleh: Tim Struktur Data IF - UNIKOM.
ARRAY STATIS Sri Nurhayati, MT.
Algoritma dan Struktur Data
Tim struktur data IF UNIKOM
LINKED LIST Oleh: Tim Algoritma & Pemrograman IF Double Linked List.
Algoritma dan Struktur Data
Linked List A group of data which is linked each other.
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 3.
Perulangan (Loop) Oleh : Tim Teaching
Transcript presentasi:

Dynamic Array and Linked List Adam M.B.

 DYNAMIC ARRAY

DEFINITION AND DECLARATION  DEFINITION AND DECLARATION

Description Array which can be managed dynamically in memory (its size). To order the place in memory, it uses POINTER.

Declaration Type Pengenal = ↑Simpul Simpul = TipeData Atau NamaVariabel : ↑TipeData

Example (1) Kamus: Bilangan : ↑integer Nama : ↑string

Example (2) Kamus: Type Point = ↑Data Data = Record < Nim : integer, Nama : string, Nilai : real > EndRecord DataMhs : point

 ALLOC AND DEALLOC

Definition Alloc is statement that can be used to order place in memory while program is running. Dealloc is statement that can be used to delete place which had been ordered while program is running.

Ilustration in Memory Alloc(DataMhs) DataMhs Still Empty Nil

 OPERATION

Case Kamus: Type Point = ↑Data Data = Record < NamaMhs : string, Jurusan : string > EndRecord T1,T2: point

Copy Pointer (Cont’d) Alloc(T1) T1 Alloc(T2) T2

Copy Pointer (Cont’d) T1 T2 T1.NamaMhs  ‘Adam’ T1.Jurusan  ‘Teknik Informatika’ T1 T2

Copy Pointer (Cont’d) T1 T2  T1 T2

Copy Value T1 T2  T1 T2

Delete the Pointer Dealloc(T1)

 LINKED LIST

 DEFINITION

Description Data structure that is prepared sequentially, dynamically, and infinite. Linked list is connected by pointer.

Array VS Linked List ARRAY LINKED LIST Static Dynamic Insert and Delete are finite Insert and Delete are infinite Random Access Sequential Access Delete element is only delete value Delete element is truly delete space

Types of Linked List Single Linked List Double Linked List Circular Linked List

 DECLARATION (Single Linked List)

Connection Field (Next) Description Linked list that its node consists of one link/pointer that refers to another node. Ilustration of node: Info Field (Info) Connection Field (Next)

Declaration Kamus: Type NamaPointer = ↑Simpul Simpul = Record < InfoField : TipeData, ConnectionField : NamaPointer > EndRecord NamaVarPointer : NamaPointer

Example Kamus: Type Point = ↑Simpul Simpul = Record < Info : integer, Next : Point > EndRecord Awal,Akhir : Point

 OPERATION

Creation Searching Insertion Sorting Delete Destroy Traversal

Creation Pointer (awal and akhir) is given nil as their value. awal awal  nil akhir  nil

Front Insertion If list is empty (awal = nil). alloc(baru) baru.next  nil baru.info  1 baru 1 akhir awal awal  baru baru 1 akhir  baru

Front Insertion (cont’d) If list isn’t empty (awal ≠ nil). For example, there is list that has two nodes: akhir awal 2 3 One node will be inserted in front of list: alloc(baru) 1 baru baru.info  1

Front Insertion (cont’d) New node will be inserted before the node that was refered by awal. awal 2 akhir 3 baru↑.next  awal baru 1

Front Insertion (cont’d) After new node was inserted, move awal to new node. 2 3 baru 1 akhir awal awal  baru

Front Insertion (cont’d) The last result for front insertion if linked list wasn’t empty: awal 2 3 akhir baru 1

Procedure SisipDepanSingle(Input elemen : tipedata, I/O awal, akhir : nama_pointer) {I.S. : data yang akan disisipkan (elemen), pointer penunjuk awal dan pointer penunjuk akhir sudah terdifinisi} {F.S. : menghasilkan satu simpul yang disisipkan di depan pada single linked list} Kamus : baru : nama_pointer Algoritma : alloc(baru) baru↑.info  elemen If (awal = nil) Then baru↑.next  nil akhir  baru Else baru↑.next  awal EndIf awal  baru EndProcedure

Back Insertion If list is empty (awal = nil)  the process is same as front insertion if linked list is empty.

Back Insertion (cont’d) If list isn’t empty (awal ≠ nil). For example, there is list that has two nodes: awal 3 2 akhir New node that will be inserted: alloc(baru) baru.next  nil baru 1 baru.info  1

Back Insertion (cont’d) New node will be inserted after the node that was refered by akhir. akhir awal 3 2 akhir.next baru baru 1

Back Insertion (cont’d) Move akhir to new node. awal 3 2 baru 1 akhir akhir  baru

Back Insertion (cont’d) The last result for back insertion if linked list wasn’t empty: awal 3 2 akhir 1 baru

Procedure SisipBelakangSingle(Input elemen : tipedata, I/O awal, akhir : nama_pointer) {I.S. : data yang akan disisipkan (elemen), pointer penunjuk awal dan pointer penunjuk akhir sudah terdifinisi} {F.S. : menghasilkan satu simpul yang disisipkan di belakang pada single linked list} Kamus : baru : nama_pointer Algoritma : alloc(baru) baru↑.info  elemen baru↑.next  nil If (awal = nil) Then awal  baru Else akhir↑.next  baru EndIf akhir  baru EndProcedure

Middle Insertion If list is empty (awal = nil)  the process is same as front insertion if linked list is empty.

Middle Insertion (cont’d) If list isn’t empty (awal ≠ nil). awal 2 5 4 akhir 3 New node that will be inserted after 4: alloc(baru) baru 1 baru.info  1

Middle Insertion (cont’d) Search node 4 using sequential search and bantu pointer. baru 1 awal 2 5 4 akhir 3 bantu bantu

Middle Insertion (cont’d) Connect the connection field from new node to the neighbour node of node that was refered by bantu. baru 1 awal 2 5 4 akhir 3 bantu baru.next  bantu↑.next

Middle Insertion (cont’d) After new node was connected with node 4 then refer the connection field of node that was refered by bantu to new node. bantu awal 2 baru 1 4 akhir 3 5 bantu.next  baru

Middle Insertion (cont’d) The last result for middle insertion if linked list wasn’t empty: awal 4 3 bantu 2 akhir 5 1 baru

Procedure SisipTengahSingle(Input elemen : tipedata, I/O awal, akhir : nama_pointer) {I.S. : data yang akan disisipkan (elemen), pointer penunjuk awal dan pointer penunjuk akhir sudah terdifinisi} {F.S. : menghasilkan satu simpul yang disisipkan di tengah pada single linked list} Kamus : baru,bantu : nama_pointer ketemu : boolean datasisip : tipedata Algoritma : If (awal = nil) Then alloc(baru) baru↑.info  elemen baru↑.next  nil

awal  baru akhir  baru Else Input(datasisip) bantu  awal ketemu  false While (not ketemu and bantu ≠ nil) do If (datasisip = bantu↑.info) Then ketemu  true bantu  bantu↑.next EndIf EndWhile

If (ketemu) Then alloc(baru) baru↑ If (ketemu) Then alloc(baru) baru↑.info  elemen If (bantu = akhir) sisip_belakang_single(elemen,awal,akhir) Else baru↑.next  bantu↑.next bantu↑.next  baru EndIf Output(“Data yang akan disisipkan tidak ada”); EndProcedure

Front Deletion Delete one node in beggining of linked list if linked list has only one node (awal = akhir). awal akhir 1

Front Deletion (cont’d) If deletion happens in linked list with one node then linked list will be empty. 1 awal akhir phapus phapus  awal elemen  phapus .info elemen awal akhir awal  nil akhir  nil dealloc(phapus) 1 phapus

Front Deletion (cont’d) If linked list has more than one node (awal ≠ akhir). For example, linked list has two nodes. awal 2 3 akhir

Front Deletion (cont’d) awal 2 3 akhir phapus phapus  awal elemen elemen  phapus.info awal  awal.next awal 2 3 phapus akhir dealloc(phapus)

Front Deletion (cont’d) The last result for front deletion if linked list has more than one node: awal 3 akhir 2 phapus

Procedure HapusDepanSingle(Output elemen : tipedata, I/O awal, akhir : nama_pointer) {I.S. : pointer penunjuk awal dan pointer penunjuk akhir sudah terdifinisi} {F.S. : menghasilkan single linked list yang sudah dihapus satu simpul di depan} Kamus : phapus : nama_pointer Algoritma : phapus  awal elemen  baru↑.info If (awal = akhir) Then awal  nil akhir  nil Else awal awal ↑.next EndIf dealloc(phapus) EndProcedure

Back Deletion Delete one node in back of linked list if linked list has only one node (awal = akhir). This process is same as front deletion if linked list has only one node.

Back Deletion (cont’d) If linked list has more than one node (awal ≠ akhir). For example, linked list has three nodes. awal 1 3 2 akhir

Back Deletion (cont’d) awal 1 3 akhir 2 phapus elemen phapus  awal elemen  akhir.info phapus  phapus.next akhir  phapus awal 1 3 2 akhir phapus phapus phapus  phapus.next

Back Deletion (cont’d) awal 1 3 phapus 2 akhir akhir.next  nil dealloc(phapus)

Back Deletion (cont’d) The last result for back deletion if linked list has more than one node: awal 1 2 akhir phapus phapus 3

Procedure HapusBelakangSingle(Output elemen : tipedata, I/O awal, akhir : nama_pointer) {I.S. : pointer penunjuk awal dan pointer penunjuk akhir sudah terdifinisi} {F.S. : menghasilkan single linked list yang sudah dihapus satu simpul di belakang} Kamus : phapus : nama_pointer Algoritma : phapus  awal elemen  baru↑.info If (awal = akhir) Then awal  nil akhir  nil

Else while (phapus↑. next ≠ akhir) do phapus  phapus↑ Else while (phapus↑.next ≠ akhir) do phapus  phapus↑.next endwhile akhir  phapus akhir↑.next  nil EndIf dealloc(phapus) EndProcedure

Middle Deletion Delete one node in middle of linked list if linked list has only one node (awal = akhir). This process is same as front deletion if linked list has only one node.

Middle Deletion (cont’d) If linked list has more than one node (awal ≠ akhir). For example, linked list has four nodes and user want to delete third node. awal 2 5 4 akhir 3

Middle Deletion (cont’d) Search the third node start from the first node. If node is found then save the info of this node to the variable elemen. posisihapus=3 posisihapus=2 posisihapus=1 awal 2 5 4 akhir 3 phapus phapus elemen elemenphapus.info

Middle Deletion (cont’d) Because the connection field of previous node must be connected to the next node of node that will be deleted so we need pointer bantu that refer the node that will be deleted. awal 2 5 4 phapus akhir 3 posisihapus=3 bantu

Middle Deletion (cont’d) Connect the connection field of the node that was referred by pointer bantu to the neighbour node. Delete the node that was referred by pointer phapus. awal 2 5 4 phapus akhir 3 posisihapus=3 bantu bantu.next  phapus.next dealloc(phapus)

Middle Deletion (cont’d) The last result for middle deletion if linked list has more than one node: posisihapus=3 posisihapus=2 posisihapus=1 phapus awal 4 3 bantu phapus 4 3 5 akhir awal akhir 2 5

Traversal Operation that visiting all nodes in linked list start from the first node until last node. awal 2 5 4 akhir 3 For example, shown the process to output data: Place one pointer bantu in the first node awal 2 5 4 akhir 3 bantu

Traversal The value in info field will be output to screen from the node that was referred by bantu then pointer bantu will move to the next node until all nodes were visited (bantu = nil). awal 2 5 4 akhir 3 bantu bantu bantu bantu Screen Output: 3 4 2 5

GRACIAS THANK YOU Copyright © Adam Mukharil Bachtiar 2012 Contact Person: Adam Mukharil Bachtiar Informatics Engineering UNIKOM Jalan Dipati Ukur Nomor. 112-114 Bandung 40132 Email: adfbipotter@gmail.com Blog: http://adfbipotter.wordpress.com Copyright © Adam Mukharil Bachtiar 2012