Get 2 days of premium access
Class Notes (1,000,000)
US (430,000)
Rutgers (10,000)
4:18 (300)
Lecture 5

# 01:198:111 Lecture Notes - Lecture 5: Insertion Sort, Selection Sort, SubstringExam

Department
Computer Science
Course Code
01:198:111
Professor
A Centeno
Lecture
5

This preview shows half of the first page. to view the full 3 pages of the document.
Kirti Mitaliya
Professor Ana Centeno
Introduction to Computer Science
12 December 2018
Written Assignment 5
Problem #1:
List the resulting array after each iteration of the selection sort algorithm. Indicate the number of
letter-to-letter comparisons made for each iteration. Sort the following array of letters (sort into
alphabetical order):
Original: [C Q S A X B T] # of comparisons:
[A | C Q S X B T] 6
[A B | C Q S X T] 5
[A B C | Q S X T] 4
[A B C Q | S X T] 3
[A B C Q S | X T] 2
[A B C Q S T | X] 1
Final Sorted Array: [A B C Q S T X] 21 total comparisons
b) List the resulting array after each iteration of the insertion sort algorithm. Indicate the number
of letter-to-letter comparisons made for each iteration. Sort the following array of letters (sort
into alphabetical order):
# of Iterations:
GIVEN: [C | Q S A X B T] 0
[ C Q | S A X B T] 1
[C Q S | A X B T] 2
[A C Q S | X B T] 1
[A C Q S X | B T] 4
[A B C Q S X | T] 5
Sorted Array: [A B C Q S T X] 13 total comparisons