An Interest In:
Web News this Week
- March 28, 2024
- March 27, 2024
- March 26, 2024
- March 25, 2024
- March 24, 2024
- March 23, 2024
- March 22, 2024
Arrays | Must-known DSA Array Techniques
Webinar by Scalar and Naman Bhalla
What are Arrays?
*Linear Data Structure
*A way to store data of the same time
*Allows to get a value at any position in O(1) time
How to implement Arrays in Java ?
in Java: int[] arrayName =new int[size]
in javascript/python:
we can store different data types because it point to the object referencing array implementation in python and js
How does Array store data?
Array store data in different address of the RAM
int arr[4]- each int is 4 byte, 4*4 elements
16 byte is allocated when we run the program.
Finding Element in Arrays-
if the array is 0 indexed then , if we have to find the 3rd element, then we look for 3-1 i.e. n-1 multiple from the start position/index
13+2*4= 13+8=21 so element will be stored at 21th address
*Dynamic Arrays- *
in case of JS and python
in dynamic array no need to tell the size of the array, you can keep adding the elements infinitely, but it has to be restricted by RAM size or till the time out of memory size
in C++- Vectors
in Java- ArrayList
in Python-
in js - {}(list)
How Dynamic arrays work-
Dynamic array offer capacity and size.
capacity is arbitrary value defined by the programming language, size can be defined by user.
when array gets full initial capacity, the dynamic arrays provides extra capacity of 1.75* or 2*, depending on the programming language, this is all happening behind the scenes.
for N insertion :
the worst case is when added array will lead to creation of the new element and size increase.
time to insert+ capacity time or creating array + copy time
=N+[2N+ 2N/2+ 2N/4+.....]+[N+N/2+N/4+....]
=N+4N+2N=7N
sum of (1+1/2+1/4+1/8.....) will always be less than 2
for N insertion is nN/n = N
time complexity: O(1)
the Dynamic array has no loss, so feel free to use day to day and dynamic programming.
initialization and putting the value:
Vector array[]
array.push(11)
Follow Kritika Agarwal on Linkedin :
Kritika Agarwal Software Engineer II at Microsoft
Original Link: https://dev.to/insanity_xi/arrays-must-known-dsa-array-techniques-2omh
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To