Presented By: Mahmoud Rafeek Alfarra

Slides:



Advertisements
Similar presentations
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Advertisements

Fundamentals of Computer Science Lecture 14: Recursion Instructor: Evan Korth New York University.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
CS212: DATASTRUCTURES Lecture 3: Recursion 1. Lecture Contents 2  The Concept of Recursion  Why recursion?  Factorial – A case study  Content of a.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 1: Course overview.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION.
Lecture6 Recursion function © by Pearson Education, Inc. All Rights Reserved. 1.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions (Recursion) Outline 5.13Recursion 5.14Example.
CS212: DATASTRUCTURES Lecture 3: Recursion 1. Lecture Contents 2  The Concept of Recursion  Why recursion?  Factorial – A case study  Content of a.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
1 Recursion Recursive method –Calls itself (directly or indirectly) through another method –Method knows how to solve only a base case –Method divides.
Introduction To Programming Information Technology , 1’st Semester
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 15,16 Java’s Methods.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
A Brief Introduction to Recursion. Recursion Recursive methods … –methods that call themselves! –They can only solve a base case –So, you divide a problem.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Chapter Topics Chapter 16 discusses the following main topics:
Functions.
Chapter 15 Recursion.
Introduction to Recursion
Introduction to Programming
RECURSION.
Chapter 7 - Methods Outline Note: Inconsistent with textbook subsection numbering […] 7.13 Recursion […]
Chapter 15 Recursion.
Presented By: Mahmoud Rafeek Alfarra
Introduction to Computer Science - Alice
Introduction To Programming Information Technology , 1’st Semester
Recursion Chapter 11.
JavaScript: Functions Part II
Part a: Fundamentals & Class String
Functions Recursion CSCI 230
Presented By: Mahmoud Rafeek Alfarra
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Introduction To Programming Information Technology , 1’st Semester
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
Computer Science Core Concepts
CS302 - Data Structures using C++
Java Programming: Chapter 9: Recursion Second Edition
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
CS148 Introduction to Programming II
C Programming Pointers
Chapter 9: Pointers and String
Dr. Sampath Jayarathna Cal Poly Pomona
Programming Fundamentals Lecture #7 Functions
CSE 206 Course Review.
Presented By: Mahmoud Rafeek Alfarra
Presentation transcript:

Presented By: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE DATA STRUCTURE Using C# Information Technology , 3’rd Semester Lecture 5: Recursion & Pointers Presented By: Mahmoud Rafeek Alfarra

Outline Recursion The factorial Recursion vs. Iteration Emank X Mezank !!

Recursion A recursive method is a method that calls itself either directly or indirectly through another method. Recursion is an important topic discussed at length in upper-level computer science courses. Call Presented & Prepared by: Mahmoud R. Alfarra

The factorial The factorial of an integer number greater than or equal to 0 can be calculated iteratively (nonrecursively) using for as follows: HW 5.1 Write a method that performs the factorial using recursion Presented & Prepared by: Mahmoud R. Alfarra

The factorial Presented & Prepared by: Mahmoud R. Alfarra

The factorial If (number is less than or equal 1) Return 1 else 6 If (number is less than or equal 1) Return 1 else Return number * method(number-1) HW 5.2 Write a method that performs the factorial using recursion technique HW 5.3 Case study : The Fibonacci Series Presented & Prepared by: Mahmoud R. Alfarra

Recursion vs. Iteration Both iteration and recursion are based on a control structure. Iteration uses a repetition structure (such as for, while or do/while) Recursion uses a selection structure (such as if, if/else or switch). Presented & Prepared by: Mahmoud R. Alfarra

Recursion vs. Iteration Both iteration and recursion involve repetition. Iteration explicitly uses a repetition structure. Recursion achieves repetition through repeated method calls. Iteration and recursion each involve a termination test. HW 5.4 Case study : notes more differences between them Presented & Prepared by: Mahmoud R. Alfarra

What is Pointers ? 9 A pointer is nothing but a variable that holds the memory address of another type. In C#, pointer can only be declared to hold the memory address of value types and arrays. Presented & Prepared by: Mahmoud R. Alfarra

Declaring a Pointer type 10 The general form of declaring a pointer type is as shown below type * variable_name;  Where * is known as the de-reference operator int *x ; This Declares a pointer variable x, which can hold the address of an int type. The reference operator (&) can be used to get the memory address of a variable. int x = 100; The &x gives the memory address of the variable x, which we can assign to a pointer variable int *ptr = & x ; Presented & Prepared by: Mahmoud R. Alfarra

Pointers Console.WriteLine((int)ptr) // Displays the memory address 11 Console.WriteLine((int)ptr) // Displays the memory address Console.WriteLine(*ptr) // Displays the value at the memory address. 01011AB10 ptr 78 The value of (*ptr) is 78 But the value of (ptr) is 01011AB10 Presented & Prepared by: Mahmoud R. Alfarra

Pointers 12 using System; class MyClass { public void Method() { // code { int x = 10; int y = 20; int *ptr1 = &x; int *ptr2 = &y; Console.WriteLine((int)ptr1); Console.WriteLine((int)ptr2); Console.WriteLine(*ptr1); Console.WriteLine(*ptr2); } } } Presented & Prepared by: Mahmoud R. Alfarra

Emank X Mezank !! قال رسول الله صلى الله عليه وسلم : ( كلكم يدخل الجنـة إلا من أبى, قالوا و من يأبى يا رسول الله ؟ قال : من أطاعني دخل الجنة و من عصاني فقد أبى) رواه البخاري

Next Lecture Linked List