SlideShare uma empresa Scribd logo
1 de 19
ҰЛТТЫҚ ҚАУІПСІЗДІК КОМИТЕТІ
2022
КП-109
МУРАТБЕКОВ Ж.
Қарапайым сөзбен айтқанда, графты айналып өту-бұл
шыңдардың байланыс қасиеттерін іздеуде оның бір
шыңынан екіншісіне өту. Байланыстар (шыңдарды
байланыстыратын сызықтар) графтың бағыттары,
жолдары, беттері немесе шеттері деп аталады. Графтың
шыңдары түйіндер деп те аталады.
Графты айналып өту дегеніміз не?
Екі алгоритм де графты айналып өту
үшін қолданылғанымен, олардың кейбір
айырмашылықтары бар.
Графты айналып өтудің екі негізгі алгоритмі-
тереңдікті іздеу (Depth-First Search, DFS) және ені
бойынша іздеу (Breadth-First Search, BFS).
DFS "тереңірек сүңгу, алға бас" тұжырымдамасын
ұстанады ("go deep, head first"). Басты иедясы мынада:
біз бастапқы шыңнан (нүктеден, орыннан) белгілі бір
бағытта (белгілі бір жолмен) жолдың соңына немесе
межелі жерге (қалаған шыңға) жеткенше қозғаламыз.
Егер біз жолдың соңына жеткен болсақ, бірақ ол
баратын жер болмаса, онда біз артқа (жолдардың
тармақталу немесе алшақтық нүктесіне) оралып, басқа
жолмен жүреміз.
Мысалды қарастырайық. Бізде келесідей
бағдарланған граф бар делік:
Біз "s" нүктесіндеміз және "t"шыңын табуымыз керек. DFS
қолдану арқылы біз мүмкін жолдардың бірін зерттейміз, оны
соңына дейін жылжытамыз және егер t анықталмаса, қайтып
ораламыз және басқа жолды зерттейміз. Процесс осылай көрінеді:
Мұнда біз (p1) ең жақын шыңға қарай жүреміз және бұл жолдың
соңы емес екенін көреміз. Сондықтан біз келесі шыңға көшеміз.
Мы достигли конца p1, но не нашли t, поэтому возвращаемся в s и
двигаемся по второму пути.
"P2" жолының ең жақын "s" шыңына жеткенде, біз одан әрі
қозғалудың үш мүмкін бағытын көреміз. Біз бірінші бағытта
тупикка барғандықтан, біз екінші бағытта қозғаламыз.
Біз қайтадан жолдың соңына жеттік, бірақ t таппадық,
сондықтан біз қайтып келеміз. Біз үшінші жолмен жүреміз
және соңында қажетті "t"шыңына жетеміз.
DFS осылай жұмыс істейді. Соңына дейін белгілі бір
жолмен жүреміз. Егер жолдың соңы сіз іздеген шың болса,
біз аяқтаймыз. Егер жоқ болса, біз барлық нұсқаларды
зерттегенше артқа оралып, басқа жолмен жүреміз.Біз бұл
алгоритмді әр шыңға қатысты қолданамыз.Процедураны
бірнеше рет қайталау қажеттілігі алгоритмді жүзеге асыру
үшін рекурсияны қолдану қажеттілігін көрсетеді.
BFS "құстардың биіктігіне көтерілу арқылы кеңею"
тұжырымдамасын ұстанады ("go wide, bird ' s eye-view"). Соңына
дейін белгілі бір жолмен жүрудің орнына, BFS бір уақытта бір
көршімен алға жылжуды қамтиды. Бұл мынаны білдіреді:
Жол бойында жүрудің орнына, BFS бір әрекетте (қадамда) s-ге
жақын көршілерге баруды, содан кейін көршілердің
көршілеріне баруды және т анықталғанға дейін баруды
білдіреді.
Келесі сұрақ туындайды: алдымен қандай көршілерге бару
керектігін қалай білуге болады?Ол үшін біз "бірінші кіру,
бірінші шығу" (first-in-first-out, FIFO) тұжырымдамасын
кезектен (queue) пайдалана аламыз. Біз алдымен бізге ең
жақын шыңды, содан кейін оның келмеген көршілерін
кезекке қоямыз және бұл процесті кезек бос болғанша
немесе біз іздеген шыңды тапқанша жалғастырамыз.
Тереңдікті іздеу және ені бойынша іздеу графты айналып
өту үшін қолданылады.DFS алға-артқа жылжиды, ал BFS
мақсатты іздеу үшін көршілеріне таралады.DFS стекті, ал
BFS кезекті пайдаланады.Екеуінің де жұмыс уақыты O(V +
E), ал кеңістіктік күрделілік O(V).Бұл алгоритмдердің
философиясы әртүрлі, бірақ графтармен жұмыс істеу үшін
бірдей маңызды.
Қорытынды
Назарларыңызға рахмет!!!
Граф.pptx
Граф.pptx
Граф.pptx

