Algoritma Dan Struktur Data



Algoritma Dan Struktur Data Pendidikan Teknik Informatika

Algoritma dan Struktur Data : Rekursif dan Contoh Soal

Algoritma dan Struktur Data : Rekursif dan Contoh Soal

Introduction to Recursion

A recursive process: one in which objects are defined in terms of other objects of the same type.

Droste Effect: is the effect of a picture appearing within itself, in a place where a similar picture would realistically be expected to appear

Visual Recursion

Recursive Pattern

Recursion in Computer Science

Recursion = Method

The solution to a problem depends on solutions to smaller instances of the same problem.

Two properties :

  • A simple cases (base case, anchor)
  • A set of rules which reduce all other cases toward the base case (recurrence)

Thinking Recursively

List of numbers : 23, 72, 56, 88, 30 

Another list of numbers : 14 ; 23, 57, 20 ; 1, 2 ; etc.

Definition of a list of numbers : 

  • A List of Numbers is a : Number 
  • A List of Numbers is a : Number-comma-List of Numbers

The concept of List of Numbers is used to define itself  !

Infinite Recursion

All recursive definition must have a non-recursive part

Without non-recursive part: no way to terminate the recursive path

Factorial

n!=1 ×2 ×3 ×…×n 

n!=n ×(n-1)×(n-2)×…×1 

n!=n ×(n-1)! 

Recursive Definition of factorial :

Pseudocode

Analysis

Maximum in Array

Problem : Find the largest element in an Array of n elements, n >= 1

Example 

Recursive definition :

Pseudocode

Analysis

Fibonacci Number

Fibonacci Sequence :

  • Leonardo of Pisa a.k.a Fibonacci 
  • Growth of biologically unrealistic rabbit population 

Recursive Definition :

Pseudocode

Analysis On Fibonacci Number

Sum of an Array

Problem : Find the sum of all elements in an Array of n elements, n >= 1

Recursive definition:

Pseudocode

Analysis

Implementation Using Java

Method Calls

Tail v.s. Non-tail Recursion

Tail Recursion: it occurs when the last-executed statement of a function/method is a recursive call

Non-Tail Recursion: Other Recursive methods which are not a tail recursion

Since the recursive call is the last action of the function, there is no need for recursion. Tail recursive methods are easy to convert to iterative. No difference in execution time for most compilers, smart compilers can detect and transform it into a iteration

When Not To Use Recursive

Recursive: elegant and easy 

But, not all problems are solved efficiently using recursive. 

Recursion tree: analyze the recursive call. 

Chain recursion tree: a recursive call makes only one recursive call to itself

Transformation from recursion to iteration is often easy 

Iterative can save both space and time. 

Duplicate tasks in recursion tree: indication of time wasting to solve the same instance of a problem. 

Look up table: never duplicate work by solving the same instance of a problem in separate recursive calls.

Example: Factorial & Fibonacci

Recursion v.s. Iteration

Every recursive function can be transformed into iterative function (or using Stack). Conversely, any iterative program that manipulates a stack can be replaced by a recursive program without a stack. Time complexity can be compared to identify when not to use recursion

In general, recursion needs more space & may cause stack overflow. But easier to design and more readable

Exercises

Create a recursive method/function to:

  • multiply two integers, using only addition and recursion à MULT (a,b) 
  • compute the power of a number à POWER (a,n) 
  • compare two strings (identical or not) à STRCMP (s1,s2) 
  • check if a string is a palindrome à ISPALINDROME (S)

Sumber

Slide ASD : Rekursif

Gallery Algoritma Dan Struktur Data

I Pendahuluan Algoritma Struktur Data

Pertemuan Ke 1 9 Maret 2012 Algoritma Dan Struktur Data

Algoritma Struktur Data Algorithms Programming Language

Pdf Algoritma Dan Struktur Data 1

Algoritma Dan Struktur Data Bab 6 M Gugun

08 Algorithms And Data Structures In Python Dictionary

Welcome To My Blog Berbagi Pengetahuan Tentang

Algoritma Dan Struktur Data List

Algoritma Dan Struktur Data Teori

Algoritma Dan Struktur Data Queue

12 Crs 0106 Revised 8 Feb 2013 Csg2a3 Algoritma Dan Struktur

M Zainury Tugas Algoritma Dan Struktur Data

Algoritma Dan Struktur Data Menggunakan Eclipse Ide For C

Algoritma Dan Struktur Data Minggu 1 Pdf Algoritma Dan

Algoritma Dan Struktur Data I

04 1 Single Linked List Introduction Pptx Csg2a3 Algoritma

Diktat Kuliah Algoritma Dan Struktur Data 2

Ppt Algoritma Dan Struktur Data Powerpoint Presentation

Algoritma Dan Struktur Data Sorting

Belajar Dan Mengenal Dasar Algoritma Dan Struktur Data

5 Kemampuan Wajib Di Kuasai Jika Ingin Bekerja Di Google

Buruan Dibeli Buku Algoritma Dan Struktur Data Bahasa C Keren

Algodanstrukturdata8

Jual Buku Algoritma Dan Struktur Data Pengurutan Dan Pencarian Jakarta Timur Tb Buku Lengkap Tokopedia

12 Graph Pptx Csg2a3 Algoritma Dan Struktur Data Graph

Algoritma Dan Struktur Data I Statistika Ptu 1003 Ugm


0 Response to "Algoritma Dan Struktur Data"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel