Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

This Algorithm is 1,606,240% FASTER

597.5K views
•
January 6, 2023
by
ThePrimeagen
YouTube video player
This Algorithm is 1,606,240% FASTER

TL;DR

Improve algorithm running time by implementing optimization techniques, such as using vectors instead of hash sets and bit manipulation, resulting in significant speed improvements.

Transcript

1.6 million percent faster it's hard to even display visually because it shows up as nothing today I'm going to show you the seven steps taken to improve the running time of an algorithm but here's the kicker the slowest one was O of N and the fastest one is still o of N and along the way I'm going to use common optimization techniques that you can... Read More

Key Insights

  • ⌛ Optimization techniques, such as inserting characters one at a time and using vectors instead of hash sets, can significantly improve algorithm running time.
  • 🫦 Bit manipulation, specifically XOR operations, can be utilized to efficiently store and check the state of a search.
  • 🐎 Unrolling loops and utilizing SIMD optimization can further enhance the speed of an algorithm.
  • 🐎 The final optimized solution, with multi-threading and advanced optimization techniques, can achieve a speed improvement of over 16,000 times compared to the initial solution.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What is the initial approach to solving the problem of finding 14 distinct characters in a string?

The initial approach involves using a hash set to store the first 14 characters from the string and checking the length of the hash set to determine if 14 distinct characters have been found.

Q: What is the first optimization technique that improves the running time of the algorithm?

The first optimization is to insert characters one at a time and stop the process if a duplicate is detected. This simple if statement results in a 92% faster runtime.

Q: How does using a vector instead of a hash set improve the running time further?

While hash set lookup is constant time, it involves computing a hash, index calculation, and potentially checking for collisions. Using a vector, which requires a simple reference follow and offset calculation, results in a significantly faster runtime.

Q: How does the final optimization technique, involving bit manipulation, achieve a speed improvement?

By using a singular 32-bit number to represent the state of the search, the algorithm can use bit manipulation, specifically the XOR operation, to toggle bits and check for duplicate characters. This technique, combined with other optimizations, leads to a runtime improvement of over 233 times compared to the initial hash set solution.

Key Insights:

  • Optimization techniques, such as inserting characters one at a time and using vectors instead of hash sets, can significantly improve algorithm running time.
  • Bit manipulation, specifically XOR operations, can be utilized to efficiently store and check the state of a search.
  • Unrolling loops and utilizing SIMD optimization can further enhance the speed of an algorithm.
  • The final optimized solution, with multi-threading and advanced optimization techniques, can achieve a speed improvement of over 16,000 times compared to the initial solution.
  • These optimization techniques can be applied to various algorithms and improve the efficiency of computational processes.

Summary & Key Takeaways

  • The content discusses the process of improving the running time of an algorithm by implementing various optimization techniques.

  • The problem used in the example is finding 14 distinct characters in a long string, and the initial solution involves using a hash set.

  • Through a series of optimizations, including using vectors instead of hash sets and bit manipulation, the algorithm's running time is significantly improved.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from ThePrimeagen 📚

I was wrong btw thumbnail
I was wrong btw
ThePrimeagen
Maintaining Motivation as a Software Engineer thumbnail
Maintaining Motivation as a Software Engineer
ThePrimeagen
Why Becoming a Great Programmer Takes Time thumbnail
Why Becoming a Great Programmer Takes Time
ThePrimeagen
Will ChatGPT Terminate Your Job? thumbnail
Will ChatGPT Terminate Your Job?
ThePrimeagen
Vim As Your Editor - Introduction thumbnail
Vim As Your Editor - Introduction
ThePrimeagen

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.