Struktur Data 01

26
FTI FTI Data Structure Struktur Data

Transcript of Struktur Data 01

Page 1: Struktur Data 01

FTI

FTI

Data Structure

Struktur Data

Page 2: Struktur Data 01

FTIFTI

BobotBobot 3 SKS3 SKSUTS UTS 20% 20%TugasTugas 15% 15%PraktikumPraktikum 25% 25%UAS UAS 40% 40%Email: Email: [email protected]

[email protected] HP : 081 2339 4114: 081 2339 4114

Page 3: Struktur Data 01

FTIFTI

Materi Kuliah1. Tinjauan umum Struktur Data 2. Array, Record dan Pointer3. Linked List4. Stack, Queue, Rekursi5. Tree6. Graph7. Sorting & Searching

Page 4: Struktur Data 01

FTIFTI

Pokok Bahasan1. Pengantar2. Array3. Record & Pointer4. Link List5. Stack6. Queue7. Recursi8. Ujian Tengah Semester9. Tree

Page 5: Struktur Data 01

FTIFTI

Pokok Bahasan10. Aplikasi Tree11. Graph12. Algoritma Warshall13. Graph dengan Link-list14. Sorting & Searching15. Review seluruh materi16. Ujian Akhir Semester

Page 6: Struktur Data 01

FTIFTI

Referensi

Page 7: Struktur Data 01

FTIFTI

Referensi

Page 8: Struktur Data 01

FTIFTI

Referensi

Page 9: Struktur Data 01

FTIFTI

Referensi

Page 10: Struktur Data 01

FTIFTI

Referensi

Page 11: Struktur Data 01

FTIFTI

Program = data structure algorithmWe need to know basic algorithm and data

structures so that we can produce good-quality computer code

By ‘good-quality’, we mean a program that is efficient, which solves a problem within its resource constraints (space, time)

One cannot become a computer professional without good knowledge of these algorithms and data structures

A data structure organizes informationAn algorithm manipulation information.

Page 12: Struktur Data 01

FTIFTI

Algorithm: a set of well-defined rules for solution of a problem

An algorithm takes the input to a problem and transforms it to the output which solves the problem

A problem can have many algorithms.An algorithm possesses the following properties:

It must be correctIt must be composed of precisely defines stepsThe order of the steps must be precisely definedIt must be composed of a finite number of stepsIt must terminate for all inputs

algorithm

A computer program is an instance, or concrete representation, for an algorithm in some programming language

Page 13: Struktur Data 01

FTIFTI

Data structuresA type is a set of values.

e.g. Integer, BooleanA data type is a type and a collection of operations that manipulate the typee.g. AdditionA data item is a member of a data typeA data item is piece of information (a physical instantiation of a data type)

Page 14: Struktur Data 01

FTIFTI

Data type in Pascal:simple: Integer, Real, Char, BooleanAggregate: Array, Record

Aggregate data type is an example of a data structureit consist of:Simple memberRelationship among the membersOperation on the data structure that allow

the manipulation of its members

Page 15: Struktur Data 01

FTIFTI

In programming languages, some data structures are built-in (e.g. Array, string)

Many other data structures are often needed and they can be implemented using the built-in data structures

These are called user-defined data structuresIn Pascal, we use record to define data structuresOrganized data in logical or mathematical model

of a particular organization of data.It must be rich enough in structure to mirror the

actual relationship of the data in the real worldThe structure should be simple enough that one

can effectively process the data when necessary.

Page 16: Struktur Data 01

FTIFTI

Type of Type of Data StructureData StructureArray: a list of a finite number n of similar

data elements referenced respectively by a set of n consecuitive numbers

Linked list: a linier collection of data items.Stack: a list of elements in which an element

may be inserted or deleted only at one end, called the top of the stack

Queue: a list of elements in which deletions can take place only at one end, called the front, and insertion can take place only at the other end, called the rear.

Page 17: Struktur Data 01

FTIFTI

Tree: data structure which reflects hierarchical relationship between various elements.

Graph: data structure that contain a relationship between pairs of elements which is not necessarily hierarchical in nature.

Page 18: Struktur Data 01

FTIFTI

Data Structure: OperationData Structure: OperationTraversing: accessing record exactly once so that

