Notes PPTS
Notes PPTS
SunBeam Institute of
Information & Technology,
Hinjwadi, Pune & Karad.
SACHIN PAWAR
Sunbeam Infotech www.sunbeaminfo.com
Data Structures
Q. What is a Program?
- A program is a set of instructions written in any programming language (like
C, C++, Java, Python, Assembly etc...) given to the machine to do specific task.
- An algorithm is a template whereas a program is an implementation
of an algorithm.
Q. What is an Algorithm?
- An algorithm is a finite set of instructions written in human understandable
language (like english), if followed, acomplishesh a given task.
- An algorithm is a finite set of instructions written in human understandable
language (like english) with some programming constraints, if followed,
acomplishesh a given task, such an algorithm also called as pseudocode.
1. Selection Sort:
- In this algorithm, in first iteration, first position gets selected and
element which is at selected position gets compared with all its next
position elements, if selected position element found greater than
any other position element then swapping takes place and in first
iteration smallest element gets setteled at first position.
- In the second iteration, second position gets selected and element
which is at selected position gets compared with all its next position
elements, if selected position element found greater than any other
position element then swapping takes place and in second iteration
second smallest element gets setteled at second position, and so on
in maximum (n-1) no. of iterations all array elements gets arranged
in a sorted manner.
2. Bubble Sort:
- In this algorithm, in every iteration elements which are two consecutive
positions gets compared, if they are already in order then no need of
swapping between them, but if they are not in order i.e. if prev position
element is greater than its next position element then swapping takes
place, and by this logic in first iteration largest element gets setteled at
last position, in second iteration second largest element gets setteled at
second last position and so on, in max (n-1) no. of iterations all
elements gets arranged in a sorted manner.