Chapterبەش 2 · Lectureوانە 2.1
Algorithms, Pseudocode and Flowchartsئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوت
Planning before coding: what an algorithm is and what makes it good, writing it in pseudocode, drawing it with the standard flowchart symbols, the three building blocks sequence, selection and repetition, checking it with a trace table and border tests, comparing algorithms by time and memory, breaking big problems into smaller ones, and a five-part plan for a mini project — all without any programming language.
پلاندانان پێش کۆدنووسین: چییە و چی باشی دەکات، نووسینی بە ، کێشانی بە هێما ستانداردەکانی ، سێ بەردی بناغە (ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە)، پشکنینی بە و تاقیکردنەوەی سنوورەکان، بەراوردکردنی بە کات و ، کێشە گەورەکان و پلانێکی پێنج بەشی بۆ ، هەمووی بەبێ هیچ .
What you will learnچی فێر دەبیت
- Define an algorithm and judge whether a list of steps is a good one.
- Write simple algorithms in pseudocode.
- Read and draw flowcharts with the seven standard symbols.
- Recognise sequence, selection and repetition in any algorithm.
- Check an algorithm by hand with a trace table and good test inputs.
- Plan a mini project as scenario, flowchart, algorithm, code and examples.
- Compare correct algorithms by the time and memory they need.
- Break a big problem into smaller ones and plan the work of a team.
- پێناسە بکەیت و بڕیار بدەیت لیستێکی هەنگاو باشە یان نا.
- سادە بە بنووسیت.
- بە حەوت هێما ستانداردەکە بخوێنیتەوە و بیکێشیت.
- ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە لە هەر بناسیتەوە.
- بە دەست و بە و تاقیکردنەوەی باش بپشکنیت.
- پلانی وەک ، ، ، کۆد و نموونە دابنێیت.
- دروست بەپێی ئەو کات و پێویستیانە بەراورد بکەیت.
- کێشەیەکی گەورە بکەیت بە کێشەی بچووکتر و پلانی کاری تیمێک دابنێیت.
What an algorithm isئەلگۆریزم چییە؟
Before you write code, you need a plan. An algorithm is a finite list of clear, ordered steps that turns some input into the output you want. A recipe, the directions to a friend's house and the steps for taking cash from an ATM are all everyday algorithms.
پێش ئەوەی کۆد بنووسیت، پێویستت بە پلانێکە. لیستێکی کۆتاییداری هەنگاوی ڕوون و ڕیزکراوە کە دەکات بە ئەو دەتەوێت. ڕێنمایی چێشتلێنان، ڕێنمایی گەیشتن بە ماڵی هاوڕێیەک و هەنگاوەکانی وەرگرتنی پارە لە ئامێری ATM هەموویان ڕۆژانەن.
A finite list of clear steps that solves a problem or does a task. Programmers often plan an algorithm with or a before they write the code.
زنجیرەیەک هەنگاوی ڕوون و کۆتاییدارە کە کێشەیەک چارەسەر دەکات یان کارێک ئەنجام دەدات. زۆرجار پێش نووسینی کۆد، هەنگاوەکان بە یان بە دادەڕێژن.
For example, here is an algorithm in plain words for finding the largest of three numbers: “Remember the first number as the largest so far. Look at the second number; if it is bigger, remember it instead. Do the same with the third number. Say the number you remember.”
بۆ نموونە، ئەمە بە وشەی ئاسایی بۆ دۆزینەوەی گەورەترینی سێ ژمارە: «یەکەم ژمارە وەک گەورەترینی تا ئێستا لەبیر بگرە. سەیری ژمارەی دووەم بکە؛ ئەگەر گەورەتر بوو، لە جیاتی ئەو ئەمیان لەبیر بگرە. هەمان کار بە ژمارەی سێیەم بکە. ئەو ژمارەیە بڵێ کە لەبیرتە.»
What an algorithm isئەلگۆریزم چییە؟
What makes a good algorithmچی ئەلگۆریزمێک باش دەکات
- Clear — every step has one meaning. “Add a little salt” is not clear; “add 5 grams of salt” is.
- Ordered — the steps come in a fixed order, and the order matters.
- Finite — it always stops after a limited number of steps. “Keep adding 1 forever” never ends.
- Has input and output — it says what it starts with and what it gives back.
- Same input, same result — each step’s result depends only on the input and the steps before it, so the same input always gives the same output.
- Doable — every step can really be carried out, by a person with pencil and paper or by a computer.
- ڕوون: هەر هەنگاوێک یەک واتای هەیە. «کەمێک خوێ بکە» ڕوون نییە؛ «5 گرام خوێ بکە» ڕوونە.
- ڕیزکراو: هەنگاوەکان ڕیزبەندییەکی دیاریکراویان هەیە و ڕیزبەندییەکە گرنگە.
- کۆتاییدار: هەمیشە دوای ژمارەیەکی سنووردار هەنگاو دەوەستێت. «بۆ هەمیشە 1 زیاد بکە» هەرگیز کۆتایی نایەت.
- و هەیە: دەڵێت بە چی دەست پێ دەکات و چی دەداتەوە.
- هەمان ، هەمان ئەنجام: ئەنجامی هەر هەنگاوێک تەنها بە و هەنگاوەکانی پێشوویەوە بەندە، بۆیە هەمان هەمیشە هەمان دەدات.
- جێبەجێکراو: هەموو هەنگاوێک بەڕاستی دەکرێت، لەلایەن مرۆڤێک بە قەڵەم و کاغەز یان لەلایەن .
Pseudocodeنیمچەکۆد
Pseudocode writes an algorithm in short, structured lines that look a little like code but are meant for people, not computers. It has no single official standard, but most books use similar words: INPUT and OUTPUT, ← for “store this value”, IF … THEN … ELSE … END IF for decisions and WHILE … DO … END WHILE for repetition. The keywords stay in English in every language, because they become real code later.
بە دێڕی کورت و ڕێکخراو دەنووسێت کە کەمێک لە کۆد دەچن بەڵام بۆ مرۆڤن، نەک بۆ . هیچ ستانداردێکی فەرمیی تاکی نییە، بەڵام زۆربەی کتێبەکان وشەی هاوشێوە بەکار دەهێنن: INPUT و OUTPUT، ← بۆ «ئەم هەڵبگرە»، IF … THEN … ELSE … END IF بۆ بڕیار و WHILE … DO … END WHILE بۆ دووبارەکردنەوە. لە هەموو زمانێکدا بە ئینگلیزی دەمێننەوە، چونکە دواتر دەبن بە کۆدی ڕاستەقینە.
START
INPUT a, b, c
largest ← a
IF b > largest THEN
largest ← b
END IF
IF c > largest THEN
largest ← c
END IF
OUTPUT largest
ENDExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
largest ← ameans: store the value ofainlargest.largest ← aواتە:aلەlargestـدا هەڵبگرە.- Lineدێڕی 4-6
A decision: the indented line runs only when the condition is true.
بڕیارێک: دێڕە بۆشاییدارەکە تەنها کاتێک جێبەجێ دەبێت کە ڕاست بێت.
- Lineدێڕی 10
The answer goes out.
وەڵامەکە دەچێتە دەرەوە.
Pseudocode lets you think about the steps without worrying about one language's punctuation. The same lines can later be written in Python, Java or C#. AI books use their own pseudocode conventions; those are explained in Reading AI pseudocode.
ڕێگەت پێ دەدات بیر لە هەنگاوەکان بکەیتەوە بەبێ نیگەرانی لە خاڵبەندیی زمانێکی دیاریکراو. هەمان دێڕەکان دواتر دەکرێت بە Python، Java یان C# بنووسرێن. کتێبەکانی ڕێکەوتنی تایبەت بە خۆیان هەیە؛ ئەوانە لە خوێندنەوەی نیمچەکۆدی ژیریی دەستکرد ڕوون کراونەتەوە.
Learn what pseudocode is and how programmers write short English-like steps before writing real code.
فێردەبیت چییە و چۆن پێش نووسینی کۆدی ڕاستەقینە، هەنگاوی کورت بە زمانێکی نزیک لە ئینگلیزی دەنووسن.
Watch 0:50-3:01: what pseudocode is and a first example with ←; it stops before the loop example.
لە 0:50 تا 3:01 سەیر بکە: چییە و یەکەم نموونە بە ←؛ پێش نموونەی ڕادەوەستێت.
Flowchart symbolsهێماکانی هێڵکاریی ڕەوت
A flowchart draws an algorithm as shapes joined by arrows. Each shape has a fixed meaning, so anyone can read a flowchart. Flow diagrams for work processes were introduced by the engineers Frank and Lillian Gilbreth in 1921; the symbols programmers use today are set in the international standard ISO 5807 (1985).
وەک شێوەی بەیەکەوە بەستراو بە تیر دەکێشێت. هەر شێوەیەک واتایەکی دیاریکراوی هەیە، بۆیە هەموو کەسێک دەتوانێت بخوێنێتەوە. کار لە ساڵی 1921دا لەلایەن هەردوو ئەندازیار Frank و Lillian Gilbrethـەوە ناسێنران؛ ئەو هێمایانەی ئەمڕۆ بەکاریان دەهێنن لە ستانداردی نێودەوڵەتیی ISO 5807 (1985)دا دیاری کراون.
| Shapeشێوە | Nameناو | Use it forبۆ چی بەکاری دەهێنیت |
|---|---|---|
| rounded rectangle (oval)لاکێشەی خڕ (هێلکەیی) | terminal | Start and Endدەستپێک و کۆتایی |
| rectangleلاکێشە | process | a calculation or action, such as total ← total + markحیسابکردن یان کارێک، وەک total ← total + mark |
| parallelogramلاکێشەی لار | input/output | reading data in or showing a resultوەرگرتنی یان پیشاندانی ئەنجام |
| diamondئەڵماسی | decision | a yes/no question; two labelled exitsپرسیارێکی بەڵێ/نەخێر؛ دوو ڕێگای دەرچوونی ناونووسکراو |
| arrowتیر | flow line | the order of the stepsڕیزبەندیی هەنگاوەکان |
| rectangle with double sidesلاکێشە بە دوو هێڵی لاتەنیشت | predefined process | a named sub-algorithm drawn in its own flowchart بچووکی ناودار کە لە جیادا کێشراوە |
| small circle with a letterبازنەیەکی بچووک بە پیتێک | connector | joining parts of a flowchart that do not fit together, for example on the next pageبەستنەوەی بەشەکانی کە پێکەوە جێیان نابێتەوە، بۆ نموونە لە لاپەڕەی دواتردا |
See how programmers draw a flowchart: the shapes for start, process, decision and input/output, joined by arrows.
دەبینیت چۆن دەکێشن: شێوەکانی دەستپێک، پرۆسە، بڕیار و /، کە بە تیر پێکەوە دەبەسترێن.
Watch 0:50-4:38.
لە 0:50 تا 4:38 سەیر بکە.
Flowchart symbolsهێماکانی هێڵکاریی ڕەوت
Rules for a clear flowchartیاساکانی هێڵکارییەکی ڕەوت ڕوون
- Exactly one Start and at least one End.
- Flow goes from top to bottom and left to right; arrows show any other direction.
- A decision has exactly two exits, labelled Yes and No (or True and False).
- Write short actions in words or pseudocode — not whole lines of a real programming language.
- Use the right shape: calculations in rectangles, input and output in parallelograms.
- Avoid crossing lines; use connectors when a chart is too big for one page.
- ڕێک یەک دەستپێک و لانیکەم یەک کۆتایی.
- ڕەوت لە سەرەوە بۆ خوارەوە و لە چەپەوە بۆ ڕاست دەڕوات؛ تیرەکان هەر ئاڕاستەیەکی تر پیشان دەدەن.
- بڕیار ڕێک دوو ڕێگای دەرچوونی هەیە کە بە بەڵێ و نەخێر ناونووس کراون.
- کاری کورت بە وشە یان بە بنووسە، نەک دێڕی تەواوی ڕاستەقینە.
- شێوەی دروست بەکار بهێنە: حیسابکردن لە لاکێشەدا، و لە لاکێشەی لاردا.
- خۆت لە هێڵی بەیەکداچوو بپارێزە؛ کاتێک بۆ یەک لاپەڕە زۆر گەورەیە گەیەنەر بەکار بهێنە.
Three building blocksسێ بەردی بناغە
Every algorithm, however large, is built from only three control structures:
هەموو ، هەرچەند گەورە بێت، تەنها لە سێ دروست دەکرێت:
- Sequence — steps run one after another, in order.
- Selection — a condition chooses one of two paths (
IF … THEN … ELSE). - Repetition — steps repeat while a condition is true (
WHILE … DO), also called a loop.
- ڕیزبەندی: هەنگاوەکان یەک لە دوای یەک و بە ڕیز جێبەجێ دەبن.
- هەڵبژاردن: یەکێک لە دوو ڕێگا هەڵدەبژێرێت (
IF … THEN … ELSE). - دووبارەکردنەوە: هەنگاوەکان دووبارە دەبنەوە مادام ڕاستە (
WHILE … DO)، پێی دەوترێت .
In 1966 the computer scientists Corrado Böhm and Giuseppe Jacopini showed that these three are enough to express any algorithm a computer can carry out. Every language in this course — Python today, Java or C# tomorrow — has its own words for them, but the ideas are the same.
لە ساڵی 1966دا زانایانی Corrado Böhm و Giuseppe Jacopini سەلماندیان کە ئەم سێیانە بەسن بۆ دەربڕینی هەر کە بتوانێت جێبەجێی بکات. هەموو زمانێکی ئەم کۆرسە (ئەمڕۆ Python، سبەی Java یان C#) وشەی خۆی بۆیان هەیە، بەڵام بیرۆکەکان وەک یەکن.
The three building blocks of every program: sequence (steps in order), selection (a question chooses the path) and loops (repeat).
سێ بەردی بناغەی هەموو : ڕیزبەندی (هەنگاوەکان بە دوای یەکدا)، هەڵبژاردن (پرسیارێک ڕێگەکە دیاری دەکات) و (دووبارەکردنەوە).
Whole video (2:26).
هەموو ڤیدیۆکە (2:26).
Worked example: the largest of three numbersنموونەی شیکراوە: گەورەترینی سێ ژمارە
Here is the algorithm from the start of this lesson as a flowchart. It uses sequence (the first three steps) and selection (the two diamonds). The idea: keep the “largest so far” in largest, and replace it whenever you find a bigger number. The same algorithm in pseudocode is on the pseudocode screen.
ئەمە ئەو لە سەرەتای ئەم وانەیەدا هات، وەک . ڕیزبەندی (سێ هەنگاوی یەکەم) و هەڵبژاردن (دوو شێوە ئەڵماسییەکە) بەکار دەهێنێت. بیرۆکەکە: «گەورەترینی تا ئێستا» لە largestـدا هەڵبگرە و هەر کاتێک ژمارەیەکی گەورەترت دۆزییەوە بیگۆڕە. هەمان بە لە شاشەی نیمچەکۆددایە.
Worked example: the largest of three numbersنموونەی شیکراوە: گەورەترینی سێ ژمارە
Checking with a trace tableپشکنین بە خشتەی بەدواداچوون
A mistake in a bank’s transfer program could send only half of the money; in hospital or aircraft software a mistake can hurt people. So an algorithm must be checked in every situation before anyone trusts it. How, before any code exists? You trace it: follow the steps by hand with real input and write every change in a trace table — one column per variable, one row per step.
هەڵەیەک لە گواستنەوەی پارەی بانکێکدا دەکرێت تەنها نیوەی پارەکە بنێرێت؛ لە نەخۆشخانە یان فڕۆکەدا هەڵەیەک دەکرێت زیان بە خەڵک بگەیەنێت. بۆیە پێش ئەوەی کەس متمانەی پێ بکات، دەبێت لە هەموو بارێکدا بپشکنرێت. چۆن، پێش ئەوەی هیچ کۆدێک هەبێت؟ بەدوایدا دەچیت: بە دەست و بە ڕاستەقینە شوێن هەنگاوەکان دەکەویت و هەموو گۆڕانکارییەک لە دەنووسیت: ستوونێک بۆ هەر و ڕیزێک بۆ هەر هەنگاوێک.
A table you fill in by hand to follow a program or an step by step: one column for each and for the , one row for each step. It shows exactly where a happens.
خشتەیەکە بە دەست پڕی دەکەیتەوە بۆ ئەوەی هەنگاو بە هەنگاو بەدوای یان بچیت: ستوونێک بۆ هەر و بۆ ، هەروەها ڕیزێک بۆ هەر هەنگاوێک. بە وردی پیشان دەدات لە کوێدا ڕوو دەدات.
| Stepهەنگاو | a | b | c | largest | Output |
|---|---|---|---|---|---|
| INPUT a, b, c | 7 | 12 | 9 | ||
| largest ← a | 7 | ||||
b > largest? : Yesb > largest? : بەڵێ | 12 | ||||
c > largest? : Noc > largest? : نەخێر | 12 | ||||
| OUTPUT largest | 12 |
Now trace a harder case, 5, 5, 3, where two numbers are equal: largest starts as 5; is ? No; is ? No; the output is 5. Correct. Good testers always try equal values, the smallest and largest values, and unusual inputs. In the Python track you use trace tables to find bugs in real code: Errors and debugging.
ئێستا بەدوای حاڵەتێکی قورستردا بچۆ، 5، 5، 3، کە دوو ژمارە یەکسانن: largest بە 5 دەست پێ دەکات؛ ئایا ؟ نەخێر؛ ئایا ؟ نەخێر؛ 5ـە. دروستە. تاقیکەرەوەی باش هەمیشە یەکسانەکان، بچووکترین و گەورەترین و نائاسایی تاقی دەکاتەوە. لە ڕێڕەوی Pythonـدا بۆ دۆزینەوەی لە کۆدی ڕاستەقینەدا بەکار دەهێنیت: هەڵەکان و کرمەکوژی.
Worked example: the largest of three numbersنموونەی شیکراوە: گەورەترینی سێ ژمارە
A trap: equal numbersداوێک: ژمارەی یەکسان
Many students first write the largest-of-three algorithm like this. It looks right, and it works for 7, 12, 9. Trace it with 5, 5, 3 before you read on.
زۆر خوێندکار سەرەتا گەورەترینی سێ ژمارە بەم شێوەیە دەنووسن. ڕاست دەردەکەوێت و بۆ 7، 12، 9 کار دەکات. پێش ئەوەی بەردەوام بیت، بە 5، 5، 3 بەدوایدا بچۆ.
START
INPUT a, b, c
IF a > b AND a > c THEN
OUTPUT a
ELSE IF b > a AND b > c THEN
OUTPUT b
ELSE
OUTPUT c
END IF
ENDExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
5 > 5 is false, so this branch is skipped.
5 > 5 هەڵەیە، بۆیە ئەم لقە جێبەجێ نابێت.
- Lineدێڕی 5
5 > 5 is false again, so this branch is skipped too.
5 > 5 دیسان هەڵەیە، بۆیە ئەم لقەش جێبەجێ نابێت.
- Lineدێڕی 7-8
Only ELSE is left, so it outputs c = 3 — the smallest number!
تەنها ELSE ماوە، بۆیە c = 3 دەردەدات: بچووکترین ژمارە!
The comparisons use >, so when the two biggest numbers are equal, neither of them wins and the algorithm falls through to c. Fix it with >= in both tests, or use the “largest so far” version from the flowchart, which handles ties naturally. This is exactly why we trace with unusual inputs.
بەراوردەکان > بەکار دەهێنن، بۆیە کاتێک دوو گەورەترین ژمارەکە یەکسان بن، هیچیان نابەنەوە و دەگاتە c. بە >= لە هەردوو پشکنینەکەدا چاکی بکە، یان وەشانی «گەورەترینی تا ئێستا»ی ناو بەکار بهێنە کە بە سروشتی ژمارەی یەکسان چارەسەر دەکات. ڕێک بۆ ئەمە بە نائاسایی بەدوای دەچین.
Worked example: the largest of three numbersنموونەی شیکراوە: گەورەترینی سێ ژمارە
Another trap: adding timesداوێکی تر: کۆکردنەوەی کات
A travel app adds the times of two bus trips. Its first algorithm added the hours and the minutes separately. Tested with 2 h 20 min + 1 h 30 min, it gave 3 h 50 min — correct. But for 1 h 15 min + 1 h 50 min it gave 2 h 65 min, and no clock shows 65 minutes. One test case was enough to break it. The highlighted lines fix it:
گەشت کاتی دوو گەشتی پاس کۆ دەکاتەوە. یەکەم کاتژمێرەکان و خولەکەکانی بە جیا کۆ دەکردەوە. بە 2 کاتژمێر و 20 خولەک لەگەڵ 1 کاتژمێر و 30 خولەک تاقی کرایەوە و 3 کاتژمێر و 50 خولەکی دا، کە دروستە. بەڵام بۆ 1 کاتژمێر و 15 خولەک لەگەڵ 1 کاتژمێر و 50 خولەک وەڵامەکەی 2 کاتژمێر و 65 خولەک بوو و هیچ کاتژمێرێک 65 خولەک پیشان نادات. یەک حاڵەتی تاقیکردنەوە بەس بوو بۆ شکاندنی. دێڕە ڕەنگکراوەکان چاکی دەکەن:
START
INPUT h1, m1, h2, m2
hours ← h1 + h2
minutes ← m1 + m2
IF minutes ≥ 60 THEN
hours ← hours + 1
minutes ← minutes − 60
END IF
OUTPUT hours, minutes
ENDNow 1 h 15 min + 1 h 50 min gives 3 h 5 min. Test the border too: 0 h 45 min + 0 h 15 min must give exactly 1 h 0 min, which is why the test is minutes ≥ 60. One IF is enough: each input has fewer than 60 minutes, so their sum is at most 118.
ئێستا 1 کاتژمێر و 15 خولەک لەگەڵ 1 کاتژمێر و 50 خولەک دەدات 3 کاتژمێر و 5 خولەک. سنوورەکەش تاقی بکەرەوە: 0 کاتژمێر و 45 خولەک لەگەڵ 0 کاتژمێر و 15 خولەک دەبێت ڕێک 1 کاتژمێر و 0 خولەک بدات؛ بۆیە پشکنینەکە minutes ≥ 60ـە. یەک IF بەسە: هەر کەمتر لە 60 خولەکی هەیە، بۆیە کۆکەیان لە 118 زیاتر نابێت.
Worked example: the average of five marksنموونەی شیکراوە: تێکڕای پێنج نمرە
This algorithm adds repetition. Two variables do the work: total adds up the marks (an accumulator) and count counts how many marks have been read (a counter). Both must start at 0. The loop repeats while count < 5; after the fifth mark the condition is false and the algorithm leaves the loop.
ئەم دووبارەکردنەوە زیاد دەکات. دوو کارەکە دەکەن: total نمرەکان کۆ دەکاتەوە () و count دەژمێرێت چەند نمرە وەرگیراوە (). هەردووکیان دەبێت بە 0 دەست پێ بکەن. دووبارە دەبێتەوە مادام count < 5؛ دوای نمرەی پێنجەم هەڵە دەبێت و لە دەردەچێت.
START
total ← 0
count ← 0
WHILE count < 5 DO
INPUT mark
total ← total + mark
count ← count + 1
END WHILE
average ← total / 5
OUTPUT average
ENDExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
Start the accumulator and the counter at 0.
و بە 0 دەست پێ بکە.
- Lineدێڕی 4
The loop condition is checked before each repeat.
پێش هەر دووبارەبوونەوەیەک دەپشکنرێت.
- Lineدێڕی 7
Without this line count stays 0 and the loop never ends.
بەبێ ئەم دێڕە count هەر 0 دەمێنێتەوە و هەرگیز کۆتایی نایەت.
| After readingدوای وەرگرتنی | mark | total | count | count < 5? |
|---|---|---|---|---|
| (start)(دەستپێک) | – | 0 | 0 | Yesبەڵێ |
| 1st markنمرەی یەکەم | 8 | 8 | 1 | Yesبەڵێ |
| 2nd markنمرەی دووەم | 6 | 14 | 2 | Yesبەڵێ |
| 3rd markنمرەی سێیەم | 10 | 24 | 3 | Yesبەڵێ |
| 4th markنمرەی چوارەم | 7 | 31 | 4 | Yesبەڵێ |
| 5th markنمرەی پێنجەم | 9 | 40 | 5 | No: leave the loopنەخێر: لە دەربچۆ |
Worked example: the average of five marksنموونەی شیکراوە: تێکڕای پێنج نمرە
Following the flowchart step by stepشوێنکەوتنی هێڵکاریی ڕەوتەکە هەنگاو بە هەنگاو
Watch the same flowchart run with the marks 8, 6, 10, 7 and 9. The highlighted shape is the step running now, and the box on the right shows the variables after that step.
سەیر بکە هەمان بە نمرەکانی 8، 6، 10، 7 و 9 جێبەجێ دەبێت. شێوە ڕەنگکراوەکە ئەو هەنگاوەیە کە ئێستا جێبەجێ دەبێت و چوارگۆشەکەی لای ڕاست دوای ئەو هەنگاوە پیشان دەدات.


Comparing algorithmsبەراوردکردنی ئەلگۆریزمەکان
A problem often has more than one correct algorithm. Which one should you use? Take the question “Is n prime?”. A prime number is a whole number above 1 that only 1 and itself divide exactly. Here are four correct methods. Each tries divisors in order and answers “not prime” as soon as one divides n exactly; if none does, n is prime.
کێشەیەک زۆرجار زیاتر لە یەک دروستی هەیە. کامیان بەکار بهێنیت؟ پرسیاری «ئایا n سەرەتاییە؟» وەربگرە. ژمارەی سەرەتایی لە سەرووی 1 کە تەنها 1 و خودی خۆی بە تەواوی دابەشی دەکەن. ئەمە چوار ڕێگای دروستە. هەر یەکەیان دابەشکەرەکان بە ڕیز تاقی دەکاتەوە و هەر کە یەکێکیان n بە تەواوی دابەش بکات، وەڵام دەداتەوە «سەرەتایی نییە»؛ ئەگەر هیچیان نەیکرد، n سەرەتاییە.
| Method: the divisors it triesڕێگا: ئەو دابەشکەرانەی تاقییان دەکاتەوە | Divisions for ژمارەی دابەشکردن بۆ |
|---|---|
| 1. every number from 2 to 1. هەموو ژمارەیەک لە 2ـەوە تا | 95 |
| 2. only up to half of n: apart from n itself, no divisor is bigger than 2. تەنها تا نیوەی n: جگە لە خودی n، هیچ دابەشکەرێک لە گەورەتر نییە | 47 |
| 3. only up to : if , the smaller of a and b is at most 3. تەنها تا : ئەگەر ، بچووکترینی a و b لە گەورەتر نییە | 8 |
| 4. only the primes smaller than n, read from a stored list of primes4. تەنها ئەو ژمارە سەرەتاییانەی لە n بچووکترن، لە لیستێکی هەڵگیراوی ژمارە سەرەتاییەکانەوە | 24 |
All four give the same answer. For 97 they do 95, 47, 8 and 24 divisions: 97 is prime, so nothing divides it and every method must try its whole list. This is the worst case. For 91 every method stops at 7, because .
هەر چواریان هەمان وەڵام دەدەن. بۆ 97 بە ڕیز 95، 47، 8 و 24 دابەشکردن دەکەن: 97 سەرەتاییە، بۆیە هیچ ژمارەیەک دابەشی ناکات و هەر ڕێگایەک دەبێت هەموو لیستەکەی تاقی بکاتەوە. ئەمە . بۆ 91 هەموو ڕێگاکان لە 7دا دەوەستن، چونکە .
Comparing algorithmsبەراوردکردنی ئەلگۆریزمەکان
Time or memory?کات یان بیرگە؟
Method 3 is the fastest of the four, and the gap grows with n: for 1009 it does 30 divisions instead of 1007. Method 4 does fewer divisions than methods 1 and 2, but its list of primes must first be stored in memory. Combine methods 3 and 4 — divide only by the stored primes up to , that is 2, 3, 5 and 7 — and 4 divisions are enough.
ڕێگای 3 خێراترینی هەر چوارەکەیە و جیاوازییەکە لەگەڵ گەورەبوونی n زیاد دەبێت: بۆ 1009 لە جیاتی 1007 دابەشکردن تەنها 30 دەکات. ڕێگای 4 لە ڕێگاکانی 1 و 2 دابەشکردنی کەمترە، بەڵام دەبێت سەرەتا لیستی ژمارە سەرەتاییەکان لە هەڵبگیرێت. ڕێگاکانی 3 و 4 تێکەڵ بکە، واتە تەنها بەسەر ئەو ژمارە سەرەتاییە هەڵگیراوانەدا دابەش بکە کە تا ن (2، 3، 5 و 7)، ئەوسا 4 دابەشکردن بەسە.
So algorithms are compared in two ways: how the number of steps grows as the input grows — time complexity — and how much memory they need — space complexity. Often you can buy speed with memory, as method 4 does, or save memory by doing more work. The artificial-intelligence course measures both exactly with Big-O notation: Time and space complexity.
بۆیە بە دوو ڕێگا بەراورد دەکرێن: ژمارەی هەنگاوەکان چۆن لەگەڵ گەورەبوونی زیاد دەبێت () و چەند پێویستە (). زۆرجار دەتوانیت خێرایی بە بکڕیت، وەک ڕێگای 4، یان بە کاری زیاتر پاشەکەوت بکەیت. کۆرسی هەردووکیان بە وردی بە نیشانەی Big-O دەپێوێت: ئاڵۆزیی کات و ئاڵۆزیی بیرگە.
Planning a project in five partsپلاندانانی پڕۆژەیەک لە پێنج بەشدا
For a mini project, the course used a simple plan in five parts. A first-year group followed it to build a binary-to-decimal converter, and you can use it for any program:
بۆ ، کۆرسەکە پلانێکی سادەی پێنج بەشی بەکار هێنا. گرووپێکی قۆناغی یەکەم بۆ دروستکردنی گۆڕەرێکی بۆ پەیڕەوی کرد و تۆش دەتوانیت بۆ هەر بەکاری بهێنیت:
- Scenarioنەخشەنامە
Describe the aim of the project in plain words: what the program is for and how a user will use it.
ئامانجی پڕۆژەکە بە وشەی ئاسایی باس بکە: بۆ چییە و چۆن بەکاری دەهێنێت.
- Flowchartهێڵکاریی ڕەوت
Draw how the program works, with the standard symbols.
بە هێما ستانداردەکان بیکێشە کە چۆن کار دەکات.
- Algorithmئەلگۆریزم
Write the steps of the program from the very beginning, numbered, in words or pseudocode.
هەنگاوەکانی لە سەرەتاوە، بە ژمارە، بە وشە یان بە بنووسە.
- Codeکۆد
Write the source code in your programming language, following the algorithm.
بە پەیڕەوکردنی ، بە بنووسە.
- Examplesنموونەکان
Run the program on several examples and show the results, to prove that it works.
لەسەر چەند نموونەیەک جێبەجێ بکە و ئەنجامەکان پیشان بدە، بۆ سەلماندنی ئەوەی کار دەکات.
Planning a project in five partsپلاندانانی پڕۆژەیەک لە پێنج بەشدا
Why this order?بۆچی ئەم ڕیزبەندییە؟
The scenario makes sure you solve the right problem. The flowchart and the algorithm let you find mistakes on paper, where fixing them is cheap. The examples prove the program works — and when one fails, you go back to the plan, not only to the code. The group's Kurdish report gave the parts Kurdish names, shown in the Kurdish version of this screen.
دڵنیات دەکاتەوە کە کێشە دروستەکە چارەسەر دەکەیت. و ڕێگەت پێ دەدەن هەڵەکان لەسەر کاغەز بدۆزیتەوە، کە چاککردنیان هەرزانە. نموونەکان دەیسەلمێنن کە کار دەکات و کاتێک یەکێکیان سەرنەکەوت، دەگەڕێیتەوە بۆ پلانەکە، نەک تەنها بۆ کۆدەکە. ڕاپۆرتە کوردییەکەی گرووپەکە ئەم ناوانەی بۆ بەشەکان بەکار هێنا: ، «هێڵکاریی داڕژانی دراوەکان» (بۆ )، «هەنگاونامە» (بۆ )، «کۆدەکانی بەرنامەکە» و «چەند نموونەیەکی بەرنامەکە».
Planning a project in five partsپلاندانانی پڕۆژەیەک لە پێنج بەشدا
The five parts in action: a taxi-fare programپێنج بەشەکە بە کردەوە: بەرنامەیەکی کرێی تەکسی
1. Scenario. The driver types the distance of the trip in kilometres. The program shows the fare: a starting fee of 2000 dinars plus 500 dinars per kilometre. If the distance is 0 or less, it says “Try again” and asks again.
1. . شۆفێرەکە دووریی گەشتەکە بە کیلۆمەتر دەنووسێت. کرێکە پیشان دەدات: 2000 دینار کرێی دەستپێک لەگەڵ 500 دینار بۆ هەر کیلۆمەترێک. ئەگەر دوورییەکە 0 یان کەمتر بوو، دەڵێت «Try again» و دووبارە دەپرسێتەوە.
START
INPUT distance
WHILE distance ≤ 0 DO
OUTPUT "Try again"
INPUT distance
END WHILE
fare ← 2000 + distance × 500
OUTPUT fare
ENDExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3-6
An input check: repeat while the distance is not valid.
پشکنینی : دووبارە بکەرەوە مادام دوورییەکە دروست نییە.
4. Code. Each language track writes these eight lines in its own language — for example in the Python track.
4. کۆد. هەر ڕێڕەوێکی زمان ئەم هەشت دێڕە بە زمانی خۆی دەنووسێت، بۆ نموونە لە ڕێڕەوی Pythonـدا.
| 5. Example input5. نموونە | Expected output چاوەڕوانکراو | Why test itبۆچی تاقی دەکرێتەوە |
|---|---|---|
| 6 | 5000 | a normal trip: گەشتێکی ئاسایی: |
| 10 | 7000 | a second normal trip: گەشتێکی ئاسایی تر: |
| 1 | 2500 | the shortest whole tripکورتترین گەشتی تەواو |
| 0 | Try again | the border case: not allowedحاڵەتی سنوور: ڕێگەپێنەدراو |
| Try again | an impossible input نەگونجاو |
Decomposition: divide and conquerپارچەکردن: دابەشی بکە و زاڵ بە
Breaking a big problem into smaller sub-problems that are easier to solve, and then putting their solutions together to solve the whole problem.
شکاندنی کێشەیەکی گەورە بۆ چەند کێشەیەکی بچووکتر کە چارەسەرکردنیان ئاسانترە، پاشان پێکەوەنانی چارەسەرەکانیان بۆ چارەسەرکردنی هەموو کێشەکە.
Some problems are too big to plan in one go: a whole app, a school event, a weather forecast. Break such a problem into sub-problems, and each sub-problem into smaller ones, until every piece is small enough for one short algorithm. Then put the pieces together. Here is a course-registration app broken down:
هەندێک کێشە ئەوەندە گەورەن کە بە یەک جار پلانیان بۆ دانانرێت: تەواو، چالاکییەکی قوتابخانە، پێشبینیی کەشوهەوا. کێشەیەکی وەها بکە بە چەند کێشەیەکی بچووکتر و هەر یەکەشیان بکە بە بچووکتر، تا هەر پارچەیەک ئەوەندە بچووک دەبێت کە یەک کورت بەسی بێت. پاشان پارچەکان پێکەوە دابنێ. ئەمە ناونووسینی وانەکانە کە پارچە کراوە:
In code, each small piece usually becomes a function with one job; in the Python track see Small pieces, one job each. In a flowchart, a piece that is planned somewhere else is drawn as a predefined-process box.
لە کۆددا هەر پارچەیەکی بچووک زۆرجار دەبێت بە کە یەک کاری هەیە؛ لە ڕێڕەوی Pythonـدا بڕوانە پارچەی بچووک، هەریەکە بۆ یەک کار. لە ، پارچەیەک کە لە شوێنێکی تر پلانی بۆ دانراوە وەک چوارگۆشەی پرۆسەی ئامادە دەکێشرێت.
Decomposition: divide and conquerپارچەکردن: دابەشی بکە و زاڵ بە
Top-down and bottom-upدیزاینی سەرەوە بۆ خوارەوە و دیزاینی خوارەوە بۆ سەرەوە
You can work through the pieces in two directions:
دەتوانیت بە دوو ئاراستە کار لەسەر پارچەکان بکەیت:
- Top-down design: start with the whole task and split it again and again, as in the tree above, before you write anything. You always see how each piece fits the whole.
- Bottom-up design: first write and test small parts that you know you will need, such as “check that a student number is valid”, then join them into bigger parts. You have working pieces early.
- : لە هەموو ئەرکەکەوە دەست پێ بکە و پێش ئەوەی هیچ بنووسیت، دووبارە و دووبارە دابەشی بکە، وەک دارەکەی سەرەوە. هەمیشە دەبینیت هەر پارچەیەک چۆن لەگەڵ هەمووەکەدا دەگونجێت.
- : سەرەتا ئەو بەشە بچووکانە بنووسە و تاقی بکەرەوە کە دەزانیت پێویستت دەبن، وەک «بپشکنە ئایا ژمارەی خوێندکار دروستە»، پاشان بیانبەستە بە یەکەوە بۆ بەشی گەورەتر. زوو پارچەی کاراکەت دەبێت.
Real projects usually mix both. Either way, give every piece one clear job, a clear input and a clear output, so that the pieces fit together like bricks in a wall.
پڕۆژە ڕاستەقینەکان زۆرجار هەردووکیان تێکەڵ دەکەن. بە هەر ڕێگایەک بێت، یەک کاری ڕوون، ڕوون و ڕوون بدە بە هەر پارچەیەک، بۆ ئەوەی پارچەکان وەک خشت لە دیوارێکدا پێکەوە بگونجێن.
Decomposition: divide and conquerپارچەکردن: دابەشی بکە و زاڵ بە
Sharing the work in a teamدابەشکردنی کارەکە لە تیمێکدا
Decomposition also lets a team share the work: different people or groups take different sub-problems, ideally the ones they know best. Each piece is first tested on its own, then the pieces are joined and tested together — the unit and integration levels of testing. Big jobs such as a school’s open day, a delivery service or a weather forecast are organised this way.
هەروەها ڕێگە بە تیمێک دەدات کارەکە دابەش بکات: کەس یان گرووپی جیاواز کێشە بچووکە جیاوازەکان وەردەگرن، باشتر وایە ئەوانەی کە باشتر دەیانناسن. سەرەتا هەر پارچەیەک بە تەنها تاقی دەکرێتەوە، پاشان پارچەکان پێکەوە دەبەسترێن و پێکەوە تاقی دەکرێنەوە: ئاستەکانی و لە تاقیکردنەوە لە چوار ئاستدا. کاری گەورەی وەک ڕۆژی کراوەی قوتابخانەیەک، خزمەتگوزاریی گەیاندن یان پێشبینیی کەشوهەوا بەم شێوەیە ڕێک دەخرێن.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Fixچارەسەر |
|---|---|
| A decision diamond with one exit, or exits without labelsشێوەیەکی ئەڵماسی بە یەک ڕێگای دەرچوون، یان ڕێگای بێ ناونووس | Draw two exits and label them Yes and No.دوو ڕێگا بکێشە و بە بەڵێ و نەخێر ناونووسیان بکە. |
| No End, or several Startsکۆتایی نییە، یان چەند دەستپێکێک | One Start, at least one End.یەک دەستپێک، لانیکەم یەک کۆتایی. |
| Full program lines inside the shapesدێڕی تەواوی لە ناو شێوەکاندا | Short actions in words or pseudocode; the code comes later.کاری کورت بە وشە یان ؛ کۆد دواتر دێت. |
| Calculations or variable set-up in a parallelogramحیسابکردن یان ئامادەکردنی لە لاکێشەی لاردا | Parallelograms are only for input and output; calculations go in rectangles.لاکێشەی لار تەنها بۆ و ؛ حیسابکردن دەچێتە ناو لاکێشەوە. |
| A loop whose condition never changes کە هەرگیز ناگۆڕێت | Change the counter inside the loop, or the loop never ends. لە ناو بگۆڕە، ئەگەرنا هەرگیز کۆتایی نایەت. |
| Forgetting to set total or count to 0 firstلەبیرچوونی ئەوەی سەرەتا total یان count بکەیت بە 0 | Initialise every accumulator and counter before the loop.پێش سەرەتایی بۆ هەموو و دابنێ. |
| Testing with only one easy exampleتاقیکردنەوە تەنها بە یەک نموونەی ئاسان | Also try equal values, borders such as 0, and impossible input. یەکسانەکان، سنوورەکان وەک 0 و نەگونجاویش تاقی بکەرەوە. |
Exercisesڕاهێنانەکان
Write an algorithm in pseudocode that reads a whole number and outputs “Even” or “Odd”, and say which shapes its flowchart needs.
بە بنووسە کە وەردەگرێت و «Even» یان «Odd» دەردەدات و بڵێ پێویستی بە کام شێوانەیە.
Hintئاماژە
A number is even when dividing it by 2 leaves no remainder.
ژمارە جووتە کاتێک دابەشکردنی بەسەر 2دا هیچ نەبێت.
Show answerوەڵامەکە پیشان بدە
START
INPUT n
IF the remainder of n ÷ 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
END IF
ENDFlowchart: Start and End (rounded), INPUT n and the two OUTPUTs (parallelograms), and one decision diamond remainder of n ÷ 2 = 0? with Yes and No exits. It uses sequence and selection. Check: 14 → Even, 7 → Odd, 0 → Even.
: دەستپێک و کۆتایی (خڕ)، INPUT n و هەردوو OUTPUT (لاکێشەی لار)، هەروەها یەک شێوەی ئەڵماسیی بڕیار (remainder of n ÷ 2 = 0?، واتە ئایا سفرە؟) بە ڕێگای بەڵێ و نەخێر. ڕیزبەندی و هەڵبژاردن بەکار دەهێنێت. پشکنین: 14 دەبێت بە Even، 7 دەبێت بە Odd و 0 دەبێت بە Even.
Make a trace table for this pseudocode. What is the output, and what does the algorithm calculate?
بۆ ئەم دروست بکە. چییە و چی حیساب دەکات؟
result ← 0
count ← 0
WHILE count < 3 DO
result ← result + 4
count ← count + 1
END WHILE
OUTPUT resultShow answerوەڵامەکە پیشان بدە
| result | count | count < 3? |
|---|---|---|
| 0 | 0 | Yesبەڵێ |
| 4 | 1 | Yesبەڵێ |
| 8 | 2 | Yesبەڵێ |
| 12 | 3 | Noنەخێر |
The output is 12. The algorithm adds 4 three times, so it calculates : multiplication by repeated addition.
12ـە. سێ جار 4 زیاد دەکات، بۆیە حیساب دەکات: لێکدان بە کۆکردنەوەی دووبارە.
A student describes a flowchart: “Start → parallelogram ‘total ← 0’ → diamond ‘count < 10?’ with one arrow going down → rectangle ‘INPUT mark’ → back to the diamond.” List every error.
خوێندکارێک وەسف دەکات: «دەستپێک، لاکێشەی لاری ‹total ← 0›، شێوەی ئەڵماسیی ‹count < 10?› بە یەک تیر بەرەو خوارەوە، لاکێشەی ‹INPUT mark›، گەڕانەوە بۆ شێوە ئەڵماسییەکە.» هەموو هەڵەکان بژمێرە.
Show answerوەڵامەکە پیشان بدە
total ← 0is a process: it belongs in a rectangle, not a parallelogram.INPUT markis input: it belongs in a parallelogram.- The diamond needs two labelled exits; the No exit (leaving the loop) is missing.
- count is never set to 0 and never increased, so the loop could never end.
- There is no End.
total ← 0پرۆسەیە: شوێنی لە لاکێشەدایە، نەک لاکێشەی لار.INPUT mark: شوێنی لە لاکێشەی لاردایە.- شێوە ئەڵماسییەکە پێویستی بە دوو ڕێگای ناونووسکراوە؛ ڕێگای نەخێر (دەرچوون لە ) ونە.
- count هەرگیز ناکرێت بە 0 و هەرگیز زیاد ناکرێت، بۆیە هەرگیز کۆتایی نایەت.
- کۆتایی نییە.
A shop in the bazaar gives 10% off when the bill is more than 50000 dinars. Write the scenario, the algorithm in pseudocode and at least three test examples.
دوکانێک لە بازاڕدا کاتێک پسوولەکە زیاتر لە 50000 دینار بێت 10% داشکاندن دەکات. ، بە و لانیکەم سێ نموونەی تاقیکردنەوە بنووسە.
Show answerوەڵامەکە پیشان بدە
Scenario: the shopkeeper types the bill; the program shows the amount to pay. Bills over 50000 dinars get 10% off; other bills are unchanged.
: دوکاندارەکە بڕی پسوولەکە دەنووسێت؛ ئەو بڕەی دەبێت بدرێت پیشان دەدات. پسوولەی سەرووی 50000 دینار 10% داشکاندنی هەیە؛ پسوولەکانی تر وەک خۆیان دەمێننەوە.
START
INPUT bill
IF bill > 50000 THEN
pay ← bill − bill × 10 / 100
ELSE
pay ← bill
END IF
OUTPUT pay
END| Input | Output |
|---|---|
| 40000 | 40000 |
| 50000 | 50000 (not more than 50000)50000 (زیاتر نییە لە 50000) |
| 60000 | 54000 |
Extend the “largest so far” idea: write pseudocode that reads 10 numbers and outputs the largest. Use a loop.
بیرۆکەی «گەورەترینی تا ئێستا» فراوان بکە: بنووسە کە 10 ژمارە وەردەگرێت و گەورەترینیان دەردەدات. بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
START
INPUT number
largest ← number
count ← 1
WHILE count < 10 DO
INPUT number
IF number > largest THEN
largest ← number
END IF
count ← count + 1
END WHILE
OUTPUT largest
ENDThe first number starts as the largest, so the loop reads the other 9. It combines all three building blocks: sequence, selection inside repetition.
یەکەم ژمارە وەک گەورەترین دەست پێ دەکات، بۆیە 9 ژمارەکەی تر وەردەگرێت. هەر سێ بەردی بناغەکە تێکەڵ دەکات: ڕیزبەندی و هەڵبژاردن لە ناو دووبارەکردنەوەدا.
Exercisesڕاهێنانەکان
More practice: steps and decisionsڕاهێنانی زیاتر: هەنگاو و بڕیار
A carpet shop measures rooms in metres and centimetres, for example 4 m 25 cm by 3 m 60 cm. Write pseudocode that reads the length and the width (each as metres and centimetres) and outputs the area in square metres and the perimeter in centimetres.
دوکانێکی فەرش ژوورەکان بە مەتر و سانتیمەتر دەپێوێت، بۆ نموونە 4 مەتر و 25 سانتیمەتر لە 3 مەتر و 60 سانتیمەتر. بنووسە کە درێژی و پانی (هەر یەکەیان بە مەتر و سانتیمەتر) وەردەگرێت و ڕووبەر بە مەتری دووجا و چێوە بە سانتیمەتر دەردەدات.
Hintئاماژە
Turn each length into centimetres first: 4 m 25 cm = 425 cm. Then the calculation is the same as for one unit.
سەرەتا هەر درێژییەک بکە بە سانتیمەتر: 4 مەتر و 25 سانتیمەتر = 425 سانتیمەتر. پاشان حیسابەکە وەک ئەوەیە کە تەنها یەک یەکە هەبێت.
Show answerوەڵامەکە پیشان بدە
START
INPUT length_m, length_cm, width_m, width_cm
length ← length_m × 100 + length_cm
width ← width_m × 100 + width_cm
area ← length × width / 10000
perimeter ← 2 × (length + width)
OUTPUT area, perimeter
ENDCheck with 4 m 25 cm by 3 m 60 cm: cm², and because cm², the area is 15.3 m². The perimeter is cm, that is 15 m 70 cm.
بە 4 مەتر و 25 سانتیمەتر لە 3 مەتر و 60 سانتیمەتر بیپشکنە: سانتیمەتری دووجا و چونکە سانتیمەتری دووجایە، ڕووبەرەکە 15.3 مەتری دووجایە. چێوەکە سانتیمەترە، واتە 15 مەتر و 70 سانتیمەتر.
Draw a troubleshooting flowchart for a phone that will not charge. Ask at least three yes/no questions, for example: Is the charger in a socket that works? Does the phone charge with another cable? Does it charge with another charger?
بکێشە بۆ مۆبایلێک کە بارگە نابێت. لانیکەم سێ پرسیاری بەڵێ/نەخێر بکە، بۆ نموونە: ئایا بارگەکەرەکە لە پریزێکی کارادایە؟ ئایا مۆبایلەکە بە کێبڵێکی تر بارگە دەبێت؟ ئایا بە بارگەکەرێکی تر بارگە دەبێت؟
Hintئاماژە
Each diamond asks one question. Its Yes or No exit leads either to a fix (a rectangle, then End) or to the next question. Ask the cheapest and easiest question first.
هەر شێوەیەکی ئەڵماسی یەک پرسیار دەکات. ڕێگای بەڵێ یان نەخێرەکەی یان دەچێت بۆ چاککردنێک (لاکێشەیەک، پاشان کۆتایی) یان بۆ پرسیاری دواتر. سەرەتا هەرزانترین و ئاسانترین پرسیار بکە.
Show answerوەڵامەکە پیشان بدە
START
IF the charger is not in a working socket THEN
plug it into a socket that works
ELSE IF the phone charges with another cable THEN
replace the old cable
ELSE IF the phone charges with another charger THEN
replace the old charger
ELSE
take the phone to a repair shop
END IF
ENDIn the flowchart every IF is a diamond with labelled Yes and No exits, every action is a rectangle, and every path ends at End. Each question rules out one cause. Computers are fixed in the same way in Troubleshooting and Task Manager.
لە هەر IFـێک شێوەیەکی ئەڵماسییە بە ڕێگای ناونووسکراوی بەڵێ و نەخێر، هەر کارێک لاکێشەیە و هەموو ڕێگایەک بە کۆتایی دەگات. هەر پرسیارێک هۆیەک لادەبات. بە هەمان شێوە چاک دەکرێن لە چارەسەرکردنی کێشە و بەڕێوەبەری ئەرکەکان.
In a card game each player turns over one card. A card has a colour, green or yellow, and a number from 1 to 9. The rules: (1) a 9 beats every other card, and two 9s are a draw; (2) otherwise, if the colours are different, green wins; (3) otherwise the higher number wins; (4) the same colour and the same number is a draw. Write pseudocode that reads both cards and outputs “Player 1”, “Player 2” or “Draw”, then test it.
لە یارییەکی کارتدا هەر یاریزانێک کارتێک هەڵدەداتەوە. کارت ڕەنگێکی هەیە، سەوز یان زەرد و ژمارەیەک لە 1 تا 9. یاساکان: (1) 9 هەموو کارتێکی تر دەباتەوە و دوو 9 یەکسانن؛ (2) ئەگەرنا، ئەگەر ڕەنگەکان جیاواز بن، سەوز دەباتەوە؛ (3) ئەگەرنا ژمارە گەورەترەکە دەباتەوە؛ (4) هەمان ڕەنگ و هەمان ژمارە یەکسانە. بنووسە کە هەردوو کارتەکە وەردەگرێت و «Player 1»، «Player 2» یان «Draw» دەردەدات، پاشان تاقیی بکەرەوە.
Show answerوەڵامەکە پیشان بدە
START
INPUT colour1, number1, colour2, number2
IF number1 = 9 AND number2 = 9 THEN
OUTPUT "Draw"
ELSE IF number1 = 9 THEN
OUTPUT "Player 1"
ELSE IF number2 = 9 THEN
OUTPUT "Player 2"
ELSE IF colour1 ≠ colour2 THEN
IF colour1 = "green" THEN
OUTPUT "Player 1"
ELSE
OUTPUT "Player 2"
END IF
ELSE IF number1 > number2 THEN
OUTPUT "Player 1"
ELSE IF number2 > number1 THEN
OUTPUT "Player 2"
ELSE
OUTPUT "Draw"
END IF
END| Cardsکارتەکان | Output | Rule usedیاسای بەکارهاتوو |
|---|---|---|
| green 3, yellow 8سەوز 3، زەرد 8 | "Player 1" | (2) different colours(2) ڕەنگی جیاواز |
| yellow 9, green 5زەرد 9، سەوز 5 | "Player 1" | (1) a 9 wins(1) 9 دەباتەوە |
| yellow 4, yellow 7زەرد 4، زەرد 7 | "Player 2" | (3) higher number(3) ژمارەی گەورەتر |
| green 6, green 6سەوز 6، سەوز 6 | "Draw" | (4) same card(4) هەمان کارت |
The order of the IFs follows the order of the rules. If the colour test came first, a yellow 9 would lose to a green 2.
ڕیزبەندیی IFـەکان ڕیزبەندیی یاساکان پەیڕەو دەکات. ئەگەر پشکنینی ڕەنگ یەکەم بوایە، 9ـی زەرد بەرامبەر 2ـی سەوز دەیدۆڕاند.
An electricity company charges in steps (example prices, not a real tariff): the first 100 units cost 80 dinars each, the next 150 units 120 dinars each, and every unit above 250 costs 200 dinars. Every bill also has a fixed meter fee of 2000 dinars. Write pseudocode for the bill and test it with 90, 250 and 320 units.
کۆمپانیایەکی کارەبا بە پلە پارە وەردەگرێت (نرخی نموونەیی، نەک نرخی ڕاستەقینە): 100 یەکەی یەکەم هەر یەکەیەک 80 دینار، 150 یەکەی دواتر هەر یەکەیەک 120 دینار و هەر یەکەیەک لە سەرووی 250 بە 200 دینار. هەموو پسوولەیەکیش 2000 دینار کرێی جێگیری مەتەری هەیە. بۆ پسوولەکە بنووسە و بە 90، 250 و 320 یەکە تاقیی بکەرەوە.
Hintئاماژە
Only the units inside each step get that step’s price: for 320 units, 100 units at 80, 150 at 120 and the last 70 at 200.
تەنها ئەو یەکانەی لە ناو هەر پلەیەکدان نرخی ئەو پلەیە وەردەگرن: بۆ 320 یەکە، 100 یەکە بە 80، 150 بە 120 و 70ـی کۆتایی بە 200.
Show answerوەڵامەکە پیشان بدە
START
INPUT units
IF units ≤ 100 THEN
cost ← units × 80
ELSE IF units ≤ 250 THEN
cost ← 100 × 80 + (units − 100) × 120
ELSE
cost ← 100 × 80 + 150 × 120 + (units − 250) × 200
END IF
bill ← cost + 2000
OUTPUT bill
END| Unitsیەکە | Workingحیسابکردن | Bill (dinars)پسوولە (دینار) |
|---|---|---|
| 90 | 9200 | |
| 250 | 28000 | |
| 320 | 42000 |
A common mistake is to charge all 320 units at the top price (). Test the borders too: 100, 101, 250 and 251 units give 10000, 10120, 28000 and 28200 dinars.
هەڵەیەکی باو ئەوەیە هەموو 320 یەکەکە بە بەرزترین نرخ حیساب بکرێت (). سنوورەکانیش تاقی بکەرەوە: 100، 101، 250 و 251 یەکە دەدەن 10000، 10120، 28000 و 28200 دینار.
A three-digit number is an Armstrong number when the sum of the cubes of its digits equals the number itself: . Draw a flowchart, or write pseudocode, that reads a three-digit number and outputs whether it is an Armstrong number.
ژمارەیەکی سێ پێی دەوترێت ژمارەی Armstrong کاتێک کۆی سێجای یەکسان بێت بە خودی ژمارەکە: . بکێشە، یان بنووسە، کە ژمارەیەکی سێ وەردەگرێت و دەریدەخات ئایا ژمارەی Armstrongـە یان نا.
Hintئاماژە
Take the digits apart with whole-number division and the remainder: n DIV 10 is the whole part of (153 DIV 10 = 15) and n MOD 10 is the remainder (153 MOD 10 = 3). Python writes them // and %.
بە دابەشکردنی تەواو و لێک جیا بکەرەوە: n DIV 10 بەشی تەواوی ـە (153 DIV 10 = 15) و n MOD 10 (153 MOD 10 = 3). Python ئەمانە بە // و % دەنووسێت.
Show answerوەڵامەکە پیشان بدە
START
INPUT n
hundreds ← n DIV 100
tens ← (n DIV 10) MOD 10
ones ← n MOD 10
total ← hundreds × hundreds × hundreds + tens × tens × tens + ones × ones × ones
IF total = n THEN
OUTPUT "Armstrong number"
ELSE
OUTPUT "Not an Armstrong number"
END IF
ENDThe flowchart is a sequence of four process boxes followed by one decision. Check: 153 → 1, 5, 3 → : an Armstrong number. 254 → : not. The only three-digit Armstrong numbers are 153, 370, 371 and 407.
ڕیزێکە لە چوار لاکێشەی پرۆسە و پاشان یەک بڕیار. پشکنین: 153 دەبێت بە 1، 5، 3 و : ژمارەی Armstrongـە. 254: : نییە. تەنها ئەم ژمارە سێ ژمارەی Armstrongـن: 153، 370، 371 و 407.
Exercisesڕاهێنانەکان
More practice: loops and testingڕاهێنانی زیاتر: خولەکان و تاقیکردنەوە
Aram and Shilan flip a coin to decide who sits in the front seat of the car. They flip up to five times, and the first to win three flips gets the seat. For each flip the input is 1 (Aram won it) or 2 (Shilan won it). Write pseudocode that outputs the winner.
ئارام و شیلان دراو هەڵدەدەن بۆ ئەوەی بڕیار بدەن کێ لە کورسیی پێشەوەی ئۆتۆمبێلەکە دادەنیشێت. تا پێنج جار هەڵیدەدەن و یەکەم کەس کە سێ جار بیباتەوە کورسییەکە وەردەگرێت. بۆ هەر هەڵدانێک 1ـە (ئارام بردییەوە) یان 2 (شیلان بردییەوە). بنووسە کە براوەکە دەردەدات.
Hintئاماژە
Use two counters, one for each person, and repeat while both are below 3.
دوو بەکار بهێنە، یەکێک بۆ هەر کەسێک و دووبارەی بکەرەوە مادام هەردووکیان لە 3 کەمترن.
Show answerوەڵامەکە پیشان بدە
START
wins_aram ← 0
wins_shilan ← 0
WHILE wins_aram < 3 AND wins_shilan < 3 DO
INPUT flip
IF flip = 1 THEN
wins_aram ← wins_aram + 1
ELSE
wins_shilan ← wins_shilan + 1
END IF
END WHILE
IF wins_aram = 3 THEN
OUTPUT "Aram"
ELSE
OUTPUT "Shilan"
END IF
ENDFive flips are always enough: after five flips one of them has at least three wins, so the loop never needs a sixth. Trace 1, 2, 2, 1, 1: after five flips Aram has 3 and Shilan 2, so the output is Aram. With 2, 2, 2 the loop stops after three flips: Shilan.
پێنج هەڵدان هەمیشە بەسە: دوای پێنج هەڵدان یەکێکیان لانیکەم سێ جار بردوویەتییەوە، بۆیە هەرگیز پێویستی بە شەشەم نییە. بەدوای 1، 2، 2، 1، 1دا بچۆ: دوای پێنج هەڵدان ئارام 3ـی هەیە و شیلان 2، بۆیە ئارامە. بە 2، 2، 2 دوای سێ هەڵدان دەوەستێت: شیلان.
A class collects 100000 dinars for a trip. Each gift is 5000, 10000 or 25000 dinars. Write pseudocode that keeps reading gifts until the total reaches 100000, then outputs the total and the number of gifts.
پۆلێک 100000 دینار بۆ گەشتێک کۆ دەکاتەوە. هەر بەخششێک 5000، 10000 یان 25000 دینارە. بنووسە کە بەردەوام بەخشش وەردەگرێت تا کۆکە دەگاتە 100000، پاشان کۆکە و ژمارەی بەخششەکان دەردەدات.
Show answerوەڵامەکە پیشان بدە
START
total ← 0
gifts ← 0
WHILE total < 100000 DO
INPUT gift
total ← total + gift
gifts ← gifts + 1
END WHILE
OUTPUT total, gifts
ENDThe loop does not know in advance how many times it will run; it stops when total < 100000 becomes false. The total can go past the target: with the gifts 25000, 10000, 25000, 5000, 25000 and 25000 the output is 115000 after 6 gifts.
پێشوەختە نازانێت چەند جار دووبارە دەبێتەوە؛ کاتێک total < 100000 هەڵە دەبێت دەوەستێت. کۆکە دەکرێت لە ئامانجەکە تێپەڕێت: بە بەخششەکانی 25000، 10000، 25000، 5000، 25000 و 25000، دوای 6 بەخشش 115000ـە.
The least common multiple (LCM) of two whole numbers is the smallest number that both of them divide exactly: the LCM of 4 and 6 is 12. Write an algorithm that reads two positive whole numbers and outputs their LCM.
LCMـی دوو بچووکترین ژمارەیە کە هەردووکیان بە تەواوی دابەشی دەکەن: LCMـی 4 و 6 دەکاتە 12. بنووسە کە دوو موجەب وەردەگرێت و LCMـەکەیان دەردەدات.
Hintئاماژە
Start with the larger number and keep adding it to itself until the smaller number divides the result exactly.
بە ژمارە گەورەکە دەست پێ بکە و بەردەوام بیخەرە سەر خۆی تا ژمارە بچووکەکە ئەنجامەکە بە تەواوی دابەش دەکات.
Show answerوەڵامەکە پیشان بدە
START
INPUT a, b
IF a > b THEN
big ← a
small ← b
ELSE
big ← b
small ← a
END IF
multiple ← big
WHILE the remainder of multiple ÷ small ≠ 0 DO
multiple ← multiple + big
END WHILE
OUTPUT multiple
ENDTrace 4 and 6: big = 6 and small = 4; 6 ÷ 4 leaves 2, so try 12; 12 ÷ 4 leaves 0, so the output is 12. Also check 5 and 7 (35) and 6 and 6 (6). The twin problem is the greatest common divisor (GCD), written as a Python function in Modules and import; with it, .
بەدوای 4 و 6دا بچۆ: big = 6 و small = 4؛ دابەشکردنی 6 بەسەر 4دا 2ـی هەیە، بۆیە 12 تاقی بکەرەوە؛ 12 بەسەر 4دا 0ـی هەیە، بۆیە 12ـە. 5 و 7 (35) و 6 و 6 (6)ـیش بپشکنە. کێشە جمکەکەی GCDـە (گەورەترین ژمارە کە هەردووکیان دابەش دەکات)، کە لە مۆدیوڵەکان و import وەک Python نووسراوە؛ بەو، .
A bus has seats numbered 1 to 40. Seats 1–10 are “Front”, seats 11–40 are “Back”, and any other number is “No such seat”. A student wrote the algorithm below. (a) Choose test values on and next to every border. (b) Which of them give a wrong answer? (c) Correct the algorithm.
پاسێک کورسیی ژمارە 1 تا 40ـی هەیە. کورسییەکانی 1 تا 10 «Front»ـن، کورسییەکانی 11 تا 40 «Back»ـن و هەر ژمارەیەکی تر «No such seat»ـە. خوێندکارێک ئەم خوارەوەی نووسیوە. (أ) تاقیکردنەوە لەسەر هەموو سنوورێک و لە تەنیشتیان هەڵبژێرە. (ب) کامیان وەڵامی هەڵە دەدەن؟ (ج) ڕاست بکەرەوە.
INPUT seat
IF seat ≥ 0 AND seat ≤ 40 THEN
IF seat < 10 THEN
OUTPUT "Front"
ELSE
OUTPUT "Back"
END IF
ELSE
OUTPUT "No such seat"
END IFShow answerوەڵامەکە پیشان بدە
| Seatکورسی | Output | Right?دروستە؟ |
|---|---|---|
| "No such seat" | yesبەڵێ | |
| 0 | "Front" | no: there is no seat 0نەخێر: کورسیی 0 نییە |
| 1 | "Front" | yesبەڵێ |
| 10 | "Back" | no: seat 10 is at the frontنەخێر: کورسیی 10 لە پێشەوەیە |
| 11 | "Back" | yesبەڵێ |
| 40 | "Back" | yesبەڵێ |
| 41 | "No such seat" | yesبەڵێ |
Correct the two borders: IF seat ≥ 1 AND seat ≤ 40 THEN and IF seat ≤ 10 THEN. Easy values such as 5 and 25 pass and hide both mistakes. Mistakes live at the borders, so test each border and the numbers just inside and just outside it.
هەردوو سنوورەکە ڕاست بکەرەوە: IF seat ≥ 1 AND seat ≤ 40 THEN و IF seat ≤ 10 THEN. ئاسانەکانی وەک 5 و 25 تێدەپەڕن و هەردوو هەڵەکە دەشارنەوە. هەڵەکان لە سنوورەکاندا دەژین، بۆیە هەر سنوورێک و ئەو ژمارانەی ڕێک لە ناوەوە و ڕێک لە دەرەوەیدان تاقی بکەرەوە.
Summaryپوختە
- An algorithm is a finite list of clear, ordered steps from input to output.
- Pseudocode writes the steps as structured lines for people; flowcharts draw them with standard ISO 5807 symbols.
- Terminal, process, input/output, decision, flow line, predefined process and connector each have one shape.
- Every algorithm is built from sequence, selection and repetition.
- A trace table checks an algorithm by hand; always try equal values and borders.
- A project plan: scenario → flowchart → algorithm → code → examples.
- A good algorithm also gives the same output for the same input every time.
- Test the borders and the values next to them: they find mistakes that easy values hide.
- Algorithms for the same problem are compared by time (time complexity) and memory (space complexity); you can often trade one for the other.
- Decomposition breaks a big problem into smaller ones (top-down or bottom-up); the pieces are tested alone, then together.
- لیستێکی کۆتاییداری هەنگاوی ڕوون و ڕیزکراوە لە بۆ .
- هەنگاوەکان وەک دێڕی ڕێکخراو بۆ مرۆڤ دەنووسێت؛ بە هێما ستانداردەکانی ISO 5807 دەیانکێشێت.
- دەستپێک و کۆتایی، پرۆسە، /، بڕیار، هێڵی ڕەوت، پرۆسەی ئامادە و گەیەنەر هەر یەکێکیان شێوەیەکی هەیە.
- هەموو لە ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە دروست دەکرێت.
- بە دەست دەپشکنێت؛ هەمیشە یەکسانەکان و سنوورەکان تاقی بکەرەوە.
- پلانی پڕۆژە: ، ، ، کۆد، نموونەکان.
- باش هەروەها هەموو جارێک بۆ هەمان هەمان دەدات.
- سنوورەکان و ئەو لە تەنیشتیانن تاقی بکەرەوە: ئەو هەڵانە دەدۆزنەوە کە ئاسانەکان دەیانشارنەوە.
- بۆ هەمان کێشە بە کات () و () بەراورد دەکرێن؛ زۆرجار دەکرێت یەکێکیان بە ئەوی تر بگۆڕیتەوە.
- کێشەیەکی گەورە دەکات بە کێشەی بچووکتر ( یان )؛ پارچەکان سەرەتا بە تەنها و پاشان پێکەوە تاقی دەکرێنەوە.
What are the three building blocks of every algorithm?سێ بەردی بناغەی هەموو ئەلگۆریزمێک چین؟
Sequence, selection and repetition.
ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە.
Which flowchart shape is used for a yes/no question, and how many exits does it have?کام شێوەی هێڵکاریی ڕەوت بۆ پرسیاری بەڵێ/نەخێر بەکار دێت و چەند ڕێگای دەرچوونی هەیە؟
A diamond, with two labelled exits: Yes and No.
شێوەی ئەڵماسی، بە دوو ڕێگای ناونووسکراو: بەڵێ و نەخێر.
Why must a counter change inside a loop?بۆچی دەبێت ژمێرەر لە ناو خولدا بگۆڕێت؟
Otherwise the loop condition never becomes false and the loop never ends.
ئەگەرنا هەرگیز هەڵە نابێت و هەرگیز کۆتایی نایەت.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Learn what an algorithm is with an everyday counting example, how a loop repeats steps, and how to write the steps as pseudocode.
بە نموونەیەکی ڕۆژانەی ژماردن فێردەبیت چییە، چۆن هەنگاوەکان دووبارە دەکاتەوە و چۆن هەنگاوەکان وەک بنووسیت.
Whole video (4:57): an algorithm (0:14), a loop (1:13), the faster algorithm in pseudocode (2:39). Kurdish subtitles are available.
هەموو ڤیدیۆکە (4:57): (0:14)، (1:13) و خێراترەکە بە (2:39). ژێرنووسی کوردیشی هەیە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Related lecturesوانە پەیوەندیدارەکان
- How Code Becomes a Running Program: Compilers and Interpretersچۆن کۆد دەبێت بە بەرنامەیەک کە کار دەکات: کۆمپایلەرەکان و ئینتەرپرێتەرەکان
- Programming Languages and Algorithmsزمانەکانی بەرنامەسازی و ئەلگۆریزمەکان
- Agent Programs, Pseudocode and Algorithm Analysisبەرنامەکانی ئەیجێنت، نیمچەکۆد و شیکارکردنی ئەلگۆریزم
- Project: Binary to Decimal Converterپڕۆژیلە: گۆڕینی دووانی بۆ دەیی
- Errors and Debuggingهەڵەکان و کرمەکوژی
- Defining and Calling Functionsناساندن و بانگکردنی کردارەکان
- Troubleshooting and Task Managerچارەسەرکردنی کێشە و بەڕێوەبەری ئەرکەکان
- Modules and importمۆدیوڵەکان و import
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Harvard CS50x 2026, lecture notes week 0 (algorithms, pseudocode, the phone-book example)
- Wikipedia: Algorithm (definition, al-Khwarizmi)
- Wikipedia: Pseudocode (no single standard)
- Wikipedia: Flowchart (ISO 5807 symbols, Gilbreth 1921)
- Wikipedia: Structured program theorem (Böhm–Jacopini, 1966)
- Wikipedia: Primality test (trial division only up to the square root; dividing only by stored primes)
- Wikipedia: Top-down and bottom-up design (stepwise refinement, decomposition, combining both)
- Wikipedia: Boundary-value analysis (test on, just below and just above each border)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.