Arrays
Arrays are contiguous blocks of memory that store elements of the same type.
Implementation
- Python
- TypeScript
- Golang
# Initialize an array
arr = [1, 2, 3, 4, 5]
# Access element
first = arr[0]
# Modify element
arr[0] = 10
# Add element to end
arr.append(6)
# Remove last element
arr.pop()
// Initialize an array
const arr: number[] = [1, 2, 3, 4, 5];
// Access element
const first: number = arr[0];
// Modify element
arr[0] = 10;
// Add element to end
arr.push(6);
// Remove last element
arr.pop();
package main
import "fmt"
func arrayOperations() []int {
// Initialize an array
arr := []int{1, 2, 3, 4, 5}
// Access element
first := arr[0]
fmt.Println("First element:", first)
// Modify element
arr[0] = 10
// Add element to end
arr = append(arr, 6)
// Remove last element
arr = arr[:len(arr)-1]
return arr
}
Operations
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Access | ||
| Search | ||
| Insert | ||
| Delete | ||
| Sort |