Mais conteúdo relacionado

Destaque

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Destaque (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Граф.pptx

  • 2. Қарапайым сөзбен айтқанда, графты айналып өту-бұл шыңдардың байланыс қасиеттерін іздеуде оның бір шыңынан екіншісіне өту. Байланыстар (шыңдарды байланыстыратын сызықтар) графтың бағыттары, жолдары, беттері немесе шеттері деп аталады. Графтың шыңдары түйіндер деп те аталады. Графты айналып өту дегеніміз не?
  • 3. Екі алгоритм де графты айналып өту үшін қолданылғанымен, олардың кейбір айырмашылықтары бар. Графты айналып өтудің екі негізгі алгоритмі- тереңдікті іздеу (Depth-First Search, DFS) және ені бойынша іздеу (Breadth-First Search, BFS).
  • 4. DFS "тереңірек сүңгу, алға бас" тұжырымдамасын ұстанады ("go deep, head first"). Басты иедясы мынада: біз бастапқы шыңнан (нүктеден, орыннан) белгілі бір бағытта (белгілі бір жолмен) жолдың соңына немесе межелі жерге (қалаған шыңға) жеткенше қозғаламыз. Егер біз жолдың соңына жеткен болсақ, бірақ ол баратын жер болмаса, онда біз артқа (жолдардың тармақталу немесе алшақтық нүктесіне) оралып, басқа жолмен жүреміз.
  • 5. Мысалды қарастырайық. Бізде келесідей бағдарланған граф бар делік:
  • 6. Біз "s" нүктесіндеміз және "t"шыңын табуымыз керек. DFS қолдану арқылы біз мүмкін жолдардың бірін зерттейміз, оны соңына дейін жылжытамыз және егер t анықталмаса, қайтып ораламыз және басқа жолды зерттейміз. Процесс осылай көрінеді:
  • 7. Мұнда біз (p1) ең жақын шыңға қарай жүреміз және бұл жолдың соңы емес екенін көреміз. Сондықтан біз келесі шыңға көшеміз. Мы достигли конца p1, но не нашли t, поэтому возвращаемся в s и двигаемся по второму пути.
  • 8. "P2" жолының ең жақын "s" шыңына жеткенде, біз одан әрі қозғалудың үш мүмкін бағытын көреміз. Біз бірінші бағытта тупикка барғандықтан, біз екінші бағытта қозғаламыз.
  • 9. Біз қайтадан жолдың соңына жеттік, бірақ t таппадық, сондықтан біз қайтып келеміз. Біз үшінші жолмен жүреміз және соңында қажетті "t"шыңына жетеміз.
  • 10. DFS осылай жұмыс істейді. Соңына дейін белгілі бір жолмен жүреміз. Егер жолдың соңы сіз іздеген шың болса, біз аяқтаймыз. Егер жоқ болса, біз барлық нұсқаларды зерттегенше артқа оралып, басқа жолмен жүреміз.Біз бұл алгоритмді әр шыңға қатысты қолданамыз.Процедураны бірнеше рет қайталау қажеттілігі алгоритмді жүзеге асыру үшін рекурсияны қолдану қажеттілігін көрсетеді.
  • 11. BFS "құстардың биіктігіне көтерілу арқылы кеңею" тұжырымдамасын ұстанады ("go wide, bird ' s eye-view"). Соңына дейін белгілі бір жолмен жүрудің орнына, BFS бір уақытта бір көршімен алға жылжуды қамтиды. Бұл мынаны білдіреді:
  • 12. Жол бойында жүрудің орнына, BFS бір әрекетте (қадамда) s-ге жақын көршілерге баруды, содан кейін көршілердің көршілеріне баруды және т анықталғанға дейін баруды білдіреді.
  • 13.
  • 14. Келесі сұрақ туындайды: алдымен қандай көршілерге бару керектігін қалай білуге болады?Ол үшін біз "бірінші кіру, бірінші шығу" (first-in-first-out, FIFO) тұжырымдамасын кезектен (queue) пайдалана аламыз. Біз алдымен бізге ең жақын шыңды, содан кейін оның келмеген көршілерін кезекке қоямыз және бұл процесті кезек бос болғанша немесе біз іздеген шыңды тапқанша жалғастырамыз.
  • 15. Тереңдікті іздеу және ені бойынша іздеу графты айналып өту үшін қолданылады.DFS алға-артқа жылжиды, ал BFS мақсатты іздеу үшін көршілеріне таралады.DFS стекті, ал BFS кезекті пайдаланады.Екеуінің де жұмыс уақыты O(V + E), ал кеңістіктік күрделілік O(V).Бұл алгоритмдердің философиясы әртүрлі, бірақ графтармен жұмыс істеу үшін бірдей маңызды. Қорытынды