Sunteți pe pagina 1din 26

Struktur Data

FTI Data Structure

FTI

Bobot UTS Tugas Praktikum UAS

3 SKS 20% 15% 25% 40%

Email: kadwi@yahoo.com kadwi.suharsono@gmail.com HP : 081 2339 4114


FTI

Materi Kuliah
1. Tinjauan umum Struktur Data
2. Array, Record dan Pointer 3. Linked List

4. Stack, Queue, Rekursi


5. Tree 6. Graph

7. Sorting & Searching

FTI

Pokok Bahasan
1. Pengantar 2. Array 3. Record & Pointer 4. Link List 5. Stack 6. Queue 7. Recursi 8. Ujian Tengah Semester 9. Tree
FTI

Pokok Bahasan
10. Aplikasi Tree 11. Graph 12. Algoritma Warshall 13. Graph dengan Link-list 14. Sorting & Searching 15. Review seluruh materi 16. Ujian Akhir Semester

FTI

Referensi

FTI

Referensi

FTI

Referensi

FTI

Referensi

FTI

Referensi

FTI

Program = data structure algorithm


We 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 information An algorithm manipulation information.

FTI

algorithm
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 correct It must be composed of precisely defines steps The order of the steps must be precisely defined It must be composed of a finite number of steps It must terminate for all inputs
A computer program is an instance, or concrete representation, for an algorithm in some programming language

FTI

Data structures
A type is a set of values.

e.g. Integer, Boolean A data type is a type and a collection of operations that manipulate the type e.g. Addition A data item is a member of a data type A data item is piece of information (a physical instantiation of a data type)

FTI

Data type in Pascal:

simple: Integer, Real, Char, Boolean Aggregate: Array, Record Aggregate data type is an example of a data structure it consist of:
Simple member Relationship among the members Operation on the data structure that allow the

manipulation of its members

FTI

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 structures In Pascal, we use record to define data structures Organized 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 world The structure should be simple enough that one can effectively process the data when necessary.

FTI

Type of Data Structure


Array: 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.

FTI

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.

FTI

Data Structure: Operation


Traversing: accessing record exactly once so that certain items

in the record may be processed Searching: 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 structure Deleting: removing a record from the structure Sorting: arranging the records in some logical order Merging: combining the records in two different sorted file into a single sorted file

FTI

Array
Linier data structure: its element form a sequence or a

linier list Elements 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

FTI

FTI

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 LA 1. [initial counter] Set K := LB. 2. Repeat steps 3 and 4 while K <= UB 3. [visit element] Apply PROCESS to LA[K] 4. [increase counter] Set K := K + 1 [End of Step 2 loop] 5. Exit

FTI

insersting linier array


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. 2. 3. 4. 5. 6. 7.

[initial counter] Set J := N. Repeat steps 3 and 4 while J >= K [move Jth element downward] Set LA[J+1]:= LA[J] [Decrease counter] Set J := J-1 [End of Step 2 loop] [Insert element] Set LA[K]:= ITEM [Reset N] Set N := N+1 Exit

FTI

deleting linier array


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. 2.

3. 4.

Set ITEM := LA[K]. 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] [Reset the number N of elements in LA] Set N := N-1 Exit

FTI

Sorting linier array


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 - 1 2. 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 FTI

searching linier array


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]:=ITEM 2. [Initialize counter] Set LOC := 1 3. [Search for ITEM] Repeat while DATA[LOC]<>ITEM Set LOC:=LOC+1 [End of loop] 4. [Successful ?] If LOC=N+1 then Set LOC:= 0 5. Exit FTI

Binary searching linier array


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. 2. 3. 4. 5. 6.

[Initialize segment variable] Set BEG:=LB, END:=UB and MID:=INT(BEG+END)/2 Repeat steps 3 and 4 while BEG<=END and DATA[MID] <>ITEM If ITEM < DATA[MID] then Set END := MID-1 Else Set BEG := MID + 1 Set MID := INT((Beg+END)/2) [End of Step 2 loop] If DATA[MID]=ITEM then set LOC:= MID Else Set LOC:= NULL Exit

FTI

S-ar putea să vă placă și