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ù

    Master Math & Fast Calculation Tricks

    Master Math & Fast Calculation Tricks

    PIANO DI APPRENDIMENTO

    Master Math & Fast Calculation Tricks

    In a world driven by data, the ability to process numbers quickly and accurately is a vital competitive advantage. This plan is designed for students, professionals, and lifelong learners who want to eliminate math anxiety and master the art of rapid mental calculation.

    2 h 19 m•4 Sezioni
    To read faster in a time limit of 10 minutes

    To read faster in a time limit of 10 minutes

    PIANO DI APPRENDIMENTO

    To read faster in a time limit of 10 minutes

    In an age of information overload, the ability to process text quickly is a vital competitive advantage for professionals and students alike. This plan is designed for anyone looking to save hours of study or work time by mastering the mechanics of rapid comprehension and memory retention.

    2 h 57 m•4 Sezioni
    Data structures and algorithms

    Data structures and algorithms

    PIANO DI APPRENDIMENTO

    Data structures and algorithms

    Data structures and algorithms form the foundation of efficient software development and are essential for technical interviews at top tech companies. This learning plan benefits software engineers, computer science students, and anyone looking to write more optimized code or prepare for technical interviews.

    2 h 13 m•3 Sezioni
    Boost Productivity, ML, DS & Data Analysis

    Boost Productivity, ML, DS & Data Analysis

    PIANO DI APPRENDIMENTO

    Boost Productivity, ML, DS & Data Analysis

    This comprehensive track is designed for professionals who want to pair elite time management with advanced technical expertise in data science. It is ideal for aspiring data scientists and engineers looking to master the full stack of AI development while maintaining peak cognitive performance.

    3 h 34 m•4 Sezioni
    Rank newsjack content for SEO & social shares

    Rank newsjack content for SEO & social shares

    PIANO DI APPRENDIMENTO

    Rank newsjack content for SEO & social shares

    In an era of rapid information cycles, the ability to capitalize on real-time trends is a critical competitive advantage. This plan is designed for marketers, journalists, and creators who want to blend technical SEO with the viral science of newsjacking to dominate search rankings and social feeds.

    2 h 43 m•4 Sezioni
    Speed read with comprehension

    Speed read with comprehension

    PIANO DI APPRENDIMENTO

    Speed read with comprehension

    In our information-saturated world, the ability to process content quickly without sacrificing understanding is a competitive advantage. This learning plan is ideal for students, professionals, and lifelong learners who need to absorb large volumes of material efficiently—whether for academic success, career advancement, or personal enrichment.

    1 h 58 m•4 Sezioni
    如何高效率瘦下来

    如何高效率瘦下来

    PIANO DI APPRENDIMENTO

    如何高效率瘦下来

    在信息碎片化时代,许多人受困于无效的极端减肥法。本课程通过整合营养学、运动科学与行为心理学,专为追求高效、科学减重的忙碌人士设计,帮助你从根源上重塑体质并防止反弹。

    2 h 49 m•4 Sezioni
    Excel as a Med Student & Future Doctor 💊🏥

    Excel as a Med Student & Future Doctor 💊🏥

    PIANO DI APPRENDIMENTO

    Excel as a Med Student & Future Doctor 💊🏥

    In an increasingly data-driven healthcare landscape, traditional medical training often overlooks technical proficiency. This plan bridges that gap, empowering medical students and residents to master data analytics and automation for better clinical outcomes.

    4 h 5 m•5 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 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 React State Mistakes: Stop Storing Derived Data
    Developing Backbone.js ApplicationsTwo Scoops of DjangoRefactoringClean Code
    25 sources
    React State Mistakes: Stop Storing Derived Data
    Managing filtered lists in state often leads to bugs and extra renders. Learn why calculating values on the fly keeps your UI in sync and your code clean.
    22 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 Writing High-Performance .NET Code
    Writing High-Performance .NET Code
    Ben Watson
    Optimize .NET code like Microsoft's Bing engineers do.
    9 min