–tags: Data Structures
Arrays:
- Ordered collection of items with an index
- Index used to find the data
- Zero based index
- Fixed size - they are immutable
- dynamically add or remove elements in runtime
- data type is mostly specific
- the more constraints you put into data type ; the smaller efficient and practical use
- Flexibility comes at the cost of performance and memory
Multidimensional arrays:
- Rows and columns: Array of arrays
- different dimensional arrays: collection of n-1 arrays is the n- dimensional arrays
- Multiple locations: Sets of days and time for the weather is a 3d array
Jagged arrays:
- Not only rectangular arrays
- For days in months: there are relevant places where data is empty
- Internal arrays having different lengths
- new int[12][] gives us feasibility to write different one dimensional arrays in different situations
Resizable arrays:
- all arrays that are defined firstly are immutable
- array list is different and instantiated as an object
- Objectives C gives the NSArray is immutable
- NSMutableArray has mutability
Question:
- Adding element at the top or the bottom
- Add the element at specific position
- Larger the array there is performance lag
- Same functionality is used in a different way in every programming language
- pop is used mostly to remove the item in a array
Sorting in an array:
- Internal structure and index remains the same
- Colossal amount of data if there are thousands of data to work with
- Different sorting algorithms on the basis of data size
- So, to choose different types and different mechanisms for sorting on the basis of how frequently the data needs to be sorted and how much data is to be sorted
Arrays of custom objects SORT:
- Information to sort on which order
- Look into these objects and sort according to some data inside the object
- Bit of logic: making a comparator function to order or sort the objects
Searching arrays:
- Sequential search to find the element
- Linear time algorithm
- Need to check every data just to find the data and predictable sequence to find data easily
- Cannot have a data structure that is equally good in all situations
Built in search behavior:
- .contains(data_item)
- .indexof(data_item)
Binary search
- Faster
- Begins the array with the half
- Goes into the midpoint again and finds the data as last
- Half interval search or Divide-and-conquer algorithm
- .binarySearch in almost all languages