SlideShare a Scribd company logo
1 of 8
Sqrt-დეკომპოზიცია წარმოადგენს მეთოდს ან მონაცემთა
სტრუქტურას, რომელიც საშუალებას გვაძლევს
ზოგიერთი ტიპიური ოპერაცია (ელემენტების ჯამი
ინტერვალზე, მაქსიმუმის ან მინიმუმის პოვნა
ინტერვალზე და ა.შ) შევასრულოთ O( 𝑁) დროში, რაც
გაცილებით სწრაფია, ვიდრე ტრივიალური O(N).
ამოცანა შეგვიძლია ასე ჩამოვაყალიბოთ: მოცემულია N
ელემენტისაგან შედგენილი მასივი A[n]. ნებისმიერი L და
R ინდექსებისათვის ვიპოვოთ A[L..R] ინტერვალში
შემავალი ელემენტების ჯამი O( 𝑁) დროში.
Sqrt-დეკომპოზიციის ძირითად იდეას წარმოადგენს შემდეგი სახის
პრეკალკულაცია (წინასწარი გამოთვლა): დავყოთ მოცემული მასივი
𝑁 სიგრძის ბლოკებად და თითოეული ბლოკისათვის წინასწარ
დავთვალოთ მასში შემავალი ელემენტების ჯამი. i-ური ბლოკის
ჯამი შევინახოთ B(i) ელემენტში. ცხადია, რომ ბლოკების რაოდენობა
და ბლოკების სიგრძე ერთმანეთს დაემთხვევა და ის ტოლი იქნება
𝑁-ის მნიშვნელობისა, რომელიც მეტობით იქნება დამრგვალებული.
ვთქვათ, K= 𝑁 , მაშინ A მასივი ბლოკებად დაიყოფა შემდეგნაირად:
𝐴 0 ,𝐴 1 …𝐴[𝐾−1] 𝐴 𝐾 ,𝐴 𝐾+1 …𝐴[2∗𝐾−1]
…
𝐴 𝑘−1 ∗𝑘 …𝐴[𝑁]
B[0] B[1] B[K-1]
უკანასკნელ ბლოკში შეიძლება იყოს K-ზე ნაკლები ელემენტი,
მაგრამ ეს სტრუქტურის მუშაობაზე არავითარ გავლენას არ
ახდენს.
ავაგოთ SQRT დეკომპოზიცია N=23 ელემენტისაგან შედგენილი მასივისათვის.
K ამ სიტუაციაში იქნება 5-ის ტოლი.
ვთქვათ, მოთხოვნილია ელემენტთა ჯამის პოვნა [3,17] ინტერვალზე. მე-3
და მე-4 ელემენტების, ასევე მე-15, მე-16 და მე-17 ელემენტების ჯამს
ვიპოვით A მასივიდან ორი ცალ-ცალკე ციკლით, ხოლო [5,9] და [10,14]
ინტერვალების ჯამს B მასივიდან ავიღებთ: B[1]+B[2] .
6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7
22
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
20
1
24
2
27
3
14
4
A
B
6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7
22
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
20
1
24
2
27
3
14
4
A
B
მოხდება მხოლოდ ორი ცვლილება
6 3 8 1 4 2 4 7 9 5 3 4 5 9 3 1 6 9 6 5 4 3 7
22
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
27
1
24
2
27
3
14
4
A
B
ვთქვათ, მასივის მე-8 ინდექსზე მყოფი ელემენტი 2 შეცვალეს და მისი
ახალი მნიშვნელობაა 9, ეს გამოიწვევს მხოლოდ ორ ცვლილებას:
გახორციელდება მინიჭება A[8]=9 და ახალი და ძველი მნიშნელობების
სხვაობა დაემატება B მასივის შესაბამის ელემენტს. B[1]=20+(9-2)=27.
6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7
8
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
7
1
9
2
9
3
7
4
A
B
ვთქვათ, მოთხოვნილია მაქსიმალური ელემენტის პოვნა [2,12] ინტერვალზე.
ერთი ციკლით ვიპოვით მაქსიმუმს მე-2, მე-3 და მე-4 ელემენტებს შორის,
შემდეგ ავიღებთ გამზადებულ პასუხს B მასივიდან [5,9] ინტერვალისათვის
და კიდევ ერთი ციკლი დაგვჭირდება ასევე მე-10, მე-11 და მე-12 ელემენტებს
შორის მაქსიმუმის საპოვნელად. საბოლოოდ, მაქსიმუმის არჩევა მოგვიწევს
სამ რიცხვს შორის max(8,7,5)=8.
მაქსიმუმებისათვის მონაცემთა განახლების დროს განსახილველია სამი
შემთხვევა: ა) როცა ახალი მონაცემი არ აღემატება საკუთარი შუალედის
მაქსიმუმს. ამ შემთხვევაში იცვლება მხოლოდ ელემენტი A მასივში. ბ) ახალი
მონაცემი მეტია აქამდე არსებულ მაქსიმუმზე. მაშინ იცვლება ელემენტი A
მასივში და იგივე მონაცემი ჩაიწერება B-ს შესაბამის ინდექსზეც (ანუ
განახლდება). გ) როცა ახალი მონაცემი ძველ მაქსიმუმს ცვლის უფრო მცირე
მნიშვნელობით. ამ შემთხვევაში საჭიროა ციკლით გადავყვეთ A მასივის
შესაბამის უბანს და მისი მაქსიმუმი ხელახლა ვიპოვოთ.
6 3 8 1 4 2 4 7 2 5 3 4 5 2 3 1 6 9 6 5 4 3 7
8
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
7
1
5
2
9
3
7
4
A
B
ჯამის, მინიმუმის ან მაქსიმუმის პოვნისას SQRT დეკომპოზიცია უარეს
შემთხვევაში 3∗ 𝑁 ოპერაციას გააკეთებს, რადგან საწყის და საბოლოო
უბნებზე მას შეიძლება მაქსიმუმ 𝑁-1 ოპერაციის გაკეთება დასჭირდეს,
ხოლო დანარჩენი უბნების რაოდენობა, ცხადია, რომ 𝑁-ს არ აღემატება.
მონაცემთა განახლებისას ჯამების დროს O(1) ოპერაცია ჰყოფნის, ხოლო
მინიმუმის და მაქსიმუმის პოვნისას O( 𝑁).

