Join Raghavendra Dixit for an in-depth discussion in this video Selection sort: Pseudocode, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's look at the pseudocode…for the selection sort algorithm.…What we are doing with the selection sort algorithm is that…we are swapping the smallest number with the first element,…then moving to the second element and swapping the next…largest with the second element, and so on.…So we start from the first element,…which is the zero index and go all the way up…to the second last element, whose index is equal…to two less than the length of the array.…
So the index i will keep track of the element…from which the minimum needs to be exchanged, all right?…Then we need to find the index…containing the minimum element.…So we can initialize it with i because in each iteration,…the element at i may be the minimum.…As you can see, we don't care about elements…before the i index because they will all be sorted.…After initializing the min index with i,…we can look through all the remaining elements of the array,…starting from i plus one at index…and see which of them is the minimum.…
So we write another loop going from index i plus one…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.