0% found this document useful (0 votes)
5 views

Module – III (1)

python

Uploaded by

vidhyapm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Module – III (1)

python

Uploaded by

vidhyapm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 116

Module – III

UCEST105 - ALGORITHMIC THINKING WITH PYTHON

Compiled By
Mr. Shyam Krishna K
Assistant Professor
Dept. of AI & DS
Muthoot Institute of Technology & Science
[email protected]
Syllabus (10 Hours)
SELECTION AND ITERATION USING PYTHON:- if-else, elif,
for loop, range, while loop. Sequence data types in Python - list,
tuple, set, strings, dictionary, Creating and using Arrays in Python
(using Numpy library).
DECOMPOSITION AND MODULARIZATION* :- Problem
decomposition as a strategy for solving complex problems,
Modularization, Motivation for modularization, Defining and using
functions in Python, Functions with multiple return values
RECURSION:- Recursion Defined, Reasons for using Recursion,
The Call Stack, Recursion and the Stack, Avoiding Circularity in
Recursion,

UCEST105 - Module III 2


Course Outcome (CO3)
Apply the essential Python
programming skills, to translate the
algorithmic model into an
executable program.

UCEST105 - Module III 3


SELECTION AND
ITERATION USING
PYTHON

UCEST105 - Module III 4


if and if-else Statements
• if statement is also known as conditional execution.
• Ex:
# check if number is greater than 0
if number > 0:
print('Number is positive.')
• It is possible to combine multiple conditions using logical
operators.
• Ex:
x=int(input("Enter a number"))
if x > 0 and x < 10:
print(x,"is a positive single digit.")

UCEST105 - Module III 5


if and if-else Statements
• Python provides an alternative syntax for writing the condition in
the above code that is similar to mathematical notation:
• Ex:
x=int(input("Enter a number"))
if 0<x<10:
print(x,"is a positive single digit.")

UCEST105 - Module III 6


Two-way selection statement
• The if-else statement, also known as alternative execution, is the
most common type of selection statement in Python
• Ex:
age = int(input("Enter age: "))
if age > 18:
print(“Major”)
else:
print(“Minor”)

UCEST105 - Module III 7


Multi-way selection statement
• Multi-way selection is achieved through the if-elif-else
statement.
• elif is the abbreviation of “else if”
• Ex: The multi-way if
x = 10 statement is called
chained conditional
y = 5
execution.
if x < y:
print(x,“ is less than ”,y)
elif x > y:
print(x, "is greater than", y)
else:
print(x, "and", y, "are equal")
UCEST105 - Module III 8
Repetition statements or loops
• Python supports two types of loops – those that repeat an action a
fixed number of times (definite iteration) and those that act until a
condition becomes false (conditional iteration).

UCEST105 - Module III 9


Definite iteration: The for loop
• We use for in association with the range() function that dictates
the number of iterations.
• To be precise, range(k) when used with for causes the loop to
iterate k times.
• Ex:
for i in range(5): range(k) starts
print("Hello") counting from 0,
incrementing after each
iteration, and stops on
reaching k − 1.

UCEST105 - Module III 10


end = " "
• By using end = " ", the Python interpreter will append
whitespace following the count value, instead of the default
newline character (‘\n’)
• To get the numbers on the same line you need to write
print(count,end=" ").
• Ex:
for i in range(5):
print(i,end=" ") Output
0 1 2 3 4

UCEST105 - Module III 11


for loop
• By default, the for loop starts counting from 0.
• To count from an explicit lower bound, you need to include it as
part of the range function.
• Ex:
for count in range(1,11):
print(count,end=" ")

UCEST105 - Module III 12


for loop
• Python provides a third variant of the for loop that allows to count
in a non-consecutive fashion.
• For this, you need to explicitly mention the step size in the range
function.
• Ex: The following code prints the even numbers between 4 and 20 (both inclusive).
for i in range(4,21,2):
print(i,end=" ")

UCEST105 - Module III 13


for loop
• When the step size is negative, the loop variable is decremented by
that amount in each iteration
• Ex: The following code displays numbers from 10 down to 1
for count in range(10,0,-1):
print(count,end=" ")

UCEST105 - Module III 14


Conditional Iteration: The while loop
• Conditional iteration requires that a condition be tested within the
loop to determine whether the loop should continue.
• Python’s while loop is tailormade for this type of control logic
• Ex:
i = 1
while i <= 10:
print(i,end=" ")
i = i + 1

