📘
Grokking-Algorithms book
PostgreSQL
  • Content
  • Introduction to Algorithms
    • Introduction
    • Binary Search
    • Big O notation
    • Recap
  • Selection sort
    • How memory works
    • Arrays and linked lists
    • Selection sort
    • Recap
  • Recursion
    • Recursion
    • Base case and recursive case
    • The stack
    • Recap
  • Quicksort
    • Divide & conquer
    • Quicksort
    • Big O notation revisited
    • Recap
  • Hash tables
    • Hash functions
    • Use cases
    • Collisions
    • Performance
    • Recap
  • Breadth-first search
    • Introduction to graph
    • What is a graph
    • Breadth-first search
    • Implementing the graph
    • Implementing the algorithm
    • Recap
  • Dijkstra's algorithm
    • Working with Dijkstra's algorithm
    • Terminology
    • Trading for a piano
    • Negative-weight edges
    • Implementation
    • Recap
  • Greedy Algorithms
    • The classroom scheduling problem
    • The knapsack problem
    • The set-covering problem
    • NP-complete problems
    • Traveling salesperson, step by step
    • Recap
  • Dynamic programming
    • The knapsack problem
    • Knapsack problem FAQ
    • Longest common substring
    • Recap
  • K-nearest neighbors
    • Classifying oranges vs. grapefruit
    • Building a recommendations system
    • Introduction to machine learning
    • Recap
  • Where to go next
    • Trees
    • Inverted indexes
    • The Fourier transform
    • Parallel algorithms
    • MapReduce
    • Bloom filters and HyperLogLog
    • The SHA algorithms
    • Locality-sensitive hashing
    • Diffie-Hellman key exchange
    • Linear programming
    • Epilogue
  • Answers to exercises
    • Chapter 1
    • Chapter 2
    • Chapter 3
    • Chapter 4
    • Chapter 5
    • Chapter 6
    • Chapter 7
    • Chapter 8
    • Chapter 9
    • Chapter 10
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Greedy Algorithms

The classroom scheduling problem

PreviousGreedy AlgorithmsNextThe knapsack problem

Last updated 1 year ago

Was this helpful?

Aytaylik, sizning sinfingiz bor va bu yerda imkon qadar ko'proq dars o'tkazmoqchisiz. Siz darslar ro'yxatini olasiz.

Siz bu sinflarning barchasini u erda ushlab turolmaysiz, chunki ularning ba'zilari bir-biriga mos keladi.

Siz ushbu sinfda imkon qadar ko'proq dars o'tkazmoqchisiz. Mumkin bo'lgan eng katta darslar to'plamiga ega bo'lish uchun qanday darslar to'plamini o'tkazishni qanday tanlaysiz?

Bu qiyin muammoga o'xshaydi, to'g'rimi? Aslida, algoritm juda oson, u sizni hayratda qoldirishi mumkin. Bu qanday ishlaydi:

  1. Eng tez tugaydigan sinfni tanlang. Bu siz ushbu sinfda o'tadigan birinchi darsdir.

  2. Endi siz birinchi darsdan keyin boshlanadigan sinfni tanlashingiz kerak. Shunga qaramay, eng tez tugaydigan sinfni tanlang. Bu siz o'tadigan ikkinchi sinf.

Buni qilishda davom eting va siz javob olasiz! Keling, sinab ko'raylik. San'at tezroq, soat 10:00 da tugaydi, shuning uchun siz tanlagan darslardan biri.

Endi sizga soat 10:00 dan keyin boshlanadigan va tezroq tugaydigan keyingi dars kerak.

Ingliz tili o'chirildi, chunki u San'atga zid keladi, lekin matematika ishlaydi. Nihoyat, CS Matematikaga zid keladi, lekin Musiqa ishlaydi.

Shunday qilib, siz ushbu sinfda o'tadigan uchta sinfdir.

Ko'pchilik menga bu algoritm oson ko'rinishini aytadi. Bu juda aniq, shuning uchun noto'g'ri bo'lishi kerak. Ammo bu ochko'z algoritmlarning go'zalligi: ular oson! Ochko'zlik algoritmi oddiy: har bir qadamda optimal harakatni tanlang. Bunday holda, har safar sinfni tanlaganingizda, eng tez tugaydigan sinfni tanlaysiz. Texnik nuqtai nazardan: har bir qadamda siz mahalliy optimal yechimni tanlaysiz va oxir-oqibat global miqyosda optimal yechim bilan qolasiz. Ishoning yoki ishonmang, bu oddiy algoritm ushbu rejalashtirish muammosiga optimal yechim topadi!

Shubhasiz, ochko'z algoritmlar har doim ham ishlamaydi. Lekin ularni yozish oson! Keling, boshqa misolni ko'rib chiqaylik.

lessons
image
image
image
image
image