انتقل إلى المحتوى
أمين أبوزيد
BEG-044

تقنيات الخوارزميات

  • 5 درس
  • 57 دقيقة قراءة
  • 4 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • المؤشران (Two pointers)
  • النافذة المنزلقة (sliding window)
  • الاستدعاء الذاتي (recursion)
  • أساسيات التراجع (backtracking)

تعلّم أولًا

57 دقيقة قراءة · 4 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Apply two pointers to sorted-array problems.
  2. Apply a sliding window to subarray/substring problems.
  3. Write recursive solutions and simple backtracking (subsets, permutations).
  4. Recognize which technique a new problem calls for.

الدروس

  1. 01المؤشران (Two pointers)12 د قراءة
  2. 02النافذة المنزلقة (Sliding window)12 د قراءة
  3. 03التفكير بالاستدعاء الذاتي11 د قراءة
  4. 04التراجع (Backtracking)11 د قراءة
  5. 05عرض عملي: حل مشكلة باستخدام النافذة المنزلقة11 د قراءة

المختبر والتمارين

Lab

BEG-044-LAB1 · Technique drills

Outcomes: 1–4 · Time: ~4 h Solve 8 problems, 2 per technique: two pointers (pair sum in a sorted array; reverse in place), sliding window (best sum of k consecutive items; longest substring without repeats), recursion (sum of digits; power), and backtracking (subsets; permutations). State the time complexity of each solution in a comment. Acceptance: 6 of 8 correct within target complexity.

Exercises (assessment: unseen timed problem set; six exercises)

IDOutcomeTask
BEG-044-EX011Given sorted [1, 3, 4, 6, 9, 11] and target 10, trace the two pointers until the pair is found.
BEG-044-EX021Remove duplicates from a sorted array in place with two pointers; return the new length.
BEG-044-EX032For [2, 1, 5, 1, 3, 2] and k = 3, find the maximum sum of 3 consecutive items with a sliding window.
BEG-044-EX043Write sumDigits(int n) recursively; name the base case.
BEG-044-EX053List all subsets of [1, 2, 3] and say how many permutations it has.
BEG-044-EX064Pick a technique for each: (a) longest run of 1s with at most one 0 flipped; (b) find two numbers that sum to a target in a sorted array; (c) all orderings of 4 letters; (d) count the files in nested folders.
أظهر الحلول
  • EX01 l=0, r=5: 1+11=12, too big, r-- ; 1+9=10, found (1 and 9).
  • EX02 int w = 1; for (int r = 1; r < a.length; r++) if (a[r] != a[w-1]) a[w++] = a[r]; return w; (assuming a non-empty array).
  • EX03 Window sums: 8, 7, 9, 6. Maximum 9 (items 5, 1, 3).
  • EX04 if (n < 10) return n; return n % 10 + sumDigits(n / 10); Base case: a single digit (n < 10).
  • EX05 [], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3] (8 subsets); 3! = 6 permutations.
  • EX06 (a) sliding window; (b) two pointers; (c) backtracking; (d) recursion.

الاختبار

Outcomes: O1 two pointers · O2 sliding window · O3 recursion and backtracking · O4 choosing a technique.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Two pointers from both ends works best on:O1
  2. 2Two pointers on a pair-sum problem takes:O1
  3. 3In a sorted pair-sum search, if the sum is too small you:O1
  4. 4A sliding window is a:O2
  5. 5The length of window [left, right] is:O2
  6. 6Every recursive method needs a:O3
  7. 7Missing base case usually causes:O3
  8. 8The number of subsets of a 4-item set is:O3
  9. 9Backtracking follows the pattern:O3
  10. 10"Longest substring with no repeated characters" calls for:O4

الجزء العملي

An unseen timed problem set (one problem per technique, stating complexity) plus the lab BEG-044-LAB1 and exercises BEG-044-EX01 to EX06. Pass: at least 3 of 4 timed problems correct within target complexity, lab at 6 of 8, and at least 8 of 10 quiz answers correct.

أخطاء شائعة

Applying two pointers to unsorted data; window bounds off by one.

التقييم

Unseen timed problem set.

الصلة بالمسار الوظيفي

Junior technical interviews.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.