UCEST105 - Module III 15


Nested loops
• It is possible to have a loop inside another loop.
• We can have a for loop inside a while loop or inside another for
loop. The same is possible for while loops too.
• The enclosing loop is called the outer loop, and the other loop is
called the inner loop.
• The inner loop will be executed once for each iteration of the outer
loop.

UCEST105 - Module III 16


Nested loops
Ex:
for i in range(1,5): #This is the outer loop
for j in range(1,5): #This is the inner loop
print(j, end=" ")
print()

UCEST105 - Module III 17


Loop control statements - break statement
• The break statement is used to terminate loops.
• Any statements inside the loop following the break will be
neglected, and the control goes out of the loop.
• break stops the current iteration and skips the succeeding
iterations (if any) and passes the control to the first statement
following (outside) the loop.

UCEST105 - Module III 18


Loop control statements - break statement
Ex:
for num in range(1,5):
if num%2==0:
print(num,"is even")
break
print("The number is",num)
print("Outside the loop")

UCEST105 - Module III 19


Loop control statements - continue statement
• The continue statement is used to bypass the remainder of the
current iteration through a loop.
• The loop does not terminate when a continue statement is
encountered.
• Rather, the remaining loop statements are skipped and the control
proceeds directly to the next pass through the loop.

UCEST105 - Module III 20


Loop control statements - continue statement
Ex:
for num in range(1,5):
if num%2==0:
print(num,"is even")
continue
print("The number is",num)
print("Outside the loop")

UCEST105 - Module III 21


Loop control statements - pass statement
• The pass statement is equivalent to the statement “Do nothing”.
• It can be used when a statement is required syntactically but the
program requires no action.
• Nothing happens when passis executed.
• It results in a NOP (No OPeration).
• After the pass is executed, control proceeds as usual to the next
statement in the loop.

UCEST105 - Module III 22


Loop control statements - pass statement
Ex:
for num in range(1,5):
if num%2==0:
print(num,"is even")
pass
print("The number is",num)
print("Outside the loop")

UCEST105 - Module III 23


SEQUENCE DATA TYPES IN
PYTHON

UCEST105 - Module III 24


Lists
• A list is an ordered set of data values.
• The values that make up a list are called its elements or items.
• The logical structure of a list is similar to that of a string.
• Each item in the list has a unique index that specifies its position
and the items are ordered by their positions.
Lists
Creating lists
• To create a new list; you simply enclose the elements in a pair of
square brackets ([ ]).
Creating lists
• a list can have another list as its element.
• Such a list is called nested list.
• The list which is a member of another list is called a member list.
• A list that contains no elements is called an empty list, denoted as
[ ].
Creating lists
• Lists of integers can also be built using the range() and list()
functions.
Length of a list
• you can determine its length (number of elements in the list) using
the len() method.
• In the case of a nested list, the member list will be counted as a
single element.

UCEST105 - Module III 29


Accessing list elements and traversal
• List indices work the same way as string indices. Thus you can use
the subscript operator to access the list elements.

UCEST105 - Module III 30


Accessing list elements and traversal

UCEST105 - Module III 31


Accessing list elements and traversal
• Printing the list by specifying its name in the print method
displays the list elements enclosed in a pair of brackets.
• To display the entire list without the brackets themselves, you
should traverse the list printing the elements one by one.

UCEST105 - Module III 32


List Comprehension
• Creating a new list from an existing list is called list
comprehension.

The statement
odd = [num for num in numbers if num%2 != 0]
essentially directs the interpreter to iterate through the list numbers
and copy all odd numbers to another list odd.

UCEST105 - Module III 33


List Comprehension – Example
• Create a list of two-digit even numbers using list comprehension

>>> even2dig = [num for num in range(10,100) if


num%2 == 0]
>>> print(even2dig)

UCEST105 - Module III 34


List Comprehension – Example
• Replace all multiples of 5 (less than 30) with -1,using list
comprehension

>>> nomul5 = [num if num%5 != 0 else -1 for num


in range(20)]
>>> print(nomul5)

UCEST105 - Module III 35


List operations
• The + operator concatenates lists:

• The * operator repeats a list a given number of times:

UCEST105 - Module III 36


