Dsa Week 2 Updates
Dsa Week 2 Updates
Data Structures
CS2001
Email: [email protected]
Array
Contiguous area of memory consisting of equal-size elements
indexed by contiguous integers.
What’s Special About Arrays?
Random access memory.
Constant time access (O(1)) to any particular element in an array.
Constant time to access read and write
memory address = ArrayName+index*sizeof(datatype)
Creating
two
arrays
using
pointers
Copying the elements of array
Multidimensio
nal Array
Multidimensional Array
Multidi
mension
al Array
Multidimensional Array
Times for common operations
Summary
• Array: contiguous area of memory consisting of equal-size
elements indexed by contiguous integers.
• Constant-time access to any element.
• Constant-time to add/remove at the end.
• Linear time to add/remove at an arbitrary location.
Please get the concepts using visuals
https://visualgo.net/en/array
Linked List
An array is a very useful data structure provided in programming
languages. However, it has at least two limitations:
(1) its size has to be known at compilation time and
(2) the data in the array are separated in computer memory by
the same distance, which means that inserting an item inside the
array requires shifting other data in this array.
Node contains:
• Keys/Data/Content
• next pointer
Observation
• For fixed-size collections with known max limit of number of
items that will ever be needed, i.e., the max size of M, then
array is already a reasonably good data structure for List ADT
implementation.
3. Circular List:
• Delete/remove first
node
• Time complexity O(1)
Singly-linked list;
Return front item
operation
• Delete/remove first
node
• Time complexity O(1)
Add new node to tail
• add to back
(no tail pointer)
new node
Doubly-Linked List
There is a way to make popping the back and adding before cheap.
Our problem was that although we had a way to get from a previous
element to the next element, we had no way to get back. And what a
doubly-linked list says is, well, let's go ahead and add a way to get
back. So we'll have two pointers, forward and back pointers.
Doubly-Linked List
Node contains:
• key
• next pointer
• previous pointer
PopBack()
I will attached the complete code cpp file on GCR along with the
this slide lecture.
You can check the snapshots of the function code on next slide
Interpolation Search
● Interpolation search is an improvement over binary search.
● Binary Search always checks the value at middle index. But,
interpolation search may check at different locations based on
the value of element being searched.
● For interpolation search to work efficiently the array
elements/data should be sorted and uniformly distributed.
Example if we are
looking for element 4 in
the given array
Code Example
I will attached the complete code cpp file on GCR along with the
this slide lecture.
Reference
https://www.cs.emory.edu/~cheung/Courses/170/Syllabus/09/cop
y-array.html
Book - “Data Structures and Algorithms in C++ by Adam
Drozdek”
All you need to have to achieve a
dream/goal/task!!
Three promises you have to make to yourself!
Watch full video!!
https://www.youtube.com/watch?v=uxoCnxlxpIk