Csf101 Unit 03

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 53

CSF101: Programming for Problem-

Solving

Session: 2023-24

B. Tech 1st Semester

Unit-3: Arrays & Functions


Course Instructor
Dr. Madhu Sharma
Assistant Professor, School of Computing
Need of Array Variable
• Suppose we need to store rollno of the student in the integer
variable.
Declaratio
n
int rollno;

• Now we need to store rollno of 100 students.


Declaratio
n
int rollno101, rollno102, rollno103,
rollno104...;
• This is not appropriate to declare these many integer variables.
e.g. 100 integer variables for rollno.
• Solution to declare and store multiple variables of similar type is an
array.
• An array is a variable that can store multiple values.
Definition: Array
• An array is a fixed size sequential collection of elements of
same data type grouped under single variable name.
[0] [1] [2] … [99]
int rollno[100
];

Fixed Size Sequential Same Data type Single Name


Here, the size of an It is indexed to 0 to All the elements (0- All the elements (0-
array is 100 (fixed) 99 in sequence 99) will be integer 99) will be referred
to store rollno variables as a common name
rollno
Declaring an array
Syntax • By default array index
data-type variable- starts with 0.
name[size];
• If we declare an array
Integer [0] [1] [2] [3] [4] of size 5 then its
Array
int mark[5]; index ranges from 0
to 4.
integer • First element will be
store at mark[0] and
Float Array [0] [1] [2] [3] [4] last element will be
float avg[5] stored at mark[4] not
; mark[5].
float • Like integer and float
array we can declare
array of type char.
Initialing and Accessing an Array
Declaring, initializing and accessing single integer
variable
int mark=90; //variable mark is initialized with value 90
printf("%d",mark); //mark value printed

Declaring, initializing and accessing integer array


variable
int mark[5]={85,75,76,55,45}; //mark is initialized with 5 values
printf("%d",mark[0]); //prints 85
printf("%d",mark[1]); //prints 75
printf("%d",mark[2]); //prints 65
printf("%d",mark[3]); //prints 55
printf("%d",mark[4]); //prints 45

[0] [1] [2] [3] [4]