List operations
• Equality operator checks if two lists have the same elements.

• Relational operators also works well with lists.


• Python starts by comparing the first element from
each list. If they are equal, it goes on to the next
element, and so on, until it finds the first pair of
elements that are different and determines the
relation between them.
• In the example, prime[0] == even[0].
• Next, prime[1] and even[1] are compared. Thus
the resulting relation is ‘ even is thus False.
• Note that once the result is determined, the
subsequent elements are skipped.

UCEST105 - Module III 37


List operations
• Membership operation also works ion lists

UCEST105 - Module III 38


List slices
• The slice operator on a list follows the same rules as applied to
strings.

UCEST105 - Module III 39


List mutations
• Unlike strings, lists are mutable.
• In other words, a list is updatable – elements can be inserted,
removed, or replaced.
• You use the subscript operator to replace an element at a given
position:

• You can also replace a single list item with a new list.

UCEST105 - Module III 40


Slice operator and mutations
• The slice operator is a nice tool to mutate lists in terms of
replacing, inserting, or removing list elements.

Replacing elements
• You can use the slice operator to replace a single element or
multiple elements in a list.

UCEST105 - Module III 41


Inserting elements
• The slice operator is useful for inserting new elements into a list at
the desired location:

UCEST105 - Module III 42


Removing elements
• The slice operator can also be used to remove elements from a list
by assigning the empty list to them.

UCEST105 - Module III 43


Using del keyword for deletion
• Python provides the del keyword exclusively for deletion.

UCEST105 - Module III 44


List methods

UCEST105 - Module III 45


Strings and lists
• To construct a list out of the characters from a string, you can use
list() method as follows:

UCEST105 - Module III 46


split() method
• If you want to split a multi-word string into its constituent words
and construct a list out of those words, you should use the
split() method:

• In the above example, the white space where you split the string is
known as the delimiter.
• If you want to specify a different delimiter, you can pass that
character (or even a string) as an argument to the split()
method.

UCEST105 - Module III 47


join() method
• The join() method works in the opposite sense of split().
• It concatenates a list of strings by inserting a “separator” between
them.

UCEST105 - Module III 48


List aliasing and cloning
• If you assign a list variable to another, both variables refer to the
same list.
• Because the same list has two different names now, we say that the
list is aliased.
• Changes made with one list affect the other.

UCEST105 - Module III 49


List aliasing and cloning
• If you want to modify a list and also keep a copy of the original,
you need to use a technique called cloning.
• The easiest way to clone a list is to use the slice operator.

UCEST105 - Module III 50


Tuples

UCEST105 - Module III 51


Tuple
• A tuple is a sequence of values that resembles a list, except that a
tuple is immutable.
• You create a tuple by enclosing its elements in parentheses instead
of square brackets.
• The elements are to be separated by commas.

• To create a tuple with a single element, we have to include a comma


at the end, even though there is only one value. Without the comma,
Python treats the element as a string in parentheses.

UCEST105 - Module III 52


Tuple creation
• Another way to create a tuple is to use the tuple() function.

UCEST105 - Module III 53


Tuple operations
• Most of the operators and functions used with lists can be used
similarly with tuples.
• But, unlike lists, tuples are immutable – you are bound to get error
when you try to modify the tuple contents.

UCEST105 - Module III 54


Tuple operations
• Python provides a quick way to swap two variables a and b without
using any third temporary variable:

UCEST105 - Module III 55


The numpy package and arrays
• NumPy stands for Numerical Python.
• It is an excellent package for advanced computing in Python like
linear algebra, Fourier transforms, and random simulation.
• This package also provides extensive support for arrays.
• if you want to use the components in NumPy, you should first
import the package.
• NumPy is usually imported with the np alias name:
import numpy as np
Now the NumPy package can be referred to as np instead of numpy.

UCEST105 - Module III 56


Set

UCEST105 - Module III 57


Set
• A set is a collection of items just as tuples or lists but unlike the
other two, a set is unordered; the items in a set do not have a
defined order.

Creating a set and accessing its elements

• A set is created by enclosing the items in a pair of braces.


Following are some examples:

UCEST105 - Module III 58


Creating a set and accessing its elements
• You can also use the set method to create a set from a list or a
tuple as follows:

• The items in a set aren’t associated with index or position. This


