SlideShare ist ein Scribd-Unternehmen logo
1 von 18
‫סיבוכיות‬
‫תירגול‬
1
‫הגדרה‬
:
‫פונקציה‬ ‫הוא‬ ‫אלגוריתם‬ ‫של‬ ‫הריצה‬ ‫זמן‬
‫כ‬
"
‫באורך‬ ‫קלט‬ ‫לכל‬ ‫ש‬
‫היותר‬ ‫לכל‬ ‫מבצע‬ ‫האלגוריתם‬
‫צעדים‬
‫הגדרות‬
:
‫יהיו‬
‫אזי‬
‫ש‬ ‫מתקיים‬
:
‫סיבוכיות‬ ‫פונקציות‬
1
‫תרגיל‬
:
‫הוכח‬
‫פתרון‬
:
‫נראה‬
1
)
2
)
1
)
‫עבור‬ ‫הנדרש‬ ‫ומתקיים‬
‫סיבוכיות‬ ‫פונקציות‬
2
2
)
‫עבור‬
‫מתקיים‬
‫לכן‬
‫עבור‬
:
‫ומתקיים‬
‫עבור‬ ‫הנדרש‬
‫סיבוכיות‬ ‫פונקציות‬
3
4
‫הגדרה‬
:
‫תוים‬ ‫ולכתוב‬ ‫לקרוא‬ ‫ניתן‬ ‫ממנו‬ ‫מסרט‬ ‫מורכבת‬ ‫טיורינג‬ ‫מכונת‬
,
‫קורא‬ ‫ראש‬
/
‫כותב‬
,
‫ומערכת‬
‫הסרט‬ ‫לפי‬ ‫שפועלת‬ ‫חישובית‬
.
‫פורמלית‬
,
‫טיורינג‬ ‫מכונת‬
‫שביעייה‬ ‫היא‬
:
‫א‬
"
‫השפה‬ ‫של‬ ‫ב‬
(
‫קלט‬
)
‫א‬
"
‫של‬ ‫ב‬
(
)
‫הפנימיים‬ ‫המצבים‬ ‫קבוצת‬
‫מעבר‬ ‫פונקציית‬
‫התחלתי‬ ‫מצב‬
‫מקבל‬ ‫מצב‬
‫דוחה‬ ‫מצב‬
‫טיורינג‬ ‫מכונות‬
‫תחילת‬
‫ריצה‬
:
‫סרט‬
‫ולאחריו‬ ‫הקלט‬ ‫את‬ ‫מכיל‬ ‫המכונה‬
‫ריקים‬ ‫תאים‬
.
‫הקורא‬ ‫הראש‬
/
‫נמצא‬ ‫כותב‬
‫הסרט‬ ‫בתחילת‬
.
‫המצב‬
‫המצב‬ ‫הוא‬ ‫הפנימי‬
‫ההתחלתי‬
.
‫מעבר‬
:
‫המצב‬ ‫ואת‬ ‫לראש‬ ‫מתחת‬ ‫שנמצא‬ ‫התו‬ ‫את‬ ‫כקלט‬ ‫מקבלת‬ ‫המעבר‬ ‫פונקציית‬
‫הנוכחי‬ ‫הפנימי‬
.
‫לראש‬ ‫מתחת‬ ‫שייכתב‬ ‫התו‬ ‫את‬ ‫כפלט‬ ‫מוציאה‬ ‫הפונקציה‬
,
‫את‬
‫החדש‬ ‫הפנימי‬ ‫המצב‬
,
‫הראש‬ ‫יזוז‬ ‫אליו‬ ‫הכיוון‬ ‫ואת‬
.
‫ריצה‬ ‫סיום‬
:
‫מקבל‬ ‫למצב‬ ‫מגיעה‬ ‫המכונה‬ ‫אם‬
,
‫ומקבלת‬ ‫עוצרת‬ ‫היא‬
.
‫אם‬
‫למצב‬ ‫מגיעה‬ ‫המכונה‬
‫דוחה‬
,
‫עוצרת‬ ‫היא‬
‫ודוחה‬
.
‫טיורינג‬ ‫מכונות‬
5
‫הגדרות‬
:
‫מ‬
"
‫ט‬
‫מכריעה‬
(
decides
)
‫שפה‬
‫אם‬
‫לכל‬
:
‫את‬ ‫מקבלת‬
.
‫את‬ ‫דוחה‬
.
‫מ‬
"
‫ט‬
‫מזהה‬
(
recognizes
)
‫שפה‬
‫אם‬
‫לכל‬
:
‫את‬ ‫מקבלת‬
.
‫את‬ ‫דוחה‬
‫עוצרת‬ ‫לא‬ ‫או‬
.
‫טיורינג‬ ‫מכונות‬
6
‫תרגיל‬
:
‫תהי‬
‫הפלינדרומים‬ ‫שפת‬
.
‫מ‬ ‫ליבנות‬ ‫צריך‬
"
‫את‬ ‫שמכריעה‬ ‫ט‬
.
‫פתרון‬
:
‫של‬ ‫פתרון‬ ‫נראה‬
‫מצבים‬ ‫מעבר‬ ‫ותרשים‬ ‫אלגוריתם‬
.
‫אלגוריתם‬
:
‫בסרט‬ ‫הראשון‬ ‫שבתא‬ ‫התו‬ ‫את‬ ‫וזכור‬ ‫קרא‬
,
‫אותו‬ ‫מחק‬ ‫ואז‬
.
‫ריק‬ ‫שאינו‬ ‫בסרט‬ ‫האחרון‬ ‫לתא‬ ‫הגעה‬ ‫עד‬ ‫הסרט‬ ‫על‬ ‫עבור‬
.
‫שזכרת‬ ‫מהתו‬ ‫שונה‬ ‫התו‬ ‫אם‬
,
‫דחה‬
.
‫אחרת‬
,
‫הנוכחי‬ ‫התא‬ ‫מחק‬
,
‫ריק‬ ‫שאינו‬ ‫בסרט‬ ‫הראשון‬ ‫לתא‬ ‫חזור‬
,
‫התהליך‬ ‫על‬ ‫וחזור‬
.
‫כזה‬ ‫ואין‬ ‫ריק‬ ‫לא‬ ‫תא‬ ‫מחפשים‬ ‫הריצה‬ ‫במהלך‬ ‫אם‬
(
‫בודד‬ ‫תו‬ ‫מכיל‬ ‫או‬ ‫ריק‬ ‫הסרט‬
)
,
‫קבל‬
.
‫ריצה‬ ‫זמן‬ ‫סיבוכיות‬
:
‫מקום‬ ‫סיבוכיות‬
:
‫טיורינג‬ ‫מכונות‬
7
‫מצבים‬ ‫מעבר‬ ‫תרשים‬
:
‫טיורינג‬ ‫מכונות‬
8
q0
q4
q1
q5
q2
q3
qrej
qacc
qrej
qcc
qacc
(
‫זוגי‬ ‫פלינדרום‬
)
(
‫אי‬ ‫פלינדרום‬
-
‫זוגי‬
) (
‫אי‬ ‫פלינדרום‬
-
‫זוגי‬
)
P
‫השפות‬ ‫מחלקת‬
‫ע‬ ‫להכרעה‬ ‫שניתנות‬
"
‫פולינומיאלי‬ ‫בזמן‬ ‫טיורינג‬ ‫מכונת‬ ‫י‬
.
‫ב‬ ‫לשפות‬ ‫דוגמאות‬
:
•
‫סופית‬ ‫שפה‬ ‫כל‬
•
‫הפלינדרומים‬ ‫שפת‬
•
‫קודקודים‬ ‫וזוג‬ ‫גרפים‬
‫כ‬
"
‫בין‬ ‫מסלול‬ ‫קיים‬ ‫ש‬
‫ל‬
.
•
‫בגודל‬ ‫קליקה‬ ‫בהם‬ ‫שקיימת‬ ‫גרפים‬
-
‫עבור‬
‫קבוע‬
.
‫סיבוכיות‬ ‫מחלקות‬
9
‫א‬ ‫חישוב‬
-
‫דטרמיניסטי‬
‫המוגדרת‬ ‫מעבר‬ ‫פונקציית‬ ‫יש‬ ‫דטרמיניסטית‬ ‫טיורינג‬ ‫למכונת‬
:
‫א‬ ‫טיורינג‬ ‫למכונת‬
-
‫המוגדרת‬ ‫מעבר‬ ‫פונקציית‬ ‫יש‬ ‫דטרמיניסטיות‬
:
‫סיבוכיות‬ ‫מחלקות‬
10
‫מ‬
"
‫ט‬
‫דטרמיניסטית‬
:
‫סיבוכיות‬ ‫מחלקות‬
11
…
1
1
1
0
1
0
0
1
…
1
1
1
1
1
0
0
1
q2
q4
‫מ‬
"
‫ט‬
‫א‬
-
‫דטרמיניסטית‬
:
‫סיבוכיות‬ ‫מחלקות‬
12
…
1
1
1
0
1
0
0
1
…
1
1
1
0
1
0
0
1
q2
q4
…
1
0
1
0
1
0
0
1
q3
…
1
0
1
0
1
0
0
1
…
1
0
1
0
1
0
0
1
…
1
0
1
0
1
0
0
1
…
1
0
1
0
1
0
0
1
NP
(
‫ע‬ ‫הגדרה‬
"
‫א‬ ‫חישוב‬ ‫י‬
-
‫דטרמיניסטי‬
)
‫השפות‬ ‫מחלקת‬
‫ע‬ ‫להכרעה‬ ‫שניתנות‬
"
‫טיורינג‬ ‫מכונת‬ ‫י‬
‫א‬
-
‫דטרמיניסטית‬
‫פולינומיאלי‬ ‫בזמן‬
.
‫א‬ ‫חישוב‬
-
‫אקראי‬ ‫חישוב‬ ‫לא‬ ‫הוא‬ ‫דטרמיניסטי‬
.
‫המכונה‬ ‫כאילו‬ ‫כך‬ ‫על‬ ‫לחשוב‬ ‫ניתן‬
"
‫מנחשת‬
"
‫את‬
‫האפשריים‬ ‫הצעדים‬ ‫מבין‬ ‫הנכון‬ ‫הצעד‬
.
‫הגדרה‬
:
‫מ‬
"
‫א‬ ‫ט‬
"
‫ד‬
‫מכריעה‬
‫שפה‬
‫אם‬
‫ו‬ ‫עוצרת‬ ‫היא‬ ‫לכל‬
:
‫מקבלת‬ ‫שבסופו‬ ‫חישוב‬ ‫מסלול‬ ‫קיים‬
‫את‬
.
‫סיבוכיות‬ ‫מחלקות‬
13
NP
(
‫ע‬ ‫הגדרה‬
"
‫מוודא‬ ‫עד‬ ‫י‬
)
‫השפות‬ ‫מחלקת‬
‫ע‬ ‫לוודא‬ ‫שניתן‬
"
‫פולינומיאלי‬ ‫בזמן‬ ‫דטרמיניסטית‬ ‫טיורינג‬ ‫מכונת‬ ‫י‬
.
‫מ‬
"
‫שפה‬ ‫מוודאת‬ ‫ט‬
‫אם‬
‫לכל‬
‫ו‬ ‫עוצרת‬ ‫היא‬
:
‫עד‬ ‫קיים‬
(
‫ב‬ ‫תלוי‬
)
‫כ‬
"
‫ש‬
‫מקבלת‬
.
‫סיבוכיות‬ ‫מחלקות‬
14
‫ב‬ ‫לשפות‬ ‫דוגמאות‬
:
•
‫ב‬ ‫שנמצאת‬ ‫שפה‬ ‫כל‬
.
•
‫המילטוני‬ ‫מעגל‬ ‫בהם‬ ‫שקיים‬ ‫גרפים‬
.
•
‫בגודל‬ ‫קליקה‬ ‫בהם‬ ‫שקיימת‬ ‫גרפים‬
-
‫גודל‬ ‫על‬ ‫הגבלה‬ ‫ללא‬
.
‫סיבוכיות‬ ‫מחלקות‬
15
‫משפט‬
:
‫שקולות‬ ‫ל‬ ‫שראינו‬ ‫ההגדרות‬ ‫שתי‬
‫פתרון‬
:
‫נראה‬
1
)
2
)
1
)
‫שקיימת‬ ‫נניח‬
‫קיים‬ ‫בשפה‬ ‫ולכל‬
‫ל‬
‫ההגדרה‬ ‫פי‬
,
‫את‬ ‫ונראה‬
:
‫א‬ ‫באופן‬ ‫בוחרת‬
"
‫מחרוזת‬ ‫ד‬
.
‫את‬ ‫מריצה‬
‫הקלט‬ ‫עם‬
,
‫אמ‬ ‫ומקבלת‬
"
‫קיבלה‬ ‫זו‬ ‫ריצה‬ ‫ם‬
.
‫נכונות‬
:
‫מקבלת‬
‫בריצת‬ ‫קיים‬
‫מקבל‬ ‫מסלול‬
‫קיים‬
‫כ‬
"
‫ש‬
‫מקבלת‬
‫סיבוכיות‬ ‫מחלקות‬
16
2
)
‫שקיימת‬ ‫נניח‬
‫את‬ ‫ונראה‬ ‫את‬ ‫שמכריעה‬
:
‫ע‬ ‫שמוכתב‬ ‫במסלול‬ ‫על‬ ‫את‬ ‫מריצה‬
"
‫י‬
,
‫אמ‬ ‫ומקבלת‬
"
‫זו‬ ‫ריצה‬ ‫ם‬
‫קיבלה‬
.
‫נכונות‬
:
‫כ‬ ‫קיים‬
"
‫ש‬
‫מקבלת‬
‫בריצת‬ ‫קיים‬
‫מקבל‬ ‫מסלול‬
‫סיבוכיות‬ ‫מחלקות‬
17

Weitere ähnliche Inhalte

Empfohlen

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
 

Empfohlen (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
 

Recitation01.pptx