Arrays

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

10 Terms

1
New cards

What is Data structure

Structuring our data inside of RAM

2
New cards

RAM

  • RAM is measured in bytes

  • Byte = 8 Bits

  • A bit can be thought of as position that can store a digit

  • A digit can be either 0 or 1

  • A simple digit (like natural numbers) takes 4 bytes

  • Giga → 109

3
New cards

RAM components

RAM is made of:

  • Values

  • Addresses

Every value is stored at a distinct location

4
New cards

Arrays

  • Arrays store characters the same way as numbers but each character takes only 1 byte to store in memory

<ul><li><p>Arrays store characters the same way as numbers but each character takes only 1 byte to store in memory</p></li></ul>
5
New cards

Any data structure the two most common operations

  • Reading to the data

  • writing to the data

6
New cards

Reading the data (from an array)

  1. "Reading from an array" refers to accessing and retrieving elements stored within an array data structure in a programming language.

  2. Arrays are containers that store a collection of elements, and reading from an array involves retrieving specific elements or iterating through all elements in the array.

7
New cards

Writing to an array (static array)

Arrays are fixed-size.

Static arrays mean that they are fixed-size arrays.

In most programming languages, static arrays have a fixed size that cannot be changed once they are initialized.
Therefore, directly removing the last element from a static array is typically not supported. Instead, you'd usually overwrite the value in the last position or adjust the logic to work within the bounds of the array size.

let arr = [1,2,3]
arr[arr.length - 1] = null // Overwriting the last element with null
8
New cards

O(n)

  • O means → In the worst case.

  • n → refers to a variable.

9
New cards

i-th

i-th means → any arbitrary element you could pick, any index

10
New cards

Summary of static array

  • r/w i-th element → O(1). you could do it in constant time

  • Insert/Remove End → O(1)

  • Insert Middle → O(n)

  • Remove Middle → O(n)