Join Raghavendra Dixit for an in-depth discussion in this video Inserting and deleting items in an ordered array, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's see how to insert and delete…items in an ordered array, and the time complexity…involved in these operations.…Let's say we want to insert this item 52…in the ordered array shown.…Well, the thing is that even after inserting the item,…the array should remain ordered, alright?…So that means you must first find the slot…where this new element goes.…And understand that we are…not really finding this item 52, alright?…So we pretty much have to start in a linear fashion,…starting from the left.…
We keep checking for items at each index,…until we find the one which is greater than…the item to be inserted, which is 52.…So now we need to make space for that.…So we need to move all the items over by one index…until there is an empty slot for the new element.…Then we copy the element in this empty slot, alright?…So inserting an item takes order of n time,…because first we need to search for the slot…going over all the elements linearly,…and then also move the items to make space…for the new element, alright?…
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.