0% found this document useful (0 votes)
19 views16 pages

Lect 1 - 2024

FoDSA lecture slides BITS Pilani, Hyderabad Campus By Sameera Muhamed Salam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views16 pages

Lect 1 - 2024

FoDSA lecture slides BITS Pilani, Hyderabad Campus By Sameera Muhamed Salam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

BITS F232 Foundations of Data Structures and

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.

An algorithm is a sequence of computational steps that transform the


input into the output
Algorithm

Algorithm: step-by-step procedure for performing some task in a finite
amount of time
set of
instructions
to
convert
INPUT input OUTPUT
to
expected
output
Kind of Problems Solved by Algorithms

Human Genome Project to identify genes in human DNA

Pattern matching

Efficient way to save and access large amount of data

E commerce Sites

Searching, Sorting, Secure payment

Manufacturing and commercial settings

Optimization problems

Allocation of scarce resources

An airline may wish to assign crews to flights in the least expensive way possible,
making sure that each flight is covered and that government regulations regarding crew
scheduling are met.
Kind of Problems Solved by Algorithms

Given ‘n’ Matrices, finding matrix multiplication

Given ‘n’ points in the plane, finding a convex hull of these points

Finding Shortest route
Data Structures

Variables and Data Types

Data Structures
Data Structures

A systematic way of organizing and accessing data

No single data structure works well for all purposes

So it is important to know their strengths and limitations

What Is Pseudo-Code?

Pseudo-code is a mixture of natural language and high-level
programming constructs that describe the main ideas behind a
generic implementation of a data structure or algorithm.

A pseudo-code mixes natural language with standard program-
ming language constructs.

We can use

Expressions: We use standard mathematical symbols to express
numeric and Boolean expressions

← instead of =

= instead of ==

What Is Pseudo-Code?


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

Mathematical Abstract Data


Model Data Type Structures

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.

You might also like