📘
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

Recursion

Siz rekursiya haqida bilib olasiz. Rekursiya ko'plab algoritmlarda qo'llaniladigan kodlash usulidir. Bu ushbu kitobning keyingi boblarini tushunish uchun qurilish bloki.

Siz muammoni asosiy va rekursiv holatga ajratishni o'rganasiz. Bo'l va zabt et strategiyasi (4-bob) qiyin muammolarni hal qilish uchun ushbu oddiy tushunchadan foydalanadi.

Men bu bobdan hayajondaman, chunki u muammolarni hal qilishning nafis usuli bo'lgan rekursiyani o'z ichiga oladi. Rekursiya mening eng sevimli mavzularimdan biri, lekin u ikkiga bo'linadi. Odamlar uni yaxshi ko'radilar yoki undan nafratlanadilar yoki bir necha yil o'tgach, uni sevishni o'rganmaguncha nafratlanadilar. Shaxsan men uchinchi lagerda edim. Ishlaringizni osonlashtirish uchun men bir nechta maslahat beraman:

  • Ushbu bobda juda ko'p kodli misollar mavjud. Qanday ishlashini ko'rish uchun kodni o'zingiz uchun ishlating.

  • Men rekursiv funktsiyalar haqida gapiraman. Hech bo'lmaganda bir marta qog'oz va qalam yordamida rekursiv funktsiyadan o'ting: "Keling, men 5 ni faktorialga o'tkazaman, keyin esa 5 marta 4 ni faktorialga qaytaraman, ya'ni ..." va hokazo. Bu kabi funktsiya bo'ylab yurish sizga rekursiv funktsiya qanday ishlashini o'rgatadi.

Ushbu bobda ko'plab psevdokodlar ham mavjud. Pseudocode -- bu kodda hal qilmoqchi bo'lgan muammoning yuqori darajadagi tavsifi. Bu kod kabi yozilgan, lekin u inson nutqiga yaqinroq bo'lishi uchun mo'ljallangan

PreviousRecapNextRecursion

Last updated 1 year ago

Was this helpful?

Page cover image