Find All Factors of a Number in O(√n) | Stop Using O(n) Brute Force!
Автор: From Brute To Best
Загружено: 2026-03-06
Просмотров: 1
Описание:
Want to find all factors of a number efficiently?
Most beginners check from 1 to n — which takes O(n) time.
But did you know you only need to check till √n?
In this video, we break down:
Brute force approach to find factors (O(n))
Why factors always come in pairs
The key observation behind square root optimization
Optimized O(√n) solution in Java
How to avoid duplicate factors for perfect squares
Time complexity comparison
We’ll walk through a clear example (36) and then implement both brute force and optimized solutions step by step.
This concept is extremely important for:
Prime number checking
Competitive programming
Coding interviews
Number theory basics
DSA beginners
By the end of this video, you’ll clearly understand WHY we check till √n — not just memorize it.
📌 Java Code Covered:
Brute force factor finding
Optimized √n solution
Sorted factor output version
Timestamps:
00:00 Introduction
00:06 The Problem
04:31 Brute Force Approach
05:56 The Problem of O(n) Complexity
10:07 Finding The Pattern
20:15 Optimized Solution Implementation
26:55 End
If you're learning Data Structures & Algorithms from scratch, this series will help you build strong fundamentals.
Subscribe and continue with:
Recursion
Josephus Problem
Bit manipulation
XOR tricks
Mathematical optimizations
#DSA #Java #CodingInterview #NumberTheory #CompetitiveProgramming #LearnToCode #SquareRootOptimization #Programming #FromBruteToBest
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: