📘
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. Breadth-first search

Introduction to graph

PreviousBreadth-first searchNextWhat is a graph

Last updated 1 year ago

Was this helpful?

Aytaylik, siz San-Frantsiskodasiz va siz Twin Peaksdan Oltin darvoza ko'prigigacha borishni xohlaysiz. Siz u erga avtobusda, eng kam o'tkazmalar soni bilan borishni xohlaysiz. Mana sizning variantlaringiz.

Eng kam qadamlar bilan yo'lni topish algoritmingiz qanday?

Xo'sh, u erga bir qadamda bora olasizmi? Bu yerda siz bir qadamda borishingiz mumkin bo'lgan barcha joylar.

Ko'prik ta'kidlanmagan; u erga bir qadamda etib bo'lmaydi. Ikki qadamda u erga bora olasizmi?

Shunga qaramay, ko'prik yo'q, shuning uchun siz ikki qadamda ko'prikka borolmaysiz. Uch qadam haqida nima deyish mumkin?

Aha! Endi Oltin darvoza ko'prigi paydo bo'ladi. Shunday qilib, bu marshrut yordamida Twin Peaksdan ko'prikka borish uchun uch qadam kerak.

Sizni ko'prikka olib boradigan boshqa yo'llar ham bor, lekin ular uzoqroq (to'rt qadam). Algoritm ko'prikka eng qisqa yo'l uch qadam uzunligini aniqladi. Ushbu turdagi muammo eng qisqa yo'l muammosi deb ataladi. Siz har doim eng qisqa narsani topishga harakat qilasiz. Bu do'stingizning uyiga boradigan eng qisqa yo'l bo'lishi mumkin. Bu shaxmat o'yinida mat qilish uchun eng kichik harakatlar soni bo'lishi mumkin. Eng qisqa yo'l muammosini hal qilish algoritmi kenglikdan birinchi qidirish deb ataladi.

Egizak cho'qqilardan Oltin darvoza ko'prigiga qanday borishni aniqlash uchun ikkita qadam mavjud:

  1. Masalani grafik sifatida modellashtiring.

  2. Kenglik-birinchi qidiruv yordamida muammoni hal qiling.

Keyinchalik men qanday grafiklar ekanligini ko'rib chiqaman. Keyin men kengroq qidiruvga batafsilroq kirishaman.

bridge
options
fewest steps
fewest steps
fewest steps
steps