Lect 1 - 2024
Lect 1 - 2024
Algorithms
INTRODUCTION & MOTIVATION
<date/time> <footer> 1
Algorithm
Algorithm: step-by-step procedure for performing some task in a finite
amount of time
Takes a value or set of values, as input.
Produces some value, or set of values, as output.
We can use
Method declarations: Algorithm name(paraml , param2 ,...)
●
declares a new method "name" and its parameters.
Method calls: name(args)
Method returns: return value
– This operation returns the value specified to the method
that calls this one.
Decision structures: if condition,then true-actions [else false-actions].
Pseudocode
While-loops: while condition, do actions.
Repeat-loops: repeat actions until condition.
For-loops for variable-increment-definition do actions
Array indexing: A[i] represents the ith cell in the array A
n-celled array A are indexed from A[0] toA[n-1]
A[i,j] represents jth cell in ith row
Abstract Data Type
An abstract data type (ADT), is a logical description of how we
view the data and the operations that are allowed without knowing
how they will be implemented.
The Problem Solving Process
Informal Pseudo
C
language Language
Program
Program
Example
Ticket reservation
C Program (Recap)
Arrays
Functions.
Exercise:
1) Write a c program to check whether the sum of elements in an array is
odd or not. You should define a function Sum() with the following
parameters
array
number of elements in the array
to find the sum of elements in the array.
Exercise
2) Write a program to find total marks of each student in a class of
strength n. Assume that each student is registered for 5 subjects
(all students registered for same subjects). Output of the program
should be name of the student and total marks. Find Average
marks obtained in each subject also.