certain items in the record may be processedSearching: finding the location of the record with a

given key value or finding the location of all records which satisfy one or more conditions.

Inserting: adding a new record to the structureDeleting: removing a record from the structureSorting: arranging the records in some logical orderMerging: combining the records in two different

sorted file into a single sorted file

Page 19: Struktur Data 01

FTIFTI

ArrayLinier data structure: its element form a

sequence or a linier listElements of the array are referenced

respectively by an index set consisting of n consecutive numbers

Elementss of the array are stored respectively in successive memory location

The number n of elements is called the length or size of the array Length=UB-LB+1

*UB:Upper Bound, LB: Lower Bound

Page 20: Struktur Data 01

FTIFTI

Page 21: Struktur Data 01

FTIFTI

Traversing linier array

LA is a linier array with lower bound LB and upper bound UB. This algoritm traverses LA applying an operation PROCESS to each element of LA1. [initial counter] Set K := LB.2. Repeat steps 3 and 4 while K <= UB3. [visit element] Apply PROCESS to LA[K]4. [increase counter] Set K := K + 1 [End of Step 2 loop]5. Exit

Page 22: Struktur Data 01

FTIFTI

INSERT(LA, N, K, ITEM)LA is a linier array with N element and K is a positive integer such that K <= N. This algoritm inserts an element ITEM into the Kth position in LA. 1. [initial counter] Set J := N.2. Repeat steps 3 and 4 while J >= K3. [move Jth element downward] Set LA[J+1]:= LA[J]4. [Decrease counter] Set J := J-1 [End of Step 2 loop]5. [Insert element] Set LA[K]:= ITEM6. [Reset N] Set N := N+17. Exit

insersting linier array

Page 23: Struktur Data 01

FTIFTI

DELETE(LA, N, K, ITEM)LA is a linier array with N element and K is a positive integer such that K <= N. This algoritm deletes the Kth element from LA. 1. Set ITEM := LA[K].2. Repeat for J := K to N-1 [move J+1th element upward] Set LA[J]:= LA[J+1] [Decrease counter] Set J := J-1 [End of loop]3. [Reset the number N of elements in LA] Set N := N-14. Exit

deleting linier array

Page 24: Struktur Data 01

FTIFTI

BUBBLE(DATA, N)DATA is an array with N elements This algorithm sorts the elements in DATA. 1. Repeat step 2 and 3 for K:=1 to N - 12. Set PTR:= 1 [initializes pass pointer PTR]3. Repeat while PTR <=N-K [executes pass] (a) if DATA[PTR] > DATA[PTR+1] then interchange DATA[PTR] and

DATA[PTR+1] (b) Set PTR := PTR + 1 [End of inner loop] [End of step 1 outer loop]4. Exit

Sorting linier array

Page 25: Struktur Data 01

FTIFTI

SEARCH(DATA, N, ITEM, LOC)DATA is a linier array with N elements, and ITEM is a given item of information. This algorithm finds the location LOC of ITEM in DATA, or set LOC:= 0 if the search is unsuccessful.1. [Insert ITEM at the end of DATA] Set

DATA[N+1]:=ITEM2. [Initialize counter] Set LOC := 13. [Search for ITEM] Repeat while DATA[LOC]<>ITEM Set LOC:=LOC+1 [End of loop]4. [Successful ?] If LOC=N+1 then Set LOC:= 05. Exit

searching linier array

Page 26: Struktur Data 01

FTIFTI

BINARY(DATA, LB, UB, ITEM, LOC)DATA is a sorted array with lower bound LB and upper bound UB, and ITEM is a given item of information. The variabel BEG, END and MID denote, respectively, the beginning, end and middle locations of a segment of elements of DATA. This algorithm finds the location LOC of ITEM in DATA or sets LOC= NULL

1. [Initialize segment variable] Set BEG:=LB, END:=UB and MID:=INT(BEG+END)/2

2. Repeat steps 3 and 4 while BEG<=END and DATA[MID] <>ITEM3. If ITEM < DATA[MID] then Set END := MID-1 Else Set BEG := MID + 14. Set MID := INT((Beg+END)/2)

[End of Step 2 loop] 5. If DATA[MID]=ITEM then set LOC:= MID

Else Set LOC:= NULL6. Exit

Binary searching linier array