Every beginner’s programming journey starts with solving the questions of Array. Being a programmer you might have surely used this data structure a lot in your application. This data structure is used in every possible situation where you need to collect the object in one place. From simple to complex software or web application array is mostly used to store and display the data dynamically at web pages. Let’s take one of the good examples of using an array in a real-world application…
We all must have used the online ticket booking system at least once. It might be for booking tickets for train or maybe bus or flights or movies or any other shows. If we want to book any seat, then it’s just a matter of clicking on a square and it will be booked.
Arrays
An array is a structure of fixed-size, which can hold items of the same data type. It can be an array of integers, an array of floating-point numbers, an array of strings or even an array of arrays (such as 2-dimensional arrays). Arrays are indexed, meaning that random access is possible.
Array operations
- Traverse: Go through the elements and print them.
- Search: Search for an element in the array. You can search the element by its value or its index
- Update: Update the value of an existing element at a given index Inserting elements to an array and deleting elements from an array cannot be done straight away as arrays are fixed in size. If you want to insert an element to an array, first you will have to create a new array with increased size (current size + 1), copy the existing elements and add the new element. The same goes for the deletion with a new array of reduced size.
Applications of arrays
- Used as the building blocks to build other data structures such as array lists, heaps, hash tables, vectors and matrices.
- Used for different sorting algorithms such as insertion sort, quick sort, bubble sort and merge sort.
Problems on Array
while searching element it always takes o(n) complexity
In an array we can not store different kinds of values It will store only the same data type of values at a time.
Array size is fixed.
So to overcome these problems of array new data structure came into the picture which is known as LinkedList. (Next post)
Some Common coding interviews Problems related to array:
- Reverse an array.
- Sum of array elements.
- Find maximum and minimum elements of an array.
- Search an element in an array.
- Find the kth max and min element in an array.
- Sort array of 0, 1, 2. with and without extra space.
- Rotate array by one.
- Find missing numbers from an array.
- Move all negative numbers to one side of the array.
- Union and Intersection of two arrays
- Longest consecutive subsequence in an array.
Top comments (0)