Join Raghavendra Dixit for an in-depth discussion in this video Merge step: Pseudocode, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's get to the pseudocode…of the merge method.…This is quite simple.…Just keep in mind that we have divided the arrays logically.…One part of the array is from start to mid index,…while the other part of the array is from mid plus one index…to the end index, all right?…So let's say we are in this last step of merge,…when these two parts of the array…have been recursively sorted by merge sort,…and now we are doing the final merge step.…While merging, if we overwrite on the array,…we will lose the data, right?…So the first thing we can do to keep things simple is…we create two temporary arrays…and copy the elements from this main array…over to those two.…
So let's first find the size of the arrays.…For the left array,…the size may be found as mid minus start plus one,…and for the second array, the size will be end minus mid,…and you can see both parts contain four elements each,…so that should be the size of the two arrays.…So let's create two arrays of sizes n1 and n2, respectively,…and name them left and right.…
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.