means it is impossible to print an arbitrary element of the set.

UCEST105 - Module III 59


Creating a set and accessing its elements
• To traverse the set, use a for loop:

• Sets do not allow duplicate elements. The duplicates are


automatically removed even if you supply non-unique values.

UCEST105 - Module III 60


Adding and removing set elements
• To add a single element to a set, you use the add() method:

• To add multiple items to a set, the update() method is to be used:

UCEST105 - Module III 61


Adding and removing set elements
• To remove an item from a set, you should use the remove()
method:

• A second way to remove an item from a set is to use the discard()


method which works the same way as remove. The difference
between these two methods is that discard() will not raise an error
if the item to be removed doesn’t exist in the set unlike remove().

UCEST105 - Module III 62


Adding and removing set elements
• To remove all the set items at once, you can use the clear() method

• The keyword del can be used to delete the set itself, that is, after
the del operation, the set will not exist anymore. Any subsequent
access to the set will throw an error.

UCEST105 - Module III 63


Sets and relational operators
• The relational operators can be used to check the relationship
(subset, superset, etc) between two sets.

UCEST105 - Module III 64


Sets and relational operators

UCEST105 - Module III 65


Mathematical set operations on Python sets
• Python supports all the mathematical set operations (union,
intersection, etc.).

UCEST105 - Module III 66


Dictionaries

UCEST105 - Module III 67


Dictionaries
• A dictionary associates a set of keys with data values.
• A dictionary is a mapping between a set of keys and a set of values.
• Each key maps to a value.
• The association of a key and a value is called a key-value pair,
sometimes called an item or an entry.
• A Python dictionary is written as a sequence of key/value pairs
separated by commas and the entire sequence is enclosed in a pair
of braces.

UCEST105 - Module III 68


Dictionaries
• Each key is separated from its value by a colon (:). Such a list of
key-value pairs enclosed in a pair of braces is known as a
dictionary literal.

• Here Name, Age and Class are keys whereas Ram, 18 and S1 are
the corresponding values.
• An empty dictionary without any items is written as {}.

UCEST105 - Module III 69


Dictionaries
• Keys are unique within a dictionary although values need not be.
• Although the entries may appear to be ordered in a dictionary, this
ordering is not the same, each time we print the entries.
• In general, the order of items in a dictionary is unpredictable.

UCEST105 - Module III 70


Dictionary operations - Accessing values
• The subscript operator is used to obtain the value associated with a
key.

• if the key is not present in the dictionary, Python raises an error

UCEST105 - Module III 71


Traversing a dictionary
• A simple for loop can be used to traverse a dictionary

UCEST105 - Module III 72


Inserting keys and updating key values
• You should use the subscript operator to add a new key/value pair
to the dictionary.

• The subscript is also used to replace the value of an existing key:

UCEST105 - Module III 73


Removing keys
• To remove a key from a dictionary, use the del operator. The
corresponding key-value pair will be removed.

UCEST105 - Module III 74


Miscellaneous operations
• The len() function returns the number of key-value pairs in a
dictionary:

• The in operator can be used to know if a key exists in the


dictionary.

UCEST105 - Module III 75


Dictionary methods
• Python provides several methods to manipulate the dictionary
elements.

UCEST105 - Module III 76


Dictionary aliasing and copying
• Assigning a dictionary literal to another creates an alias of the
original dictionary. In this case, the changes made to one will affect
the other.
• If you want to modify a dictionary and keep a copy of the original,
you need to use the copy() method. With a copy, you can make
changes to it without affecting the original.

UCEST105 - Module III 77


Dictionary aliasing and copying

UCEST105 - Module III 78


Strings
Please refer contents shared in Module – I Lecture PPT

UCEST105 - Module III 79


The string module
• The string
module
contains
string
methods
that can be
used to
manipulate
strings.

UCEST105 - Module III 80


Arrays

UCEST105 - Module III 81


Arrays
• An array is a homogeneous collection of data items, unlike lists
and tuples that are heterogeneous.

Creating arrays
• To create an array, you use the array() method of numpy package
as shown below:

UCEST105 - Module III 82


Creating arrays
• You can also create matrices (two-dimensional arrays) with
array() method:

• To know the dimensions of an array, you use the ndim attribute in


NumPy.

UCEST105 - Module III 83


Creating arrays
• To know the size across each dimension, you use the shape
attribute:

UCEST105 - Module III 84


Accessing array elements
• Indexing and slicing work the same way with arrays as with other
sequences like lists, and tuples.

UCEST105 - Module III 85


Accessing array elements
• for loop is used to traverse the array:

UCEST105 - Module III 86


Changing array dimensions
• Changing the array dimensions means to increase or decrease the
number of dimensions.
• For this, you use the reshape() method.

When you convert a one-dimensional array


into a two-dimensional array, there should be
enough number of elements to fill all the rows.
Otherwise, you will end up with an error.

UCEST105 - Module III 87


Matrix operations
• NumPy has excellent support for doing most of the matrix
operations.

UCEST105 - Module III 88


Matrix operations

UCEST105 - Module III 89


Functions

UCEST105 - Module III 90


What is Problem Decomposition?
• When solving a programming problem, problem decomposition is
a critical strategy to design efficient and maintainable solutions.
• It involves breaking down a larger programming task into smaller,
self-contained modules or functions that are easier to understand,
code, test, and debug.

UCEST105 - Module III 91


Functions
• Solutions for complex real-world problems are nevertheless going
to be simple.
• Essentially, you should divide your proposed solution into
subtasks. This is the idea of decomposition.
• Modularization takes it one step further by keeping the subtasks
as independent as possible. These subtasks are known as modules.
• A module is a named, self-contained block of statements that
carries out some specific, well-defined task. The modules should
have minimal interaction among them so that one module does not
affect another.

UCEST105 - Module III 92


Motivations for modularization
• Promotes re-use
• If the system functionality is divided into modules, other systems can
reuse them. Thus, a programmer can build on what others have already
done, instead of starting from scratch. This also eliminates redundancy
(duplication of code) to a great extent.
• Hides complexity:
• Since a module is self-contained, it does whatever it is intended to. If you
want the functionality provided by a module, you access the module and
get it done, without worrying about how the functionality is achieved.
This mechanism is called abstraction.
• Supports division of labour:
• Ideally, each module achieves a single goal. A complex task could be
divided into simpler sub-tasks, each of which can be performed by
individual modules. This promotes parallel operation with different teams
working on separate modules, speeding up the entire process with
improved collaboration among the teams.

UCEST105 - Module III 93


Motivations for modularization
• Improves debugging and testing:
• Since modules have minimal interaction among themselves, you can
isolate a module and investigate it separately to pinpoint errors, if any.
Each of the modules can be individually tested for correctness and
efficiency. This reduces the risk when the modules are integrated to build
the big picture.
• Contributes to scalability:
• New modules can be added to an existing system to enhance its
functionality. This makes the system scalable without having to redesign
the entire thing.
• Reduces development costs:
• The reuse of existing modules contributes to cost savings in
development. Also, the self-containment aspect of modules makes the
system maintenance cost-effective and produ.

UCEST105 - Module III 94


The anatomy of functions – Function Definition
• A function should be “defined” before its first use.
• To define a function, you specify its name and then write the logic
for implementing its functionality
Header

Function Body

Function definition begins with the keyword def followed by the


function name.
The header has to end with a colon, and the body has to be indented.
UCEST105 - Module III 95
Function Call
• The function will not get executed unless it is called.
• You call a function by its name, passing (supplying) the value for
each parameter separated by commas and the entire list enclosed in
parentheses

UCEST105 - Module III 96


Arguments and return value
• Arguments are the way you supply data to a function for
processing.
• The function performs the operations on the received data and
produces the result which is given back through the return
statement.
• The value that is given back is known as the return value.
• Technically, you say that a function “receives” one or more
arguments and “returns” a result.
• The parameters in the function definitions are called formal
parameters, and those in the function call are called actual
parameters.

UCEST105 - Module III 97


Arguments and return value
• Function with no arguments and no return value
• Function with arguments but no return value
• Function with return value but no arguments
• Function with arguments and return value

UCEST105 - Module III 98


Return Statement
• In Python, the return statement is used inside a function to send a
result back to the caller.
• It allows a function to produce a value that can be used later in the
program.
• Without the return statement, a function doesn't return anything by
default, and the value returned is None.

UCEST105 - Module III 99


Returning Multiple Values
• Returning Multiple Values as a Tuple (Most Common Method)
• The simplest and most common way to return multiple values from a
function is by using a tuple.
• Python automatically creates a tuple when you return more than one
value separated by commas.