More Related Content

Featured

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
 

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

SQRT_decompozition algorithm computer sc

  • 1.
  • 2. Sqrt-დეკომპოზიცია წარმოადგენს მეთოდს ან მონაცემთა სტრუქტურას, რომელიც საშუალებას გვაძლევს ზოგიერთი ტიპიური ოპერაცია (ელემენტების ჯამი ინტერვალზე, მაქსიმუმის ან მინიმუმის პოვნა ინტერვალზე და ა.შ) შევასრულოთ O( 𝑁) დროში, რაც გაცილებით სწრაფია, ვიდრე ტრივიალური O(N). ამოცანა შეგვიძლია ასე ჩამოვაყალიბოთ: მოცემულია N ელემენტისაგან შედგენილი მასივი A[n]. ნებისმიერი L და R ინდექსებისათვის ვიპოვოთ A[L..R] ინტერვალში შემავალი ელემენტების ჯამი O( 𝑁) დროში.
  • 3. Sqrt-დეკომპოზიციის ძირითად იდეას წარმოადგენს შემდეგი სახის პრეკალკულაცია (წინასწარი გამოთვლა): დავყოთ მოცემული მასივი 𝑁 სიგრძის ბლოკებად და თითოეული ბლოკისათვის წინასწარ დავთვალოთ მასში შემავალი ელემენტების ჯამი. i-ური ბლოკის ჯამი შევინახოთ B(i) ელემენტში. ცხადია, რომ ბლოკების რაოდენობა და ბლოკების სიგრძე ერთმანეთს დაემთხვევა და ის ტოლი იქნება 𝑁-ის მნიშვნელობისა, რომელიც მეტობით იქნება დამრგვალებული. ვთქვათ, K= 𝑁 , მაშინ A მასივი ბლოკებად დაიყოფა შემდეგნაირად: 𝐴 0 ,𝐴 1 …𝐴[𝐾−1] 𝐴 𝐾 ,𝐴 𝐾+1 …𝐴[2∗𝐾−1] … 𝐴 𝑘−1 ∗𝑘 …𝐴[𝑁] B[0] B[1] B[K-1] უკანასკნელ ბლოკში შეიძლება იყოს K-ზე ნაკლები ელემენტი, მაგრამ ეს სტრუქტურის მუშაობაზე არავითარ გავლენას არ ახდენს.
  • 4. ავაგოთ SQRT დეკომპოზიცია N=23 ელემენტისაგან შედგენილი მასივისათვის. K ამ სიტუაციაში იქნება 5-ის ტოლი. ვთქვათ, მოთხოვნილია ელემენტთა ჯამის პოვნა [3,17] ინტერვალზე. მე-3 და მე-4 ელემენტების, ასევე მე-15, მე-16 და მე-17 ელემენტების ჯამს ვიპოვით A მასივიდან ორი ცალ-ცალკე ციკლით, ხოლო [5,9] და [10,14] ინტერვალების ჯამს B მასივიდან ავიღებთ: B[1]+B[2] . 6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7 22 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 20 1 24 2 27 3 14 4 A B 6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7 22 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 20 1 24 2 27 3 14 4 A B
  • 5. მოხდება მხოლოდ ორი ცვლილება 6 3 8 1 4 2 4 7 9 5 3 4 5 9 3 1 6 9 6 5 4 3 7 22 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 27 1 24 2 27 3 14 4 A B ვთქვათ, მასივის მე-8 ინდექსზე მყოფი ელემენტი 2 შეცვალეს და მისი ახალი მნიშვნელობაა 9, ეს გამოიწვევს მხოლოდ ორ ცვლილებას: გახორციელდება მინიჭება A[8]=9 და ახალი და ძველი მნიშნელობების სხვაობა დაემატება B მასივის შესაბამის ელემენტს. B[1]=20+(9-2)=27.
  • 6. 6 3 8 1 4 2 4 7 2 5 3 4 5 9 3 1 6 9 6 5 4 3 7 8 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 7 1 9 2 9 3 7 4 A B ვთქვათ, მოთხოვნილია მაქსიმალური ელემენტის პოვნა [2,12] ინტერვალზე. ერთი ციკლით ვიპოვით მაქსიმუმს მე-2, მე-3 და მე-4 ელემენტებს შორის, შემდეგ ავიღებთ გამზადებულ პასუხს B მასივიდან [5,9] ინტერვალისათვის და კიდევ ერთი ციკლი დაგვჭირდება ასევე მე-10, მე-11 და მე-12 ელემენტებს შორის მაქსიმუმის საპოვნელად. საბოლოოდ, მაქსიმუმის არჩევა მოგვიწევს სამ რიცხვს შორის max(8,7,5)=8.
  • 7. მაქსიმუმებისათვის მონაცემთა განახლების დროს განსახილველია სამი შემთხვევა: ა) როცა ახალი მონაცემი არ აღემატება საკუთარი შუალედის მაქსიმუმს. ამ შემთხვევაში იცვლება მხოლოდ ელემენტი A მასივში. ბ) ახალი მონაცემი მეტია აქამდე არსებულ მაქსიმუმზე. მაშინ იცვლება ელემენტი A მასივში და იგივე მონაცემი ჩაიწერება B-ს შესაბამის ინდექსზეც (ანუ განახლდება). გ) როცა ახალი მონაცემი ძველ მაქსიმუმს ცვლის უფრო მცირე მნიშვნელობით. ამ შემთხვევაში საჭიროა ციკლით გადავყვეთ A მასივის შესაბამის უბანს და მისი მაქსიმუმი ხელახლა ვიპოვოთ. 6 3 8 1 4 2 4 7 2 5 3 4 5 2 3 1 6 9 6 5 4 3 7 8 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 7 1 5 2 9 3 7 4 A B
  • 8. ჯამის, მინიმუმის ან მაქსიმუმის პოვნისას SQRT დეკომპოზიცია უარეს შემთხვევაში 3∗ 𝑁 ოპერაციას გააკეთებს, რადგან საწყის და საბოლოო უბნებზე მას შეიძლება მაქსიმუმ 𝑁-1 ოპერაციის გაკეთება დასჭირდეს, ხოლო დანარჩენი უბნების რაოდენობა, ცხადია, რომ 𝑁-ს არ აღემატება. მონაცემთა განახლებისას ჯამების დროს O(1) ოპერაცია ჰყოფნის, ხოლო მინიმუმის და მაქსიმუმის პოვნისას O( 𝑁).