티스토리 뷰

data structure

Array

summercat 2022. 1. 19. 16:05

배열 생성 시 배열의 길이(size)를 지정해야 함 (JS, Python의 경우 언어에서 이 부분을 핸들링해주기 때문에 길이를 지정하지 않고 생성 가능)
Characteristics of array
- 0-indexed: array’s elements are indexed from 0
- very fast when reading data, but slow in searching/adding/deleting


Types of Operation and how it works
- Read: give index number of an element and get it > super fast
- Search: find the element the user wants > have to check every element of an array from index 0 until you find the element you want (linear search) > not very fast
- Insert(add): the speed depends on where new element is added
if an element is added in between / at the start of an array, elements that comes later than the added element should be moved to next index before new element is added
if total number of elements get larger than given size of the array, copy the original array to a new array and add element
- Delete:
if the user wants to remove an element in middle/start, elements that comes after should be moved forth >

'data structure' 카테고리의 다른 글

Sort  (0) 2022.01.19
Type of Time Complexity (Big O notation)  (0) 2022.01.19
Search Algorithms (Binary Search/ Linear Search)  (0) 2022.01.19
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함