Accessing Values: You can


unpack the tuple later when
you call the function

UCEST105 - Module III 100


Returning Multiple Values
• Returning Multiple Values as a List
• A function can return a list to hold multiple values. Lists are mutable,
meaning you can modify them after they are returned.

UCEST105 - Module III 101


Algorithm and flowchart for modules

UCEST105 - Module III 102


Recursion

UCEST105 - Module III 103


Recursion
• Recursion is a programming technique where a function calls itself
to solve a smaller instance of the same problem.
• This process continues until the problem is reduced to a base
case—a condition where the recursion stops
• A recursive function generally has the following structure:
• Base Case: A condition to stop the recursion and prevent infinite calls.
• Recursive Case: A smaller version of the same problem, leading toward
the base case.

UCEST105 - Module III 104


UCEST105 - Module III 105
Key Components of Recursion
• Base Case: The base case is critical as it ensures that the recursion
terminates.
• Without it, the function will keep calling itself indefinitely, causing
a stack overflow.

def countdown(n):
if n == 0: # Base case
print(“Hello All!")
else:
print(n)
countdown(n - 1) # Recursive call

UCEST105 - Module III 106


Key Components of Recursion
• Progress Toward the Base Case: Each recursive call must reduce
the size or complexity of the problem, moving it closer to the base
case.

def sum_numbers(n):
if n == 0: # Base case
return 0
else:
# Progressing towards base case
return n + sum_numbers(n - 1)

UCEST105 - Module III 107


The Call Stack
• A stack is a data structure that follows the LIFO (Last In, First Out)
principle. The last item added to the stack is the first item removed.
• The call stack is a special data structure used by programs to
manage function calls. Whenever a function is called:
• The current state of the function (execution context) is pushed onto the
call stack.
• The recursive call creates a new instance of the function, which is also
pushed onto the stack.
• When the base case is reached, the stack begins to unwind, resolving
each function call in reverse order.

UCEST105 - Module III 108


How the Stack Works in Recursion

UCEST105 - Module III 109


UCEST105 - Module III 110
Recursion tree for 4!

UCEST105 - Module III 111


Avoiding Circularity in Recursion
• Circularity in recursion occurs when the function lacks a clear base
case or fails to progress toward it, leading to infinite recursive calls
and eventual stack overflow.
• To avoid circularity:
• Always Define a Base Case: Ensure there's a condition to terminate
recursion. For example, in a factorial function, the base case is when n
== 1.

• Progress Toward the Base Case: Ensure that each recursive call moves
the problem closer to the base case. For instance, decrementing n in
factorial(n - 1) ensures progress.

• Test Your Function Thoroughly: Check edge cases to verify that the
base case is reached under all conditions.

UCEST105 - Module III 112


Avoiding Circularity in Recursion

UCEST105 - Module III 113


Reasons for using Recursion
• Simplifies Complex Problems
• Some problems are naturally recursive, meaning they are easier to break
down into smaller subproblems of the same type (e.g., traversing trees,
solving mazes, etc.).
• Example: Calculating factorial, navigating hierarchical data (e.g., file
systems).

• Reduces Code Complexity


• Recursive solutions often require fewer lines of code compared to
iterative solutions, making the logic easier to understand and maintain.
• A recursive Fibonacci sequence implementation is much shorter than its
iterative counterpart.

UCEST105 - Module III 114


Reasons for using Recursion
• Better Representation for Divide and Conquer Algorithms
• Algorithms like Merge Sort, Quick Sort, and Binary Search are naturally
expressed using recursion since they divide the problem into smaller
subproblems.

• Processes Dynamic Structures


• Data structures like trees and graphs are easier to process using recursion
because their structure is hierarchical and self-referential.
• Example: Traversing a binary tree (e.g., pre-order, in-order, or post-order
traversal).

• Handles Infinite or Unknown Sizes


• In scenarios where the size of the problem isn't fixed or predictable,
recursion can adapt dynamically to solve the problem.
• Example: Generating permutations or subsets of a set.
UCEST105 - Module III 115
Thank you…
Compiled By,
Shyam Krishna K
Asst. Prof. | Dept. of AI & DS | MITS
[email protected]

UCEST105 - Module III 116

You might also like