Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

concepts of data structure

Rating
-
Sold
-
Pages
27
Uploaded on
07-03-2024
Written in
2023/2024

Data structures are essential components that help organize and store data efficiently in computer memory. They provide a way to manage and manipulate data effectively, enabling faster access, insertion, and deletion operations. Common data structures include arrays, linked lists, stacks, queues, trees, and graphs , each serving specific purposes based on the requirements of the problem at hand. Understanding data structures is fundamental for designing efficient algorithms and optimizing software performance.

Show more Read less
Institution
Course

Content preview

UNIT IV

SORTING AND SEARCHING ALGORITHMS
Bubble sort, insertion sort, radix sort, quick sort, merge sort, shell sort etc Linear Search,
binary search

BUBBLE SORT
Bubble sort is a basic algorithm for arranging a string of numbers or
other elements in the correct order.
The metihod works by examining each set of adjacent elements in
the string, from left to right, switching their positions if they are out
of order.
As the algorithm progresses, smaller value items “bubble” to the top
of the list, this is the reason for naming the algorithm as bubble sort.

10 9 11 6 15 2



In the above example, let us take the first element for sorting the
entire list.
The very first element is the bubble element.
Take the first element in the series and is compared with the next
element. If the first element is smaller than the next element, swap
the values.
In case, the next element is not smaller then there is no change in
the list, the algorithm proceeds to the next value to compare.

9 10 11 6 15 2



Now, the bubble element is still 10.
Now, the position of 10 is changed from 1 to 2 and the bubble is
compared with the next element 11.
As 11, is greater than 10, the position of 10 is not changed as it is
lower, the bubble is shifted to 11.

,11 becomes the bubble.

9 10 11 6 15 2



Now the bubble is compared with 6, as 6 is lower, the values are
swapped.

9 10 6 11 15 2



Now the bubble is compared with the next value 15, as 11 is lower
there is no change in the list, but bubble is shifted to the next
number that is 15.

9 10 6 11 15 2



Now the bubble is compared with the next element, as the value 2
is lower than the bubble, the values are swapped.

9 10 6 11 2 15



All the above processes are taken as Pass 1.
After Pass1, however bigger the list is the maximum value will
reach its right position.
In the next pass, the last value (15) that has reached its right
position is not compared.
If the list is of ‘n’ size, n-1 value will be considered for the next pass.

9 10 6 11 2 15

Now, in the second pass, start from the beginning of the list.
9 becomes the bubble and is compared to the next value 10.
As the value is smaller than 10, no change happens and the bubble
is shifted to 10.

, 9 10 6 11 2 15



The bubble is compared with the next element 6, as the value is
lower, the values are swapped.

9 6 10 11 2 15



Still, the bubble is 10 and is compared with the next value.
The value 11 is greater than 10, therefore, no change happens in
the list and the bubble is shifter to 11.

9 6 10 11 2 15



Now, the bubble is compared to the next value 2.
As 2 is lower than 11, the values are swapped.

9 6 10 2 11 15



This is the end of Pass 2. By its ends, the second largest value in
the list, 11 has come to its actual position.
In Pass 3, n-2 elements will be considered. That is out of 6, only 4
elements will be considered.

9 6 10 2 11 15



The algorithm starts with the first element, 9 which is the bubble.
The bubble is compared with the next element 6, as the value is
lower than the bubble, they are swapped and nine continues to be
the bubble.

6 9 10 2 11 15

Written for

Course

Document information

Uploaded on
March 7, 2024
Number of pages
27
Written in
2023/2024
Type
Class notes
Professor(s)
Sudha
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
manoj2

Get to know the seller

Seller avatar
manoj2 HICET
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions