Sorting and Searching Practice Worksheet Generator

Bubble, insertion and selection sort passes, and binary search steps. No AI, no credits.

Grades 6 – 12No account needed

The array after each pass of bubble, insertion and selection sort, binary search steps, and counts of comparisons and swaps, produced by running the algorithms in code. No AI, so it never uses a generation credit.

What students practice

  • Computer Science
  • Sorting
  • Searching
  • Algorithms

Live sample sheet

No account needed to view and print.
Name: ____________________Date: ____________

Sorting and Searching Practice

1. Show the array after each pass of bubble sort: [60, 45, 85, 67, 18, 53]
Initial604585671853Pass 1456067185385Pass 2456018536785Pass 3451853606785Pass 4184553606785Pass 5184553606785Comparisons: 15, Swaps: 9
2. Show the array after each pass of insertion sort: [28, 62, 86, 47, 25, 88]
Initial286286472588After i=1286286472588After i=2286286472588After i=3284762862588After i=4252847628688After i=5252847628688Comparisons: 10, Swaps: 0
3. Show the array after each pass of selection sort: [74, 31, 20, 50, 68, 61]
Initial743120506861Pass 1203174506861Pass 2203174506861Pass 3203150746861Pass 4203150616874Pass 5203150616874Comparisons: 15, Swaps: 3
4. Trace a binary search for 4 in the sorted array: [1, 4, 6, 7, 27, 47, 59, 83]
Initial (sorted)146727475983low=0, high=7, mid=3 → 7 > 4, go left146727475983low=0, high=2, mid=1 → found at index 1146727475983
5. Show the array after each pass of bubble sort: [78, 53, 3, 18, 84, 49]
Initial78533188449Pass 153318784984Pass 231853497884Pass 331849537884Pass 431849537884Comparisons: 14, Swaps: 8
6. Show the array after each pass of insertion sort: [81, 32, 45, 4, 6, 56]
Initial8132454656After i=13281454656After i=23245814656After i=34324581656After i=44632458156After i=54632455681Comparisons: 12, Swaps: 0
7. Show the array after each pass of selection sort: [60, 25, 64, 21, 31, 74]
Initial602564213174Pass 1212564603174Pass 2212564603174Pass 3212531606474Pass 4212531606474Pass 5212531606474Comparisons: 15, Swaps: 2
8. Trace a binary search for 66 in the sorted array: [8, 21, 29, 30, 51, 66, 68, 86]
Initial (sorted)821293051666886low=0, high=7, mid=3 → 30 < 66, go right821293051666886low=4, high=7, mid=5 → found at index 5821293051666886
9. Show the array after each pass of bubble sort: [92, 9, 94, 43, 14, 11]
Initial92994431411Pass 199243141194Pass 294314119294Pass 391411439294Pass 491114439294Pass 591114439294Comparisons: 15, Swaps: 10
10. Show the array after each pass of insertion sort: [2, 36, 48, 61, 90, 8]
Initial2364861908After i=12364861908After i=22364861908After i=32364861908After i=42364861908After i=52836486190Comparisons: 9, Swaps: 0
Made with TeachSpark

Answer Key — Sorting and Searching Practice

1. Show the array after each pass of bubble sort: [60, 45, 85, 67, 18, 53]
Initial604585671853Pass 1456067185385Pass 2456018536785Pass 3451853606785Pass 4184553606785Pass 5184553606785Comparisons: 15, Swaps: 9
Solution:
Initial: [60, 45, 85, 67, 18, 53]
Pass 1: [45, 60, 67, 18, 53, 85]
Pass 2: [45, 60, 18, 53, 67, 85]
Pass 3: [45, 18, 53, 60, 67, 85]
Pass 4: [18, 45, 53, 60, 67, 85]
Pass 5: [18, 45, 53, 60, 67, 85]
Answer: [18, 45, 53, 60, 67, 85]
2. Show the array after each pass of insertion sort: [28, 62, 86, 47, 25, 88]
Initial286286472588After i=1286286472588After i=2286286472588After i=3284762862588After i=4252847628688After i=5252847628688Comparisons: 10, Swaps: 0
Solution:
Initial: [28, 62, 86, 47, 25, 88]
After i=1: [28, 62, 86, 47, 25, 88]
After i=2: [28, 62, 86, 47, 25, 88]
After i=3: [28, 47, 62, 86, 25, 88]
After i=4: [25, 28, 47, 62, 86, 88]
After i=5: [25, 28, 47, 62, 86, 88]
Answer: [25, 28, 47, 62, 86, 88]
3. Show the array after each pass of selection sort: [74, 31, 20, 50, 68, 61]
Initial743120506861Pass 1203174506861Pass 2203174506861Pass 3203150746861Pass 4203150616874Pass 5203150616874Comparisons: 15, Swaps: 3
Solution:
Initial: [74, 31, 20, 50, 68, 61]
Pass 1: [20, 31, 74, 50, 68, 61]
Pass 2: [20, 31, 74, 50, 68, 61]
Pass 3: [20, 31, 50, 74, 68, 61]
Pass 4: [20, 31, 50, 61, 68, 74]
Pass 5: [20, 31, 50, 61, 68, 74]
Answer: [20, 31, 50, 61, 68, 74]
4. Trace a binary search for 4 in the sorted array: [1, 4, 6, 7, 27, 47, 59, 83]
Initial (sorted)146727475983low=0, high=7, mid=3 → 7 > 4, go left146727475983low=0, high=2, mid=1 → found at index 1146727475983
Solution:
Initial (sorted)
low=0, high=7, mid=3 → 7 > 4, go left
low=0, high=2, mid=1 → found at index 1
Answer: Found at index 1
5. Show the array after each pass of bubble sort: [78, 53, 3, 18, 84, 49]
Initial78533188449Pass 153318784984Pass 231853497884Pass 331849537884Pass 431849537884Comparisons: 14, Swaps: 8
Solution:
Initial: [78, 53, 3, 18, 84, 49]
Pass 1: [53, 3, 18, 78, 49, 84]
Pass 2: [3, 18, 53, 49, 78, 84]
Pass 3: [3, 18, 49, 53, 78, 84]
Pass 4: [3, 18, 49, 53, 78, 84]
Answer: [3, 18, 49, 53, 78, 84]
6. Show the array after each pass of insertion sort: [81, 32, 45, 4, 6, 56]
Initial8132454656After i=13281454656After i=23245814656After i=34324581656After i=44632458156After i=54632455681Comparisons: 12, Swaps: 0
Solution:
Initial: [81, 32, 45, 4, 6, 56]
After i=1: [32, 81, 45, 4, 6, 56]
After i=2: [32, 45, 81, 4, 6, 56]
After i=3: [4, 32, 45, 81, 6, 56]
After i=4: [4, 6, 32, 45, 81, 56]
After i=5: [4, 6, 32, 45, 56, 81]
Answer: [4, 6, 32, 45, 56, 81]
7. Show the array after each pass of selection sort: [60, 25, 64, 21, 31, 74]
Initial602564213174Pass 1212564603174Pass 2212564603174Pass 3212531606474Pass 4212531606474Pass 5212531606474Comparisons: 15, Swaps: 2
Solution:
Initial: [60, 25, 64, 21, 31, 74]
Pass 1: [21, 25, 64, 60, 31, 74]
Pass 2: [21, 25, 64, 60, 31, 74]
Pass 3: [21, 25, 31, 60, 64, 74]
Pass 4: [21, 25, 31, 60, 64, 74]
Pass 5: [21, 25, 31, 60, 64, 74]
Answer: [21, 25, 31, 60, 64, 74]
8. Trace a binary search for 66 in the sorted array: [8, 21, 29, 30, 51, 66, 68, 86]
Initial (sorted)821293051666886low=0, high=7, mid=3 → 30 < 66, go right821293051666886low=4, high=7, mid=5 → found at index 5821293051666886
Solution:
Initial (sorted)
low=0, high=7, mid=3 → 30 < 66, go right
low=4, high=7, mid=5 → found at index 5
Answer: Found at index 5
9. Show the array after each pass of bubble sort: [92, 9, 94, 43, 14, 11]
Initial92994431411Pass 199243141194Pass 294314119294Pass 391411439294Pass 491114439294Pass 591114439294Comparisons: 15, Swaps: 10
Solution:
Initial: [92, 9, 94, 43, 14, 11]
Pass 1: [9, 92, 43, 14, 11, 94]
Pass 2: [9, 43, 14, 11, 92, 94]
Pass 3: [9, 14, 11, 43, 92, 94]
Pass 4: [9, 11, 14, 43, 92, 94]
Pass 5: [9, 11, 14, 43, 92, 94]
Answer: [9, 11, 14, 43, 92, 94]
10. Show the array after each pass of insertion sort: [2, 36, 48, 61, 90, 8]
Initial2364861908After i=12364861908After i=22364861908After i=32364861908After i=42364861908After i=52836486190Comparisons: 9, Swaps: 0
Solution:
Initial: [2, 36, 48, 61, 90, 8]
After i=1: [2, 36, 48, 61, 90, 8]
After i=2: [2, 36, 48, 61, 90, 8]
After i=3: [2, 36, 48, 61, 90, 8]
After i=4: [2, 36, 48, 61, 90, 8]
After i=5: [2, 8, 36, 48, 61, 90]
Answer: [2, 8, 36, 48, 61, 90]
Answers computed by code. No AI, no credits.

Assumptions and Conventions

Assumptions:
  • Bubble sort: compare adjacent pairs, swap if out of order, repeat until sorted.
  • Insertion sort: take each element and insert it into the correct position in the sorted part.
  • Selection sort: find the minimum element and swap it to the front, repeat for the rest.
  • Binary search: requires a sorted array. Compare the middle element, then search left or right half.
Conventions:
  • Array indices start at 0.
  • Each pass shows the full array state after that pass is complete.
  • Comparisons and swaps are counted across the entire sort.
Made with TeachSpark

No account needed.

Frequently asked questions

Do students need an account to use the Sorting and Searching Practice?

No. Students never need an account. They open a shared link or join with a code.

Can I print the Sorting and Searching Practice without signing up?

Yes. This tool computes answers by code, so you can generate, preview and print worksheet without an account. A free account adds saving and student links.

How are the answers computed?

Every answer is computed by code and verified by a second independent method. No AI is used.

What grades is the Sorting and Searching Practice for?

This tool fits Grades 6 – 12.

✓ No account needed to generate, preview and print. A free account adds saving and student links.

Sign in

What can I do?

Without an account

  • Generate sheets
  • Preview pages
  • Print or save as PDF
  • Make versions A, B, C
  • Make differentiated levels
  • Print answer keys
  • See the trust panel and Show the calculation
  • Try the on-screen practice
  • Report a problem

With a free account

  • Save to My library
  • Browse My library
  • Share revocable student links
  • Make QR codes
  • Turn sharing on or off

Students never need an account — they open a shared link or join with a code.

Sample output, computed by code — change the options and Generate to make your own
Name: ____________________Date: ____________

Sorting and Searching Practice

1. Show the array after each pass of bubble sort: [97, 31, 48, 81, 51, 35]
Initial973148815135Pass 1314881513597Pass 2314851358197Pass 3314835518197Pass 4313548518197Pass 5313548518197Comparisons: 15, Swaps: 9
2. Show the array after each pass of insertion sort: [8, 76, 99, 82, 46, 94]
Initial87699824694After i=187699824694After i=287699824694After i=387682994694After i=484676829994After i=584676829499Comparisons: 10, Swaps: 0
3. Show the array after each pass of selection sort: [89, 96, 63, 25, 47, 31]
Initial899663254731Pass 1259663894731Pass 2253163894796Pass 3253147896396Pass 4253147638996Pass 5253147638996Comparisons: 15, Swaps: 4
4. Trace a binary search for 78 in the sorted array: [8, 21, 33, 45, 65, 77, 78, 86]
Initial (sorted)821334565777886low=0, high=7, mid=3 → 45 < 78, go right821334565777886low=4, high=7, mid=5 → 77 < 78, go right821334565777886low=6, high=7, mid=6 → found at index 6821334565777886
5. Show the array after each pass of bubble sort: [11, 28, 7, 63, 92, 35]
Initial11287639235Pass 111728633592Pass 271128356392Pass 371128356392Comparisons: 12, Swaps: 4
6. Show the array after each pass of insertion sort: [21, 1, 68, 81, 5, 60]
Initial2116881560After i=11216881560After i=21216881560After i=31216881560After i=41521688160After i=51521606881Comparisons: 10, Swaps: 0
7. Show the array after each pass of selection sort: [70, 93, 4, 56, 90, 59]
Initial70934569059Pass 149370569059Pass 245670939059Pass 345659939070Pass 445659709093Pass 545659709093Comparisons: 15, Swaps: 4
8. Trace a binary search for 72 in the sorted array: [10, 26, 27, 31, 46, 52, 72, 84]
Initial (sorted)1026273146527284low=0, high=7, mid=3 → 31 < 72, go right1026273146527284low=4, high=7, mid=5 → 52 < 72, go right1026273146527284low=6, high=7, mid=6 → found at index 61026273146527284
9. Show the array after each pass of bubble sort: [44, 89, 15, 2, 19, 75]
Initial44891521975Pass 144152197589Pass 215219447589Pass 321519447589Pass 421519447589Comparisons: 14, Swaps: 8
10. Show the array after each pass of insertion sort: [43, 73, 8, 37, 97, 77]
Initial43738379777After i=143738379777After i=284373379777After i=383743739777After i=483743739777After i=583743737797Comparisons: 9, Swaps: 0
Made with TeachSpark

Answer Key — Sorting and Searching Practice

1. Show the array after each pass of bubble sort: [97, 31, 48, 81, 51, 35]
Initial973148815135Pass 1314881513597Pass 2314851358197Pass 3314835518197Pass 4313548518197Pass 5313548518197Comparisons: 15, Swaps: 9
Solution:
Initial: [97, 31, 48, 81, 51, 35]
Pass 1: [31, 48, 81, 51, 35, 97]
Pass 2: [31, 48, 51, 35, 81, 97]
Pass 3: [31, 48, 35, 51, 81, 97]
Pass 4: [31, 35, 48, 51, 81, 97]
Pass 5: [31, 35, 48, 51, 81, 97]
Answer: [31, 35, 48, 51, 81, 97]
2. Show the array after each pass of insertion sort: [8, 76, 99, 82, 46, 94]
Initial87699824694After i=187699824694After i=287699824694After i=387682994694After i=484676829994After i=584676829499Comparisons: 10, Swaps: 0
Solution:
Initial: [8, 76, 99, 82, 46, 94]
After i=1: [8, 76, 99, 82, 46, 94]
After i=2: [8, 76, 99, 82, 46, 94]
After i=3: [8, 76, 82, 99, 46, 94]
After i=4: [8, 46, 76, 82, 99, 94]
After i=5: [8, 46, 76, 82, 94, 99]
Answer: [8, 46, 76, 82, 94, 99]
3. Show the array after each pass of selection sort: [89, 96, 63, 25, 47, 31]
Initial899663254731Pass 1259663894731Pass 2253163894796Pass 3253147896396Pass 4253147638996Pass 5253147638996Comparisons: 15, Swaps: 4
Solution:
Initial: [89, 96, 63, 25, 47, 31]
Pass 1: [25, 96, 63, 89, 47, 31]
Pass 2: [25, 31, 63, 89, 47, 96]
Pass 3: [25, 31, 47, 89, 63, 96]
Pass 4: [25, 31, 47, 63, 89, 96]
Pass 5: [25, 31, 47, 63, 89, 96]
Answer: [25, 31, 47, 63, 89, 96]
4. Trace a binary search for 78 in the sorted array: [8, 21, 33, 45, 65, 77, 78, 86]
Initial (sorted)821334565777886low=0, high=7, mid=3 → 45 < 78, go right821334565777886low=4, high=7, mid=5 → 77 < 78, go right821334565777886low=6, high=7, mid=6 → found at index 6821334565777886
Solution:
Initial (sorted)
low=0, high=7, mid=3 → 45 < 78, go right
low=4, high=7, mid=5 → 77 < 78, go right
low=6, high=7, mid=6 → found at index 6
Answer: Found at index 6
5. Show the array after each pass of bubble sort: [11, 28, 7, 63, 92, 35]
Initial11287639235Pass 111728633592Pass 271128356392Pass 371128356392Comparisons: 12, Swaps: 4
Solution:
Initial: [11, 28, 7, 63, 92, 35]
Pass 1: [11, 7, 28, 63, 35, 92]
Pass 2: [7, 11, 28, 35, 63, 92]
Pass 3: [7, 11, 28, 35, 63, 92]
Answer: [7, 11, 28, 35, 63, 92]
6. Show the array after each pass of insertion sort: [21, 1, 68, 81, 5, 60]
Initial2116881560After i=11216881560After i=21216881560After i=31216881560After i=41521688160After i=51521606881Comparisons: 10, Swaps: 0
Solution:
Initial: [21, 1, 68, 81, 5, 60]
After i=1: [1, 21, 68, 81, 5, 60]
After i=2: [1, 21, 68, 81, 5, 60]
After i=3: [1, 21, 68, 81, 5, 60]
After i=4: [1, 5, 21, 68, 81, 60]
After i=5: [1, 5, 21, 60, 68, 81]
Answer: [1, 5, 21, 60, 68, 81]
7. Show the array after each pass of selection sort: [70, 93, 4, 56, 90, 59]
Initial70934569059Pass 149370569059Pass 245670939059Pass 345659939070Pass 445659709093Pass 545659709093Comparisons: 15, Swaps: 4
Solution:
Initial: [70, 93, 4, 56, 90, 59]
Pass 1: [4, 93, 70, 56, 90, 59]
Pass 2: [4, 56, 70, 93, 90, 59]
Pass 3: [4, 56, 59, 93, 90, 70]
Pass 4: [4, 56, 59, 70, 90, 93]
Pass 5: [4, 56, 59, 70, 90, 93]
Answer: [4, 56, 59, 70, 90, 93]
8. Trace a binary search for 72 in the sorted array: [10, 26, 27, 31, 46, 52, 72, 84]
Initial (sorted)1026273146527284low=0, high=7, mid=3 → 31 < 72, go right1026273146527284low=4, high=7, mid=5 → 52 < 72, go right1026273146527284low=6, high=7, mid=6 → found at index 61026273146527284
Solution:
Initial (sorted)
low=0, high=7, mid=3 → 31 < 72, go right
low=4, high=7, mid=5 → 52 < 72, go right
low=6, high=7, mid=6 → found at index 6
Answer: Found at index 6
9. Show the array after each pass of bubble sort: [44, 89, 15, 2, 19, 75]
Initial44891521975Pass 144152197589Pass 215219447589Pass 321519447589Pass 421519447589Comparisons: 14, Swaps: 8
Solution:
Initial: [44, 89, 15, 2, 19, 75]
Pass 1: [44, 15, 2, 19, 75, 89]
Pass 2: [15, 2, 19, 44, 75, 89]
Pass 3: [2, 15, 19, 44, 75, 89]
Pass 4: [2, 15, 19, 44, 75, 89]
Answer: [2, 15, 19, 44, 75, 89]
10. Show the array after each pass of insertion sort: [43, 73, 8, 37, 97, 77]
Initial43738379777After i=143738379777After i=284373379777After i=383743739777After i=483743739777After i=583743737797Comparisons: 9, Swaps: 0
Solution:
Initial: [43, 73, 8, 37, 97, 77]
After i=1: [43, 73, 8, 37, 97, 77]
After i=2: [8, 43, 73, 37, 97, 77]
After i=3: [8, 37, 43, 73, 97, 77]
After i=4: [8, 37, 43, 73, 97, 77]
After i=5: [8, 37, 43, 73, 77, 97]
Answer: [8, 37, 43, 73, 77, 97]
Answers computed by code. No AI, no credits.

Assumptions and Conventions

Assumptions:
  • Bubble sort: compare adjacent pairs, swap if out of order, repeat until sorted.
  • Insertion sort: take each element and insert it into the correct position in the sorted part.
  • Selection sort: find the minimum element and swap it to the front, repeat for the rest.
  • Binary search: requires a sorted array. Compare the middle element, then search left or right half.
Conventions:
  • Array indices start at 0.
  • Each pass shows the full array state after that pass is complete.
  • Comparisons and swaps are counted across the entire sort.
Made with TeachSpark

Sorting and Searching - High school CS - Sorting and searching

Bubble sort, insertion sort, selection sort, and binary search with step-by-step traces. No AI, no credits.

Options

TeachSpark uses cookies and local storage to improve your experience and process payments securely. Learn More