mark[5] 85 75 65 55 45
Read(Scan) Array Elements
Reading array without Reading array using
loop loop
1 void main() 1 void main()
2 { 2 {
3 int mark[5]; 3 int mark[5],i;
printf("Enter array element="); for(i=0;i<5;i++)
4 4
scanf("%d",&mark[0]); {
5 printf("Enter array element="); 5 printf("Enter array element=");
6 scanf("%d",&mark[1]); 6 scanf("%d",&mark[i]);
7 printf("Enter array element="); 7 }
8 scanf("%d",&mark[2]); 8 for(i=0;i<5;i++)
9 printf("Enter array element="); 9 {
10 scanf("%d",&mark[3]); 10 printf("%d",mark[i]);
11 printf("Enter array element="); 11 }
scanf("%d",&mark[4]); }
12 12
13 printf("%d",mark[0]);
14 printf("%d",mark[1]);
15 printf("%d",mark[2]);
16 printf("%d",mark[3]); [0] [1] [2] [3] [4]
17 printf("%d",mark[4]);
mark[5] 85 75 65 55 45
18 }
Develop a program to count number of positive or
negative number from an array of 10 numbers.
Program
1 void main(){ Outpu
2 int num[10],i,pos,neg; t
3 pos = 0; Enter array element=1
4 neg = 0; Enter array element=2
5 for(i=0;i<10;i++) Enter array element=3
6 { Enter array element=4
7 printf("Enter array element="); Enter array element=5
8 scanf("%d",&num[i]); Enter array element=-1
9 } Enter array element=-2
10 for(i=0;i<10;i++) Enter array element=3
11 { Enter array element=4
12 if(num[i]>0) Enter array element=5
13 pos=pos+1; Positive=8,Negative=2
14 else
15 neg=neg+1;
16 }
17 printf("Positive=%d,Negative=
18 %d",pos,neg);
}
Develop a program to read n numbers in an array and
print them in reverse order.
Program
1 void main() Outpu
2 { t
3 int num[100],n,i; Enter number of array
4 printf("Enter number of array elements= elements=5
5 "); Enter array element=1
6 scanf("%d",&n); Enter array element=2
7 //loop will scan n elements only Enter array element=3
8 for(i=0;i<n;i++) Enter array element=4
9 { Enter array element=5
10 printf("Enter array element="); 5
11 scanf("%d",&num[i]); 4
12 } 3
13 // 2
14 negative loop to print array in reverse ord 1
15 er
16 for(i=n-1;i>=0;i--)
17 {
printf("%d\n",num[i]);
}
}
Multi Dimensional Array
Declaring 2 Dimensional Array
Syntax • A two dimensional
data-type variable-name[x][y]; array can be seen as
Declaratio
a table with ‘x’ rows
n and ‘y’ columns.
int data[3][3]; //
This array can hold 9 elements • The row number
ranges from 0 to (x-
int data[3][3]; 1) and column
Column-0 Column-1 Column-2
number ranges from 0
to (y-1).
data[0] data[0] data[0]
Row-0
[0] [1] [2]
data[1] data[1] data[1]
Row-1
[0] [1] [2]
data[2] data[2] data[2]
Row-2
[0] [1] [2]
Initialing and Accessing a 2D Array:
Example-1
Program
1 int data[3][3] = {
2 {1,2,3}, //row 0 with 3 elements
3 {4,5,6}, //row 1 with 3 elements
4 {7,8,9} //row 2 with 3 elements
5 }; Column-0 Column-1 Column-2
6 printf("%d",data[0][0]); //1
7 printf("%d",data[0][1]); //2 Row-0 1 2 3
8 printf("%d\n",data[0][2]); //3
9 Row-1 4 5 6
10 printf("%d",data[1][0]); //4
11 printf("%d",data[1][1]); //5 Row-2 7 8 9
12 printf("%d\n",data[1][2]); //6
13
14 printf("%d",data[2][0]);//7
15 printf("%d",data[2][1]); //8
16 printf("%d",data[2][2]); //9
1 // data[3][3]
2 can be initialized like this also
int data[3][3]={{1,2,3},{4,5,6},{7,8,9}};
Initialing and Accessing a 2D Array:
Example-2
Program
1 int data[2][4] = {
2 {1,2,3,4}, //row 0 with 4 elements
3 {5,6,7,8}, //row 1 with 4 elements
4 };
5 printf("%d",data[0][0]); //1
6 printf("%d",data[0][1]); //2 Col-0 Col-1 Col-2 Col-3
7 printf("%d",data[0][2]); //3
8 printf("%d\n",data[0][3]); //4 Row-0 1 2 3 4
9
10 printf("%d",data[1][0]); //5 Row-1 5 6 7 8
11 printf("%d",data[1][1]); //6
12 printf("%d",data[1][2]); //7
13 printf("%d",data[1][3]); //8

1 // data[2][4]
2 can be initialized like this also
int data[2][4]={{1,2,3,4},{5,6,7,8}};
Read(Scan) 2D Array Elements
Program
1 void main(){
2 int data[3][3],i,j;
3 for(i=0;i<3;i++)
4 {
5 for(j=0;j<3;j++)
Outpu
6 { t
7 printf("Enter array element="); Enter array element=1
8 scanf("%d",&data[i][j]); Enter array element=2
9 } Enter array element=3
10 } Enter array element=4
11 for(i=0;i<3;i++) Enter array element=5
12 { Enter array element=6
13 for(j=0;j<3;j++) Enter array element=7
14 { Enter array element=8
15 printf("%d",data[i][j]); Enter array element=9
16 } 123
17 printf("\n"); 456
18 } 789
19 }
Develop a program to count number of positive, negative
and zero elements from 3 X 3 matrix
Program
1 void main(){ Outpu
2 int data[3][3],i,j,pos=0,neg=0,zero=0; t
3 for(i=0;i<3;i++) Enter array element=9
4 { Enter array element=5
5 for(j=0;j<3;j++) Enter array element=6
6 { Enter array element=-3
7 printf("Enter array element="); Enter array element=-7
8 scanf("%d",&data[i][j]); Enter array element=0
9 if(data[i][j]>0) Enter array element=11
10 pos=pos+1; Enter array element=13
11 else if(data[i][j]<0) Enter array element=8
12 neg=neg+1; positive=6,negative=2,zero
13 else =1
14 zero=zero+1;
15 }
16 }
17 printf("positive=%d,negative=%d,zero=
18 %d",pos,neg,zero);
}
String
(Character Array)
Definition: String
• A String is a one-dimensional array of characters terminated
by a null('\0').
[0] [1] [2] … [9]
char name[10]
;

• Each character in the array occupies one byte of memory, and


the last character must always be null('\0').
• The termination character ('\0') is important in a string to
identify where the
[0] string
[1] [2] ends.
[3] [4] [5] [6] [7] [8] [9]
name[10 D A R S H A N \0
]
Declaring & Initializing String
Declaratio
n
char name[10]
;
Initialization method
1:
char name[10]={'D','A','R','S','H','A','N','
\0'};
Initialization method
2:
char name[10]="DARSHAN";
//'\
0' will be automatically inserted at the end in this type of declarati
on.
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
name[10 D A R S H A N \0
]
Read String: scanf()
Program Outpu
1 void main() t
2 { Enter name: Darshan
3 char name[10]; Name=Darshan
4 printf("Enter name:"); Outpu
5 scanf("%s",name); t
Enter name: CE Darshan
6 printf("Name=%s",name);
Name=CE
7 }

• There is no need to use address of (&) operator in scanf to


store a string.
• As string name is an array of characters and the name of the
array, i.e., name indicates the base address of the string
(character array).
• scanf() terminates its input on the first whitespace(space,
tab, newline etc.) encountered.
Read String: gets()
Program
Outpu
1 #include<stdio.h> t
2 void main() Enter name:Darshan
3 { Institute
4 char name[10]; Name=Darshan Institute
5 printf("Enter name:");
6 gets(name); //
7 read string including white spaces
8 printf("Name=%s",name);
}
• gets(): Reads characters from the standard input and stores them as a string.
• puts(): Prints characters from the standard.
• scanf(): Reads input until it encounters whitespace, newline or End Of
File(EOF) whereas gets() reads input until it encounters newline or End Of
File(EOF).
• gets(): Does not stop reading input when it encounters whitespace instead it
takes whitespace as a string.
String Handling Functions : strlen()
• C has several inbuilt functions to operate on string. These
functions are known as string handling functions.
• strlen(s1): returns length of a string in integer
Program
Outpu
1 #include <stdio.h> t
2 #include <string.h> //header file for string functions Enter string: CE
3 void main() Darshan
4 { 10
5 char s1[10];
6 printf("Enter string:");
7 gets(s1);
8 printf("%d",strlen(s1)); // returns length of s1 in in
9 teger
}
String Handling Functions: strcmp()
• strcmp(s1,s2): Returns 0 if s1 and s2 are the same.
• Returns less than 0 if s1<s2.
• Returns greater than 0 if s1>s2.
Program
Outpu
1 void main() t
2 { Enter string-
3 char s1[10],s2[10]; 1:Computer
4 printf("Enter string-1:"); Enter string-
5 gets(s1); 2:Computer
Outpu
6 printf("Enter string-2:"); Strings
t are same
7 gets(s2); Enter string-
8 if(strcmp(s1,s2)==0) 1:Computer
9 printf("Strings are same"); Enter string-
10 else 2:Computer
11 printf("Strings are not same"); Strings are same
12 }
String Handling Functions
For examples consider: char s1[]="Their",s2[]="There";
Syntax Description
strcpy(s1,s2) Copies 2nd string to 1st string.
strcpy(s1,s2) copies the string s2 in to string s1 so s1 is now
“There”. s2 remains unchanged.

strcat(s1,s2) Appends 2nd string at the end of 1st string.


strcat(s1,s2); a copy of string s2 is appended at the end of
string s1. Now s1 becomes “TheirThere”

strchr(s1,c) Returns a pointer to the first occurrence of a given character in the


string s1. printf("%s",strchr(s1,'i'));
Output : ir

strstr(s1,s2) Returns a pointer to the first occurrence of a given string s2 in


string s1. printf("%s",strstr(s1,"he"));
Output : heir
String Handling Functions (Cont…)
For examples consider: char s1[]="Their",s2[]="There";
Syntax Description
strrev(s1) Reverses given string.
strrev(s1); makes string s1 to “riehT”
strlwr(s1) Converts string s1 to lower case.
printf("%s",strlwr(s1));
Output : their
strupr(s1) Converts string s1 to upper case.
printf("%s",strupr(s1));
Output : THEIR
strncpy(s1,s2,n Copies first n character of string s2 to string s1
) s1=""; s2="There";
strncpy(s1,s2,2);
printf("%s",s1);
Output : Th
strncat(s1,s2,n Appends first n character of string s2 at the end of string s1.
) strncat(s1,s2,2);
printf("%s", s1); Output :
TheirTh
String Handling Functions (Cont…)
For examples consider: char s1[]="Their",s2[]="There";
Syntax Description
strncmp(s1,s2,n Compares first n character of string s1 and s2 and returns similar
) result as strcmp() function.
printf("%d",strcmp(s1,s2,3));
Output
Returns: the
0 last occurrence of a given character in a string s1.
strrchr(s1,c)
printf("%s",strrchr(s2,'e'));
Output : ere
Functions
What is Function?
• A function is a group of statements that perform a specific task.
• It divides a large program into smaller parts.
• A function is something like hiring a person to do a specific job for you.
• Every C program can be thought of as a collection of these functions.
• Program execution in C language starts from the main function.

Syntax
void main()
{
// body part
}
• Why function ?
• Avoids rewriting the same code over and over.
• Using functions it becomes easier to write programs and keep track of what they
doing.
Types of Function
Function

User Defined Function


Library Function
(UDF)

Predefined or inbuilt Created by User


Declarations inside header Programmer need to
files declare it
Eg. printf() – stdio.h Eg. findSimpleInterest()
pow() – math.h areaOfCircle()
strcmp() – string.h
Program Structure for Function
• When we use a user-defined function program structure is divided into three parts.
Function
Structure
void func1();
Function
Prototype

void main()
{
....
func1(); Function call
}

void func1()
{
....
Function
//function body definition
....
}
Function Prototype
 A function Prototype also know as function declaration.
 A function declaration tells the compiler about a function name and how
to call the function.
 It defines the function before it is being used or called.
 A function prototype needs to be written at the beginning of the
program.

Syntax Example
return-type function-name (arg-1, arg 2, void addition(int, int);
…);
Function Definition
 A function definition defines the functions header and body.
 A function header part should be identical to the function prototype.
 Function return type
 Function name
 List of parameters
 A function body part defines function logic.
 Function statements

Syntax Example
return-type function-name (arg-1, arg 2, void addition(int x, int y)
…) {
{ printf("Addition is=%d“,
//... Function body (x+y)); }
}
WAP to add two number using add(int, int) Function
Program Outpu
t
1 #include <stdio.h> Addition is = 11
2 void add(int, int); // function declaration
3
4 void main()
5 {
6 int a = 5, b = 6;
7 add(a, b); // function call
8 }
9
10 void add(int x, int y) // function definition
11 {
12 printf("Addition is = %d", x + y);
13 }
Actual parameters and Formal parameters
• Values that are passed to the called function from the main
function are known as Actual parameters.
• The variables declared in the function prototype or definition
are known as Formal parameters.
• When a method is called, the formal parameter is temporarily
"bound" to the actual parameter.
Actual paramete Formal
rs parameters
void main() void add(int x, int y) // x and y are
{ formal parameters.
int a = 5, b = 6; {
add(a, b); // a and b are the printf("Addition is = %d", x + y);
actual parameters in this
call. }
}
Return Statement
• If function is returning a value to calling function, it needs to
use the keyword return.
• The called function can only return one value per call.
Syntax
return;
Or

return (expression);
WAP to find maximum number from two number
Program Outpu
t
1 #include <stdio.h> Max value is : 200
2 int max(int a, int b);
3 void main()
4 {
5 int a = 100;
6 int b = 200;
7 int maxvalue;
8 maxvalue = max(a, b);
9 printf("Max value is : %d\n",
10 maxvalue);
11 }
12 int max(int a, int b)
13 {
14 if (a > b)
15 return a; // return a
16 else
17 return b; // return b
18 }
WAP to calculate the Power of a Number
Program Outpu
t
1 #include <stdio.h> Enter any number : 5
2 int power(int, int); Enter power of number : 3
3 void main()
4 {
5 int num, pow, res;
5's power 3 = 125
6 printf("Enter any number : ");
7 scanf("%d", &num);
8 printf("Enter power of number : ");
9 scanf("%d", &pow);
10 res = power(num, pow);
11 printf("%d's power %d = %d", num, pow, res);
12 }
13 int power(int n, int p)
14 { int r = 1;
15 while (p >= 1)
16 {
17 r = r * n;
18 p--;
19 }
20 return r;}
WAP to find Factorial of a Number
Program Outpu
t
1 #include <stdio.h> Enter the number :
2 int fact(int); 5
3 int main() factorial = 120
4 {
5 int n, f;
6 printf("Enter the number :\n");
7 scanf("%d", &n);
8 f = fact(n);
9 printf("factorial = %d", f);
10 }
11 int fact(int n)
12 {
13 int i, fact = 1;
14 for (i = 1; i <= n; i++)
15 fact = fact * i;
16 return fact;
17 }
WAP to check Number is Prime or not
Program
Program
contd.
1 #include <stdio.h> 14 int checkPrime(int n1)
2 int checkPrime(int); 15 {
3 void main() 16 int i = 2;
4 { while (i <= n1 / 2)
17
5 int n1, prime; {
6 printf("Enter the number :");
18 if (n1 % i == 0)
7 scanf("%d", &n1); 19 return 0;
8 prime = checkPrime(n1); 20 else
9 if (prime == 1) 21 i++;
10 printf("The number %d is a prime 22 }
number.\n", n1); 23 return 1;
11 else 24 }
12 printf("The number %d is not a
prime number.\n", n1);
13 }

Outpu
t
Enter the number :7
The number 7 is a prime number.
Category of Function
(1) Function with no argument and but no return value
No
void main() Input void fun1()
{ {
..... .....
No return .....
fun1();
value .....
.....
} }

(2) Function with no argument and returns value


No
void main() Input int fun1(void)
{ {
..... .....
a = fun1() Function .....
..... result return b;
} }
Category of Function cont.
(3) Function with argument and but no return value
Value of
void main() Argument void fun1(int
{ f)
..... {
fun1(a); No Return .....
..... value .....
} .....
}
(4) Function with argument and returns value
Value of
void main() Argument int fun1(int
{ f)
..... {
b = Function .....
fun1(a); Result .....
..... return e;
} }
Key points about function
• Function is a block of code, which has some name for identification
• Any C program can have any number of functions. At least one function should be there
in the program
• Function names must be unique. No two functions can share same names
• No keyword is a functions, so do not misinterpreted by the syntax of if, while, switch,
return(), sizeof(), etc, they are not functions
• Function cannot be defined inside body of another function
• Function call, function definition and function declaration are three different
terminologies with different meanings, so never used them interchangeably
• You can call a function from a function any number of times, but can define only once.
• Function is a way to achieve modularization.
• Splitting up of a bigger task into several smaller sub tasks is known as modularization
• Functions are of two types, Predefined and user defined
• printf, scanf are examples of predefined function
• main is an example of user defined function
Key points about function
• Functions can be defined in any sequence in the program, without affecting the flow of the
program
• Function execution depends on the call of a function. Function can never execute in the life of
program if it is not called from anywhere in the program
• Function declaration is also known as function prototype
• Function declaration for the predefined functions resides in the header files
• Function definitions for all predefined functions resides in the library file
• Programmer has to provide declaration of the user defined function
• Execution of program begins with main function
• Operating system calls main
• Any function can call main
• Any function can call itself, known as recursion
• Benefits of functions
• Easy to read
• Easy to modify
• Easy to debug
• Avoids rewriting of code
• Better memory utilization
Sorting & Searching
• Searching
• Linear/Sequential Search
• Binary Search
• Sorting
• Bubble sort
Linear/Sequential Search
• In computer science, linear search or sequential search is a
method for finding a particular value in a list that consists of
checking every one of its elements, one at a time and in
sequence, until the desired one is found.
• Linear search is the simplest search algorithm.
Sequential Search – Algorithm & Example
# Input: Array A, integer key Search for 1 in given array 2 9 3 1 8
# Output: first index of key
in A
# or -1 if not found Comparing value of ith index with element to be search
one by one until we get searched element or end of the
Algorithm: Linear_Search array
Step 1: Step 1:
for i = 0 to last index of A: i=0 i=2
if A[i] equals key:
2 9 3 1 8 2 9 3 1 8
return i

return -1 i i

Step 1: Step 1:
i=1 i=3
2 9 3 1 8 2 9 3 1 8

i i
Element found at ith index, i=3
Binary Search
• If we have an array that is sorted, we can use a much more
efficient algorithm called a Binary Search.
• In binary search each time we divide array into two equal
half and compare middle element with search element.
• Searching Logic
• If middle element is equal to search element then we got that
element and return that index
• if middle element is less than search element we look right part
of array
• if middle element is greater than search element we look left
part of array.
Binary Search - Algorithm
# Input: Sorted Array A, integer key
# Output: first index of key in A,
# or -1 if not found
Algorithm: Binary_Search (A, left, right)
left = 0, right = n-1
while left < right
middle = index halfway between left, right
if A[middle] matches key
return middle
else if key less than A[middle]
right = middle -1
else
left = middle + 1
return -1
Binary Search - Algorithm
Search for 6 in given array
-1 5 6 18 19 25 46 78 10 11
Index 0 1 2 3 4 5 6 7 2
8 4
9

left right
Key=6, No of Elements = 10, so left = 0, right=9
Step 1: middle index = (left + right) /2 = (0+9)/2 = 4
middle element value = a[4] = 19
Key=6 is less than middle element = 19, so right = middle – 1 = 4 – 1 = 3, left = 0

-1 5 6 18 19 25 46 78 10 11
Index 0 1 2 3 4 5 6 7 2
8 4
9

left right
Binary Search - Algorithm
Step 2: middle index = (left + right) /2 = (0+3)/2 = 1
middle element value = a[1] = 5
Key=6 is greater than middle element = 5, so left = middle + 1 =1 + 1 = 2, right = 3

-1 5 6 18 19 25 46 78 10 11
Index 0 1 2 3 4 5 6 7 2
8 4
9

left right
Step 3: middle index = (left + right) /2 = (2+3)/2 = 2
middle element value = a[2] = 6
Key=6 is equals to middle element = 6, so element found

-1 5 6 18 19 25 46 78 10 11
Index 0 1 2 3 4 5 6 7 2
8 4
9

Element Found
Bubble Sort
• Two records are interchanged immediately upon discovering
that they are out of order
• During the first pass, R1 and R2 are compared and
interchanged in case of our of order, this process is
repeated for records R2 and R3, and so on.
• This method will cause records with a small key to move
“bubble up”,
• After the first pass, the record with the largest key will be in
the nth position.
• On each successive pass, the records with the next largest key
will be placed in positions n-1, n-2 ….., and 2, respectively.
Bubble Sort
Unsorted Array
45 34 56 23 12

Pass 1 : Pass 2 : Pass 3 : Pass 4 :


3
4 3 3 3 3 3 3 2
3 2 1
2

swap
swap
swap

5
4
3 4 4 4 4 4
2 4
2 4
3
2 3
1 3
2
1

swap
swap
4
5 5 5
2 swap 5
2 5
2 5
3
2
4 3
4
1 3
4
1 4
2
1
3 2
3

swap
6
2 6
2 6
3
2
5 3
5
1 3
1 3
5
1 5
2
1
4 2
4 2
4 4

swap
3
1 3
1 3
6
1 6
2
1
5 2
5 2
5 2
5 5 5 5
2 2 2 2
6 6 6 6 6 6 6
Procedure: BUBBLE_SORT (K, N)
1. [Initialize]
LAST  N
2. [Loop on pass index]
Repeat thru step 5 for PASS = 1, 2, 3, …. , N-1
3. [Initialize exchange counter for this pass]
EXCHS  0
4. [Perform pairwise comparisons on unsorted elements]
Repeat for I = 1, 2, ……….., LAST – 1
IF K[I] > K [I+1]
Then K[I]  K[I+1]
EXCHS  EXCHS + 1
5. [Any exchange made in this pass?]
IF EXCHS = 0
Then Return (Vector is sorted, early return)
ELSE LAST  LAST - 1
6. [Finished]
Return
BUBBLE_SORT(K,N)
• Given a vector K of N elements
• This procedure rearrange the vector in ascending order
using Bubble Sort
• The variable PASS & LAST denotes the pass index and
position of the first element in the vector
• The variable EXCHS is used to count number of exchanges
made on any pass
• The variable I is used to index elements

Thank you

You might also like