<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022" -->

---
title: Arrays: From Classroom Attendance to Algorithms | daily.dev
description: An introductory lesson explains arrays using a classroom attendance analogy, covering indexing, why array access is O(1), and how common operations (access,...
canonical: https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Arrays: From Classroom Attendance to Algorithms | daily.dev
og:description: An introductory lesson explains arrays using a classroom attendance analogy, covering indexing, why array access is O(1), and how common operations (access,...
og:url: https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022
og:image: https://api.daily.dev/og/posts/Mk2QCC022.png
og:image:alt: Arrays: From Classroom Attendance to Algorithms
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Arrays: From Classroom Attendance to Algorithms

**[Code Like A Girl](https://daily.dev/sources/colkgirl)** · 11 min read · 4 upvotes · 0 comments

## Summary

An introductory lesson explains arrays using a classroom attendance analogy, covering indexing, why array access is O(1), and how common operations (access, search, insert, delete) differ in time complexity. Two beginner coding problems (finding the largest number and counting even numbers) illustrate the Linear Traversal pattern, with JavaScript code and complexity analysis. The piece closes by listing DSA patterns that build on arrays and suggests LeetCode problems for practice.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://code.likeagirl.io/arrays-from-classroom-attendance-to-algorithms-12ba7e71f73a>

## Questions this post answers

### Why is accessing an array element by index O(1) but searching for a value O(n)?

Accessing an element by index is O(1) because the computer already knows the exact memory position and can jump directly to it, regardless of array size. Searching for a value is O(n) because the computer has no way of knowing where that value is located, so it must check elements one by one until it finds a match or reaches the end.

_Developers solidifying big-O intuition for arrays can find worked walkthroughs like this one through daily.dev._

### Why does inserting an element at the beginning of an array take O(n) time?

Inserting at the beginning requires shifting every existing element one position to the right to make room for the new value, so the number of moves grows with the array size, giving O(n) time complexity. In contrast, inserting at the end usually takes O(1) since no other elements need to move. Deleting from the beginning is also O(n) for the same shifting reason.

_Anyone weighing array operation costs before choosing a data structure can track explanations like this via daily.dev._

## Similar posts on daily.dev

- [Lear Data Structures and Algorithms Visually](https://daily.dev/posts/lear-data-structures-and-algorithms-visually-uk37akbzk) · freeCodeCamp · 1 upvotes · 0 comments
- [Before We Compare Solutions, We Need a Way to Measure Them](https://daily.dev/posts/before-we-compare-solutions-we-need-a-way-to-measure-them-imi1jm8f6) · Code Like A Girl · 1 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#algorithms](https://daily.dev/tags/algorithms), [#data-structures](https://daily.dev/tags/data-structures), [#time-complexity](https://daily.dev/tags/time-complexity)

[View this post on daily.dev](https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Arrays: From Classroom Attendance to Algorithms","url":"https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022"},"datePublished":"2026-08-14T07:41:29.956Z","dateModified":"2026-09-13T19:44:22.859Z","description":"An introductory lesson explains arrays using a classroom attendance analogy, covering indexing, why array access is O(1), and how common operations (access,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/096c5b97f1edce3dd73f1217a7a3440a?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/096c5b97f1edce3dd73f1217a7a3440a?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code Like A Girl","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code Like A Girl","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/82e21f28c59c499f9c47833c55500fd8","url":"https://daily.dev/sources/colkgirl"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,algorithms,data-structures,time-complexity","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code Like A Girl","item":"https://daily.dev/sources/colkgirl"},{"@type":"ListItem","position":3,"name":"Arrays: From Classroom Attendance to Algorithms"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/arrays-from-classroom-attendance-to-algorithms-mk2qcc022#faq","mainEntity":[{"@type":"Question","name":"Why is accessing an array element by index O(1) but searching for a value O(n)?","acceptedAnswer":{"@type":"Answer","text":"Accessing an element by index is O(1) because the computer already knows the exact memory position and can jump directly to it, regardless of array size. Searching for a value is O(n) because the computer has no way of knowing where that value is located, so it must check elements one by one until it finds a match or reaches the end. Developers solidifying big-O intuition for arrays can find worked walkthroughs like this one through daily.dev."}},{"@type":"Question","name":"Why does inserting an element at the beginning of an array take O(n) time?","acceptedAnswer":{"@type":"Answer","text":"Inserting at the beginning requires shifting every existing element one position to the right to make room for the new value, so the number of moves grows with the array size, giving O(n) time complexity. In contrast, inserting at the end usually takes O(1) since no other elements need to move. Deleting from the beginning is also O(n) for the same shifting reason. Anyone weighing array operation costs before choosing a data structure can track explanations like this via daily.dev."}}]}
```

