BeFreed
    Categories>Technology>Real-Time Medians with Two Heaps: Efficient Streaming Data

    Real-Time Medians with Two Heaps: Efficient Streaming Data

    23 min
    |
    |
    13 mag 2026
    TechnologyEducationCareer

    Learn how to calculate real-time medians for streaming data using the two heaps method. Achieve O(1) time complexity for instant results in ad tech and analytics.

    Real-Time Medians with Two Heaps: Efficient Streaming Data

    Miglior citazione da Real-Time Medians with Two Heaps: Efficient Streaming Data

    “

    By using two heaps working in tandem—a Max-Heap for the lower half and a Min-Heap for the upper half—you can achieve $O(\log n)$ for adding or deleting numbers and a staggering $O(1)$ for grabbing the median.

    ”

    Questa lezione audio è stata creata da un membro della comunità BeFreed

    Domanda di input

    Add, delete, get median int values methods in python 3. This is for a CodeSignal assessment.

    Voci dei presentatori
    Niaplay
    Jacksonplay
    Stile di apprendimento
    Approfondito
    Fonti di conoscenza
    Loading...
    link
    https://codesignal.com/learn/courses/understanding-and-using-trees-in-python/lessons/solving-real-world-problems-with-heaps-in-python?courseSlug=understanding-and-using-trees-in-python
    Running Median in O(log n) time in Python
    link
    https://stackoverflow.com/questions/68949041/running-median-in-olog-n-time-in-python
    Median of K Sliding Windows (Extended Practice) | Webcoderspeed
    link
    https://webcoderspeed.com/blog/dsa-heaps/35-find-median-sliding-window-variant
    How can I delete element in log(n) from priority queue implemented through heapq in python?
    link
    https://stackoverflow.com/questions/25828788/how-can-i-delete-element-in-logn-from-priority-queue-implemented-through-heapq

    Domande frequenti

    The most efficient approach for calculating real-time medians involves using two heaps working in tandem. This data structure strategy allows you to maintain a perfectly balanced center point as new data arrives. Unlike naive sorting methods that crawl to a stop as datasets grow, the two heaps method provides a way to handle high-frequency data streams, such as click-stream info in ad tech, with significantly better performance and algorithm optimization.

    Using two heaps transforms the performance of your application by offering O(log n) time complexity for adding or deleting numbers and a staggering O(1) complexity for retrieving the median. While a standard list requires an O(n log n) sorting cost that creates a performance wall, the two heaps approach ensures the answer is essentially ready instantly. This makes it an essential technique for acing a CodeSignal assessment or managing real-world streaming analytics.

    In an ad tech environment where data hits servers every millisecond, a naive approach of tossing numbers into a list and sorting them is a nightmare. As the volume of click-stream data increases, the computational cost of sorting causes the code to crawl to a stop. To handle a literal firehose of data effectively, developers must move away from constant sorting and utilize specialized data structures like heaps to maintain real-time responsiveness.

    Scopri di più

    Study Nate Silver's statistical methods
    PIANO DI APPRENDIMENTO

    Study Nate Silver's statistical methods

    In an era of data overload, the ability to filter out noise is a critical competitive advantage. This plan is ideal for data analysts, political junkies, and sports bettors who want to adopt the rigorous, Bayesian-inspired framework that made Nate Silver a household name.

    3 h 49 m•4 Sezioni
    多维效能:全场景时间管理系统
    PIANO DI APPRENDIMENTO

    多维效能:全场景时间管理系统

    在碎片化时代,传统时间管理已难以应对复杂的多任务挑战。本课程专为追求高产出、管理多重身份的职场精英设计,旨在通过精力管理与数字工具重塑个人的效能系统。

    1 h 36 m•4 Sezioni
    To upgrade speed reading and comprehension.
    PIANO DI APPRENDIMENTO

    To upgrade speed reading and comprehension.

    In an age of information overload, the ability to process and retain complex data quickly is a critical competitive advantage. This plan is ideal for students, researchers, and professionals who need to master dense material without sacrificing comprehension.

    3 h 32 m•4 Sezioni
    大模型数据极限下的技术博弈
    PIANO DI APPRENDIMENTO

    大模型数据极限下的技术博弈

    随着互联网公开数据趋于极限,如何突破数据瓶颈已成为大模型竞争的核心。本课程深入探讨合成数据、数据策展及算法优化,适合希望掌握前沿大模型训练策略的算法工程师与技术决策者。

    1 h 24 m•3 Sezioni
    Read more in less time
    PIANO DI APPRENDIMENTO

    Read more in less time

    In an era of information overload, the ability to process and retain knowledge quickly is a competitive necessity. This plan is designed for professionals and lifelong learners who want to master speed reading, effective note-taking, and analytical strategies to maximize their intellectual ROI.

    4 h 6 m•4 Sezioni
    Deep Work for High-Stakes Deadlines
    PIANO DI APPRENDIMENTO

    Deep Work for High-Stakes Deadlines

    In an era of constant digital noise, the ability to focus on complex tasks is a rare competitive advantage. This plan is designed for professionals facing tight deadlines who need to optimize their mental energy and reclaim control over their schedules.

    2 h 18 m•3 Sezioni
    Rapid Synthesis and Conversational Agility
    PIANO DI APPRENDIMENTO

    Rapid Synthesis and Conversational Agility

    In a fast-paced world, the ability to process information and respond instantly is a critical competitive advantage. This plan is designed for professionals and social navigators who want to overcome mental blocks and master the art of rapid, witty engagement.

    1 h 12 m•3 Sezioni
    Improve Time Management · Test 05-21
    PIANO DI APPRENDIMENTO

    Improve Time Management · Test 05-21

    In an era of constant digital distractions, mastering your schedule is a critical competitive advantage. This plan is designed for professionals and students who feel overwhelmed by their to-do lists and want to transition from reactive multitasking to proactive, high-impact work.

    5 h 12 m•4 Sezioni

    Creato da alumni della Columbia University a San Francisco

    BeFreed Riunisce Una Community Globale Di 1,000,000 Menti Curiose
    Scopri di piu su come si parla di BeFreed nel web

    "Instead of endless scrolling, I just hit play on BeFreed. It saves me so much time."

    @Moemenn
    platform
    star
    star
    star
    star
    star

    "I never knew where to start with nonfiction—BeFreed’s book lists turned into podcasts gave me a clear path."

    @Chloe, Solo founder, LA
    platform
    comments
    12
    likes
    117

    "Perfect balance between learning and entertainment. Finished ‘Thinking, Fast and Slow’ on my commute this week."

    @Raaaaaachelw
    platform
    star
    star
    star
    star
    star

    "Crazy how much I learned while walking the dog. BeFreed = small habits → big gains."

    @Matt, YC alum
    platform
    comments
    12
    likes
    108

    "Reading used to feel like a chore. Now it’s just part of my lifestyle."

    @Erin, Investment Banking Associate , NYC
    platform
    comments
    254
    likes
    17

    "Feels effortless compared to reading. I’ve finished 6 books this month already."

    @djmikemoore
    platform
    star
    star
    star
    star
    star

    "BeFreed turned my guilty doomscrolling into something that feels productive and inspiring."

    @Pitiful
    platform
    comments
    96
    likes
    4.5K

    "BeFreed turned my commute into learning time. 20-min podcasts are perfect for finishing books I never had time for."

    @SofiaP
    platform
    star
    star
    star
    star
    star

    "BeFreed replaced my podcast queue. Imagine Spotify for books — that’s it. 🙌"

    @Jaded_Falcon
    platform
    comments
    201
    thumbsUp
    16

    "It is great for me to learn something from the book without reading it."

    @OojasSalunke
    platform
    star
    star
    star
    star
    star

    "The themed book list podcasts help me connect ideas across authors—like a guided audio journey."

    @Leo, Law Student, UPenn
    platform
    comments
    37
    likes
    483

    "Makes me feel smarter every time before going to work"

    @Cashflowbubu
    platform
    star
    star
    star
    star
    star

    Creato da alumni della Columbia University a San Francisco

    BeFreed Riunisce Una Community Globale Di 1,000,000 Menti Curiose
    Scopri di piu su come si parla di BeFreed nel web

    "Instead of endless scrolling, I just hit play on BeFreed. It saves me so much time."

    @Moemenn
    platform
    star
    star
    star
    star
    star

    "I never knew where to start with nonfiction—BeFreed’s book lists turned into podcasts gave me a clear path."

    @Chloe, Solo founder, LA
    platform
    comments
    12
    likes
    117

    "Perfect balance between learning and entertainment. Finished ‘Thinking, Fast and Slow’ on my commute this week."

    @Raaaaaachelw
    platform
    star
    star
    star
    star
    star

    "Crazy how much I learned while walking the dog. BeFreed = small habits → big gains."

    @Matt, YC alum
    platform
    comments
    12
    likes
    108

    "Reading used to feel like a chore. Now it’s just part of my lifestyle."

    @Erin, Investment Banking Associate , NYC
    platform
    comments
    254
    likes
    17

    "Feels effortless compared to reading. I’ve finished 6 books this month already."

    @djmikemoore
    platform
    star
    star
    star
    star
    star

    "BeFreed turned my guilty doomscrolling into something that feels productive and inspiring."

    @Pitiful
    platform
    comments
    96
    likes
    4.5K

    "BeFreed turned my commute into learning time. 20-min podcasts are perfect for finishing books I never had time for."

    @SofiaP
    platform
    star
    star
    star
    star
    star

    "BeFreed replaced my podcast queue. Imagine Spotify for books — that’s it. 🙌"

    @Jaded_Falcon
    platform
    comments
    201
    thumbsUp
    16

    "It is great for me to learn something from the book without reading it."

    @OojasSalunke
    platform
    star
    star
    star
    star
    star

    "The themed book list podcasts help me connect ideas across authors—like a guided audio journey."

    @Leo, Law Student, UPenn
    platform
    comments
    37
    likes
    483

    "Makes me feel smarter every time before going to work"

    @Cashflowbubu
    platform
    star
    star
    star
    star
    star

    "Instead of endless scrolling, I just hit play on BeFreed. It saves me so much time."

    @Moemenn
    platform
    star
    star
    star
    star
    star

    "I never knew where to start with nonfiction—BeFreed’s book lists turned into podcasts gave me a clear path."

    @Chloe, Solo founder, LA
    platform
    comments
    12
    likes
    117

    "Perfect balance between learning and entertainment. Finished ‘Thinking, Fast and Slow’ on my commute this week."

    @Raaaaaachelw
    platform
    star
    star
    star
    star
    star

    "Crazy how much I learned while walking the dog. BeFreed = small habits → big gains."

    @Matt, YC alum
    platform
    comments
    12
    likes
    108

    "Reading used to feel like a chore. Now it’s just part of my lifestyle."

    @Erin, Investment Banking Associate , NYC
    platform
    comments
    254
    likes
    17

    "Feels effortless compared to reading. I’ve finished 6 books this month already."

    @djmikemoore
    platform
    star
    star
    star
    star
    star

    "BeFreed turned my guilty doomscrolling into something that feels productive and inspiring."

    @Pitiful
    platform
    comments
    96
    likes
    4.5K

    "BeFreed turned my commute into learning time. 20-min podcasts are perfect for finishing books I never had time for."

    @SofiaP
    platform
    star
    star
    star
    star
    star

    "BeFreed replaced my podcast queue. Imagine Spotify for books — that’s it. 🙌"

    @Jaded_Falcon
    platform
    comments
    201
    thumbsUp
    16

    "It is great for me to learn something from the book without reading it."

    @OojasSalunke
    platform
    star
    star
    star
    star
    star

    "The themed book list podcasts help me connect ideas across authors—like a guided audio journey."

    @Leo, Law Student, UPenn
    platform
    comments
    37
    likes
    483

    "Makes me feel smarter every time before going to work"

    @Cashflowbubu
    platform
    star
    star
    star
    star
    star

    "Instead of endless scrolling, I just hit play on BeFreed. It saves me so much time."

    @Moemenn
    platform
    star
    star
    star
    star
    star

    "I never knew where to start with nonfiction—BeFreed’s book lists turned into podcasts gave me a clear path."

    @Chloe, Solo founder, LA
    platform
    comments
    12
    likes
    117

    "Perfect balance between learning and entertainment. Finished ‘Thinking, Fast and Slow’ on my commute this week."

    @Raaaaaachelw
    platform
    star
    star
    star
    star
    star

    "Crazy how much I learned while walking the dog. BeFreed = small habits → big gains."

    @Matt, YC alum
    platform
    comments
    12
    likes
    108

    "Reading used to feel like a chore. Now it’s just part of my lifestyle."

    @Erin, Investment Banking Associate , NYC
    platform
    comments
    254
    likes
    17

    "Feels effortless compared to reading. I’ve finished 6 books this month already."

    @djmikemoore
    platform
    star
    star
    star
    star
    star

    "BeFreed turned my guilty doomscrolling into something that feels productive and inspiring."

    @Pitiful
    platform
    comments
    96
    likes
    4.5K

    "BeFreed turned my commute into learning time. 20-min podcasts are perfect for finishing books I never had time for."

    @SofiaP
    platform
    star
    star
    star
    star
    star

    "BeFreed replaced my podcast queue. Imagine Spotify for books — that’s it. 🙌"

    @Jaded_Falcon
    platform
    comments
    201
    thumbsUp
    16

    "It is great for me to learn something from the book without reading it."

    @OojasSalunke
    platform
    star
    star
    star
    star
    star

    "The themed book list podcasts help me connect ideas across authors—like a guided audio journey."

    @Leo, Law Student, UPenn
    platform
    comments
    37
    likes
    483

    "Makes me feel smarter every time before going to work"

    @Cashflowbubu
    platform
    star
    star
    star
    star
    star
    1.5K Ratings4.7
    Inizia il tuo percorso di apprendimento, ora
    BeFreed App
    BeFreed

    Impara qualsiasi cosa, personalizzato

    DiscordLinkedIn
    Riassunti di libri in evidenza
    Crucial ConversationsThe Perfect MarriageInto the WildNever Split the DifferenceAttachedGood to GreatSay Nothing
    Categorie di tendenza
    Self HelpCommunication SkillRelationshipMindfulnessPhilosophyInspirationProductivity
    Liste di lettura delle celebrita
    Elon MuskCharlie KirkBill GatesSteve JobsAndrew HubermanJoe RoganJordan Peterson
    Collezione premiata
    Pulitzer PrizeNational Book AwardGoodreads Choice AwardsNobel Prize in LiteratureNew York TimesCaldecott MedalNebula Award
    Argomenti in evidenza
    ManagementAmerican HistoryWarTradingStoicismAnxietySex
    Migliori libri per anno
    2025 Best Non Fiction Books2024 Best Non Fiction Books2023 Best Non Fiction Books
    Autori in evidenza
    Chimamanda Ngozi AdichieGeorge OrwellO. J. SimpsonBarbara O'NeillWinston ChurchillCharlie Kirk
    BeFreed vs altre app
    BeFreed vs. Other Book Summary AppsBeFreed vs. ElevenReaderBeFreed vs. ReadwiseBeFreed vs. Anki
    Strumenti di apprendimento
    Knowledge VisualizerAI Podcast Generator
    Informazioni
    Chi siamoarrow
    Prezziarrow
    FAQarrow
    Blogarrow
    Carrierearrow
    Partnershiparrow
    Programma Ambassadorarrow
    Directoryarrow
    BeFreed
    Try now
    © 2026 BeFreed
    Termini di utilizzoInformativa sulla privacy
    BeFreed

    Impara qualsiasi cosa, personalizzato

    DiscordLinkedIn
    Riassunti di libri in evidenza
    Crucial ConversationsThe Perfect MarriageInto the WildNever Split the DifferenceAttachedGood to GreatSay Nothing
    Categorie di tendenza
    Self HelpCommunication SkillRelationshipMindfulnessPhilosophyInspirationProductivity
    Liste di lettura delle celebrita
    Elon MuskCharlie KirkBill GatesSteve JobsAndrew HubermanJoe RoganJordan Peterson
    Collezione premiata
    Pulitzer PrizeNational Book AwardGoodreads Choice AwardsNobel Prize in LiteratureNew York TimesCaldecott MedalNebula Award
    Argomenti in evidenza
    ManagementAmerican HistoryWarTradingStoicismAnxietySex
    Migliori libri per anno
    2025 Best Non Fiction Books2024 Best Non Fiction Books2023 Best Non Fiction Books
    Strumenti di apprendimento
    Knowledge VisualizerAI Podcast Generator
    Autori in evidenza
    Chimamanda Ngozi AdichieGeorge OrwellO. J. SimpsonBarbara O'NeillWinston ChurchillCharlie Kirk
    BeFreed vs altre app
    BeFreed vs. Other Book Summary AppsBeFreed vs. ElevenReaderBeFreed vs. ReadwiseBeFreed vs. Anki
    Informazioni
    Chi siamoarrow
    Prezziarrow
    FAQarrow
    Blogarrow
    Carrierearrow
    Partnershiparrow
    Programma Ambassadorarrow
    Directoryarrow
    BeFreed
    Try now
    © 2026 BeFreed
    Termini di utilizzoInformativa sulla privacy

    Punti chiave

    1

    Finding the Middle Ground in Real-Time

    0:00
    0:31
    1:03
    1:18
    1:32
    1:39
    1:50
    2:06
    2

    The Two-Heap Balancing Act

    2:38
    2:54
    3:06
    3:16
    3:31
    3:47
    4:06
    4:10
    4:33
    4:48
    4:58
    5:15
    3

    The Challenge of Direct Deletion

    5:34
    5:50
    6:09
    3:16
    6:32
    6:45
    7:04
    7:21
    7:32
    7:41
    7:53
    3:16
    8:14
    8:26
    4

    Mastering Lazy Deletion

    8:47
    9:05
    9:30
    9:39
    10:01
    10:16
    10:35
    3:16
    11:00
    11:14
    11:37
    11:51
    5

    The Python Implementation Drill

    12:08
    12:21
    12:39
    12:46
    13:02
    13:05
    10:35
    13:39
    13:56
    13:58
    10:01
    3:16
    14:41
    14:47
    6

    Avoiding Common Pitfalls

    15:07
    15:22
    15:38
    16:00
    16:20
    16:32
    16:50
    3:16
    17:18
    17:32
    17:46
    7

    Real-World and Interview Context

    17:54
    18:07
    18:25
    18:36
    18:53
    19:09
    19:22
    19:31
    9:30
    20:12
    8

    Practical Playbook for the Assessment

    20:19
    20:30
    20:39
    20:49
    21:03
    21:15
    21:28
    21:40
    21:52
    22:04
    22:13
    22:22
    9

    Closing Reflection

    22:36
    22:55
    23:09
    23:26
    23:34
    23:41

    Contenuti simili

    Copertina del libro Optimizing Massive Cashflow Files
    Optimizing Massive Cashflow Files
    Clunky spreadsheets slow down every team. Learn how to use change summaries to audit automated cleanups and reduce file size without losing data integrity.
    15 min
    Copertina del libro Finding Bottlenecks With Data You Already Have
    The goalLean Six SigmaToyota Production SystemGemba kaizen
    20 sources
    Finding Bottlenecks With Data You Already Have
    Stop buying new sensors to find production delays. Learn how to use existing ERP data and the Drum-Buffer-Rope method to clear WIP and fix your workflow.
    28 min
    Copertina del libro Data Topology: Central vs. Edge Databases
    SQLite at the Edge: When libSQL Beats Postgres (2026) | TechPlainedDesigning your SaaS Database for Scale with Postgres — Citus Docs 8.2 documentationMulti-Tenant Architecture: Database Per Tenant vs Shared Schema — Pros and Cons (2026) - DEV CommunityThe Multi-Tenant SaaS Architecture Decision: Cost & Engineering Hours Across 4 Patterns | Appycodes
    5 sources
    Data Topology: Central vs. Edge Databases
    Struggling with global latency? Explore how shifting from central databases to per-account edge files can collapse read paths and improve performance.
    24 min
    Copertina del libro FIFO Queues: First In, First Out Explained
    System Design Interview – An Insider's GuideBuilding MicroservicesDesigning Data-Intensive ApplicationsClean Architecture
    23 sources
    FIFO Queues: First In, First Out Explained
    Miles and Nia explore FIFO queues, from basic first-come-first-served principles to advanced topics like message durability, scaling patterns, and choosing the right queue technology for your system.
    27 min
    Copertina del libro Mastering useMemo: Smart Caching Without the Overhead
    Optimal IllusionsWriting High-Performance .NET CodeHow to Pass ExamsTwo Scoops of Django
    24 sources
    Mastering useMemo: Smart Caching Without the Overhead
    Learn to optimize React apps by caching expensive calculations like large list filters. Discover why overusing useMemo backfires and get a 3-step checklist to decide when to memoize.
    20 min
    Copertina del libro Complejidad Algorítmica: El Coste Real de tu Código
    Google Drive PDF
    1 source
    Complejidad Algorítmica: El Coste Real de tu Código
    Descubre por qué un programa rápido no siempre es eficiente y aprende a medir el uso de tiempo y memoria para diseñar software de alto nivel.
    27 min
    Copertina del libro Lean Analytics
    Lean Analytics
    Alistair Croll and Benjamin Yoskovitz
    Guides startups to build and grow using data-driven analytics.
    10 min
    Copertina del libro Two Awesome Hours
    Two Awesome Hours
    Josh Davis
    Maximize productivity with science-based strategies to harness your best time and accomplish your most important work efficiently.
    10 min