Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Use the bubble sort to sort d, f, k, m, a, b, , showing the lists obtained at each step.

Short Answer

Expert verified

Bubble sort differentiates the two adjacent elements and re-short the given list in increasing order when adjacent elements are in decreasing order.

The order of elements: a,b,d,f,k,m

Step by step solution

01

Compare the elements d, f, k, m, a, b,  and write them alphabetically in increasing order.

When we compare d and f there is no need to interchange the elements as d come in the alphabet before f i.e., d, f, k, m, a, b .

When we compare f and k there is no need to interchange the elements as f come in the alphabet before k i.e., d, f, k, m, a, b .

When we compare k and m there is no need to interchange the elements as k come in the alphabet before m i.e., d, f, k, m, a, b .

When we compare m and a Here we require to interchange the elements as m come in the alphabet after a i.e., d, f, k, a, m, b .

When we compare m and b Here we require to interchange the elements as m come in the alphabet after b i.e., d, f, k, a, b, m .

02

Compare the elements and write them alphabetically in increasing order.

When we compare d and f there is no need to interchange the elements as d come in the alphabet before f i.e., d, f, k, a, b, m .

When we compare f and k there is no need to interchange the elements as f come in the alphabet before k i.e., d, f, k, a, b, m .

When we compare k and a Here we require to interchange the elements as k come in the alphabet after a i.e., d, f, a, k, b, m .

When we compare k and b Here we require to interchange the elements as k come in the alphabet after b i.e., d, f, a, b, k, m .

Here, we need not to compare the elements in blue colour as they are arranged in increasing order.

03

Compare the elements d, f, a, b, k, m and write them alphabetically in increasing order.

When we compare d and f there is no need to interchange the elements as d come in the alphabet before f i.e., d, f, a, b, k, m .

When we compare f and a Here we require to interchange the elements as f come in the alphabet after a i.e., d, a, f, b, k, m .

When we compare f and b Here we require to interchange the elements as come in the alphabet after i.e., d, a, b, f, k, m .

Here, we need not to compare the elements in blue colour as they are arranged in increasing order.

04

Compare the elements d, a, b, f, k, m and write them alphabetically in increasing order.

When we compare d and a Here we require to interchange the elements as d come in the alphabet after a i.e., a, d, b, f, k, m .

When we compare d and b Here we require to interchange the elements as d come in the alphabet after b i.e., a, b, d, f, k, m .

Here, we need not to compare the elements in blue colour as they are arranged in increasing order

05

Compare the elements a, b, d, f, k, m and write them alphabetically in increasing order.

When we compare a and b there is no need to interchange the elements as a come in the alphabet before b i.e., a,b,d,f,k,m .

Since all elements are in correct alphabetical order. So, bubble sort algorithm will not continue. And the order of elements is:

a, b, d, f, k, m

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free