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.

پلاندانان پێش کۆدنووسین: چییە و چی باشی دەکات، نووسینی بە ، کێشانی بە هێما ستانداردەکانی ، سێ بەردی بناغە (ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە)، پشکنینی بە و تاقیکردنەوەی سنوورەکان، بەراوردکردنی بە کات و ، کێشە گەورەکان و پلانێکی پێنج بەشی بۆ ، هەمووی بەبێ هیچ .

32 min read34 خولەک خوێندنەوە · 26 stepsهەنگاو

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 هەموویان ڕۆژانەن.

Definitionپێناسە

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.”

بۆ نموونە، ئەمە بە وشەی ئاسایی بۆ دۆزینەوەی گەورەترینی سێ ژمارە: «یەکەم ژمارە وەک گەورەترینی تا ئێستا لەبیر بگرە. سەیری ژمارەی دووەم بکە؛ ئەگەر گەورەتر بوو، لە جیاتی ئەو ئەمیان لەبیر بگرە. هەمان کار بە ژمارەی سێیەم بکە. ئەو ژمارەیە بڵێ کە لەبیرتە.»

Quick checkپشکنینی خێراWhich of these is an algorithm?کام لەمانە ؟

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 زیاد بکە» هەرگیز کۆتایی نایەت.
  • و هەیە: دەڵێت بە چی دەست پێ دەکات و چی دەداتەوە.
  • هەمان ، هەمان ئەنجام: ئەنجامی هەر هەنگاوێک تەنها بە و هەنگاوەکانی پێشوویەوە بەندە، بۆیە هەمان هەمیشە هەمان دەدات.
  • جێبەجێکراو: هەموو هەنگاوێک بەڕاستی دەکرێت، لەلایەن مرۆڤێک بە قەڵەم و کاغەز یان لەلایەن .
Quick checkپشکنینی خێرا“Stir the soup until it tastes good.” Which property of a good algorithm does this step break?«شۆربەکە تێک بدە تا تامی خۆش دەبێت.» ئەم هەنگاوە کام تایبەتمەندیی باش دەشکێنێت؟

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 بۆ دووبارەکردنەوە. لە هەموو زمانێکدا بە ئینگلیزی دەمێننەوە، چونکە دواتر دەبن بە کۆدی ڕاستەقینە.

Largest of three numbers in pseudocodeگەورەترینی سێ ژمارە بە نیمچەکۆدTEXT
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
END
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

largest ← a means: store the value of a in largest.

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#⁩ بنووسرێن. کتێبەکانی ڕێکەوتنی تایبەت بە خۆیان هەیە؛ ئەوانە لە خوێندنەوەی نیمچەکۆدی ژیریی دەستکرد ڕوون کراونەتەوە.

Quick checkپشکنینی خێراWhat does total ← 0 mean in pseudocode?total ← 0 لە واتای چییە؟

5 Minutes to Code: Programming Basics "Pseudocode"5toCode · Englishئینگلیزی · 378K viewsبینین · 5.7K likesلایک · Partبەشی 0:50–3:01 (ofلە 5:00)

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)⁩دا دیاری کراون.

Seven flowchart symbols. Terminal: a rounded shape marked Start, where the algorithm starts or stops. Process: a rectangle with total ← total + mark, a calculation or an action. Input/Output: a parallelogram with INPUT mark, data comes in or goes out. Decision: a diamond with mark ≥ 50?, a yes/no question with two exits. Flow line: an arrow that shows the order of the steps. Predefined process: a rectangle with double side lines, Find average, a named sub-algorithm drawn somewhere else. Connector: a small circle with the letter A that joins two parts of a large flowchart.حەوت هێمای هێڵکاریی ڕەوت. دەستپێک و کۆتایی: شێوەیەکی خڕکراو کە دەستپێکی لەسەر نووسراوە، ئەو شوێنەی ئەلگۆریزمەکە تێیدا دەست پێ دەکات یان دەوەستێت. پرۆسە: لاکێشەیەک بە total ← total + mark، حیسابکردن یان کارێک. نێوخستە/دەرخستە: لاکێشەیەکی لار بە INPUT mark، دراوە دێتە ژوورەوە یان دەچێتە دەرەوە. بڕیار: شێوەیەکی ئەڵماسی بە mark ≥ 50?، پرسیارێکی بەڵێ/نەخێر بە دوو ڕێگای دەرچوون. هێڵی ڕەوت: تیرێک کە ڕیزبەندیی هەنگاوەکان پیشان دەدات. پرۆسەی ئامادە: لاکێشەیەک بە دوو هێڵی لاتەنیشت، دۆزینەوەی تێکڕا، ئەلگۆریزمێکی بچووکی ناودار کە لە شوێنێکی تر کێشراوە. گەیەنەر: بازنەیەکی بچووک بە پیتی A کە دوو بەشی هێڵکارییەکی ڕەوت گەورە بەیەکەوە دەبەستێت.
The seven standard flowchart symbols.حەوت هێما ستانداردەکەی .CêIT
Flowchart symbols at a glanceهێماکانی بە کورتی
ShapeشێوەNameناوUse it forبۆ چی بەکاری دەهێنیت
rounded rectangle (oval)لاکێشەی خڕ (هێلکەیی)terminalStart and Endدەستپێک و کۆتایی
rectangleلاکێشەprocessa calculation or action, such as total ← total + markحیسابکردن یان کارێک، وەک total ← total + mark
parallelogramلاکێشەی لارinput/outputreading data in or showing a resultوەرگرتنی یان پیشاندانی ئەنجام
diamondئەڵماسیdecisiona yes/no question; two labelled exitsپرسیارێکی بەڵێ/نەخێر؛ دوو ڕێگای دەرچوونی ناونووسکراو
arrowتیرflow linethe order of the stepsڕیزبەندیی هەنگاوەکان
rectangle with double sidesلاکێشە بە دوو هێڵی لاتەنیشتpredefined processa named sub-algorithm drawn in its own flowchart بچووکی ناودار کە لە جیادا کێشراوە
small circle with a letterبازنەیەکی بچووک بە پیتێکconnectorjoining parts of a flowchart that do not fit together, for example on the next pageبەستنەوەی بەشەکانی کە پێکەوە جێیان نابێتەوە، بۆ نموونە لە لاپەڕەی دواتردا
Quick checkپشکنینی خێراWhich symbol do you draw for “Is the mark 50 or more?”بۆ «ئایا نمرەکە ⁦50⁩ یان زیاترە؟» کام هێما دەکێشیت؟

5 Minutes to Code: Programming Basics "Flow Charts"5toCode · Englishئینگلیزی · 74K viewsبینین · 1.2K likesلایک · Partبەشی 0:50–4:38 (ofلە 5:00)

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.
  • ڕێک یەک دەستپێک و لانیکەم یەک کۆتایی.
  • ڕەوت لە سەرەوە بۆ خوارەوە و لە چەپەوە بۆ ڕاست دەڕوات؛ تیرەکان هەر ئاڕاستەیەکی تر پیشان دەدەن.
  • بڕیار ڕێک دوو ڕێگای دەرچوونی هەیە کە بە بەڵێ و نەخێر ناونووس کراون.
  • کاری کورت بە وشە یان بە بنووسە، نەک دێڕی تەواوی ڕاستەقینە.
  • شێوەی دروست بەکار بهێنە: حیسابکردن لە لاکێشەدا، و لە لاکێشەی لاردا.
  • خۆت لە هێڵی بەیەکداچوو بپارێزە؛ کاتێک بۆ یەک لاپەڕە زۆر گەورەیە گەیەنەر بەکار بهێنە.
Quick checkپشکنینی خێراA student draws a decision diamond with only one arrow leaving it. What is wrong?خوێندکارێک شێوەیەکی ئەڵماسیی بڕیار دەکێشێت کە تەنها یەک تیری لێ دەردەچێت. چی هەڵەیە؟

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)، پێی دەوترێت .
Three small flowcharts. Sequence: INPUT mark, then mark ← mark + 5, then OUTPUT mark, one after another. Selection: a diamond asks mark ≥ 50?; Yes leads to OUTPUT "Pass", No leads to OUTPUT "Fail"; both paths meet again below. Repetition: a diamond asks more marks?; Yes leads to INPUT mark and total ← total + mark, then an arrow goes back to the question; No leads to End.سێ هێڵکاریی ڕەوتی بچووک. ڕیزبەندی: INPUT mark، پاشان mark ← mark + 5، پاشان OUTPUT mark، یەک لە دوای یەک. هەڵبژاردن: شێوەیەکی ئەڵماسی دەپرسێت mark ≥ 50?؛ بەڵێ دەچێت بۆ OUTPUT "Pass"، نەخێر دەچێت بۆ OUTPUT "Fail"؛ هەردوو ڕێگا لە خوارەوە دەگەنەوە یەک. دووبارەکردنەوە: شێوەیەکی ئەڵماسی دەپرسێت more marks?؛ بەڵێ دەچێت بۆ INPUT mark و total ← total + mark، پاشان تیرێک دەگەڕێتەوە بۆ پرسیارەکە؛ نەخێر دەچێت بۆ کۆتایی.
Sequence, selection and repetition — the three control structures.ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە: .CêIT

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#⁩) وشەی خۆی بۆیان هەیە، بەڵام بیرۆکەکان وەک یەکن.

Quick checkپشکنینی خێرا“Keep asking for the PIN until it is correct.” Which building block is this?«بەردەوام داوای PIN بکە تا دروست دەبێت.» ئەمە کام بەردی بناغەیە؟

Computer Science Basics: Sequences, Selections, and LoopsLearnFree · Englishئینگلیزی · 430K viewsبینین · 6.5K likesلایک

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ـدا هەڵبگرە و هەر کاتێک ژمارەیەکی گەورەترت دۆزییەوە بیگۆڕە. هەمان بە لە شاشەی نیمچەکۆددایە.

A flowchart: Start → INPUT a, b, c → largest ← a → decision b > largest? Yes: largest ← b; No: skip. Both paths join → decision c > largest? Yes: largest ← c; No: skip. Both paths join → OUTPUT largest → End. A note says: try it with 7, 12, 9 and the answer is 12.هێڵکارییەکی ڕەوت: دەستپێک، INPUT a, b, c، largest ← a، بڕیاری b > largest? بەڵێ: largest ← b؛ نەخێر: تێپەڕ بە. هەردوو ڕێگا دەگەنەوە یەک، بڕیاری c > largest? بەڵێ: largest ← c؛ نەخێر: تێپەڕ بە. هەردوو ڕێگا دەگەنەوە یەک، OUTPUT largest، کۆتایی. تێبینییەک دەڵێت: بە 7، 12، 9 تاقی بکەرەوە و وەڵامەکە 12ـە.
Largest of three numbers: one value is remembered and replaced when a bigger one appears.گەورەترینی سێ ژمارە: یەک لەبیر دەگیرێت و کاتێک گەورەتر دەرکەوت دەگۆڕدرێت.CêIT
Quick checkپشکنینی خێراWith the input 4, 9, 2, how many times is largest given a new value after largest ← a?بە 4، 9، 2، دوای largest ← a چەند جار نوێ دەدرێتە 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.

هەڵەیەک لە گواستنەوەی پارەی بانکێکدا دەکرێت تەنها نیوەی پارەکە بنێرێت؛ لە نەخۆشخانە یان فڕۆکەدا هەڵەیەک دەکرێت زیان بە خەڵک بگەیەنێت. بۆیە پێش ئەوەی کەس متمانەی پێ بکات، دەبێت لە هەموو بارێکدا بپشکنرێت. چۆن، پێش ئەوەی هیچ کۆدێک هەبێت؟ بەدوایدا دەچیت: بە دەست و بە ڕاستەقینە شوێن هەنگاوەکان دەکەویت و هەموو گۆڕانکارییەک لە دەنووسیت: ستوونێک بۆ هەر و ڕیزێک بۆ هەر هەنگاوێک.

Definitionپێناسە

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.

خشتەیەکە بە دەست پڕی دەکەیتەوە بۆ ئەوەی هەنگاو بە هەنگاو بەدوای یان بچیت: ستوونێک بۆ هەر و بۆ ، هەروەها ڕیزێک بۆ هەر هەنگاوێک. بە وردی پیشان دەدات لە کوێدا ڕوو دەدات.

Trace of the input 7, 12, 9بەدواداچوونی 7، ⁦12⁩، 9
StepهەنگاوabclargestOutput
INPUT a, b, c7129
largest ← a7
b > largest? 12>712 > 7: Yesb > largest? 12>712 > 7: بەڵێ12
c > largest? 9>129 > 12: Noc > largest? 9>129 > 12: نەخێر12
OUTPUT largest12

Now trace a harder case, 5, 5, 3, where two numbers are equal: largest starts as 5; is 5>55 > 5? No; is 3>53 > 5? 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>55 > 5؟ نەخێر؛ ئایا 3>53 > 5؟ نەخێر؛ 5ـە. دروستە. تاقیکەرەوەی باش هەمیشە یەکسانەکان، بچووکترین و گەورەترین و نائاسایی تاقی دەکاتەوە. لە ڕێڕەوی Pythonـدا بۆ دۆزینەوەی لە کۆدی ڕاستەقینەدا بەکار دەهێنیت: هەڵەکان و کرمەکوژی.

Quick checkپشکنینی خێراWhat goes in each column of a trace table?لە هەر ستوونێکی چی دەنووسرێت؟

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 بەدوایدا بچۆ.

A tempting but wrong versionوەشانێکی سەرنجڕاکێش بەڵام هەڵەTEXT
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
END
Explain 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. بە >= لە هەردوو پشکنینەکەدا چاکی بکە، یان وەشانی «گەورەترینی تا ئێستا»ی ناو بەکار بهێنە کە بە سروشتی ژمارەی یەکسان چارەسەر دەکات. ڕێک بۆ ئەمە بە نائاسایی بەدوای دەچین.

Quick checkپشکنینی خێراWhat does the tempting version output for 5, 5, 3?وەشانە سەرنجڕاکێشەکە بۆ 5، 5، 3 چی دەردەدات؟

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⁩ خولەک پیشان نادات. یەک حاڵەتی تاقیکردنەوە بەس بوو بۆ شکاندنی. دێڕە ڕەنگکراوەکان چاکی دەکەن:

Adding two times in pseudocodeکۆکردنەوەی دوو کات بە نیمچەکۆدTEXT
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
END

Now 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⁩ زیاتر نابێت.

Quick checkپشکنینی خێراIf the test were written minutes > 60, what would 0 h 45 min + 0 h 15 min give?ئەگەر پشکنینەکە بە minutes > 60 بنووسرایە، 0 کاتژمێر و ⁦45⁩ خولەک لەگەڵ 0 کاتژمێر و ⁦15⁩ خولەک چی دەدا؟

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؛ دوای نمرەی پێنجەم هەڵە دەبێت و لە دەردەچێت.

Average of five marks in pseudocodeتێکڕای پێنج نمرە بە نیمچەکۆدTEXT
START
total ← 0
count ← 0
WHILE count < 5 DO
    INPUT mark
    total ← total + mark
    count ← count + 1
END WHILE
average ← total / 5
OUTPUT average
END
Explain 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 دەمێنێتەوە و هەرگیز کۆتایی نایەت.

A flowchart: Start → total ← 0, count ← 0 → decision count < 5? Yes leads down to INPUT mark → total ← total + mark → count ← count + 1, and an arrow goes back up to the decision. No leads right to average ← total / 5 → OUTPUT average → End.هێڵکارییەکی ڕەوت: دەستپێک، total ← 0، count ← 0، بڕیاری count < 5? بەڵێ دەچێت بۆ خوارەوە بۆ INPUT mark، total ← total + mark، count ← count + 1 و تیرێک دەگەڕێتەوە بۆ سەرەوە بۆ بڕیارەکە. نەخێر دەچێت بۆ لای ڕاست بۆ average ← total / 5، OUTPUT average، کۆتایی.
Average of five marks: a loop with a counter and an accumulator.تێکڕای پێنج نمرە: بە و .CêIT
Trace with the marks 8, 6, 10, 7, 9: the average is 40/5=840 / 5 = 8بەدواداچوون بە نمرەکانی 8، 6، ⁦10⁩، 7، 9: تێکڕاکە 40/5=840 / 5 = 8
After readingدوای وەرگرتنیmarktotalcountcount < 5?
(start)(دەستپێک)–00Yesبەڵێ
1st markنمرەی یەکەم881Yesبەڵێ
2nd markنمرەی دووەم6142Yesبەڵێ
3rd markنمرەی سێیەم10243Yesبەڵێ
4th markنمرەی چوارەم7314Yesبەڵێ
5th markنمرەی پێنجەم9405No: leave the loopنەخێر: لە دەربچۆ
Quick checkپشکنینی خێراWhat happens if the step count ← count + 1 is forgotten?ئەگەر هەنگاوی count ← count + 1 لەبیر بچێت چی ڕوو دەدات؟

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 جێبەجێ دەبێت. شێوە ڕەنگکراوەکە ئەو هەنگاوەیە کە ئێستا جێبەجێ دەبێت و چوارگۆشەکەی لای ڕاست دوای ئەو هەنگاوە پیشان دەدات.

An animation of the average flowchart in ten steps, with a box of variables. Start. total and count are set to 0. Is 0 < 5? Yes, go down. The first mark, 8, is read. total = 0 + 8 = 8 and count = 1, and the arrow goes back to the question. Four more times with 6, 10, 7 and 9: total = 40, count = 5. Is 5 < 5? No, leave the loop. average = 40 / 5 = 8. Output 8. End: the average of the five marks is 8.
An animation of the average flowchart in ten steps, with a box of variables. Start. total and count are set to 0. Is 0 < 5? Yes, go down. The first mark, 8, is read. total = 0 + 8 = 8 and count = 1, and the arrow goes back to the question. Four more times with 6, 10, 7 and 9: total = 40, count = 5. Is 5 < 5? No, leave the loop. average = 40 / 5 = 8. Output 8. End: the average of the five marks is 8.
Following the flowchart: the loop runs five times, then the average is calculated.شوێنکەوتنی : پێنج جار دووبارە دەبێتەوە، پاشان تێکڕاکە حیساب دەکرێت.CêIT
Quick checkپشکنینی خێراHow many times is the question count < 5? asked in this run?لەم جێبەجێکردنەدا پرسیاری count < 5? چەند جار دەکرێت؟

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 n=97n = 97ژمارەی دابەشکردن بۆ n=97n = 97
1. every number from 2 to n−1n - 11. هەموو ژمارەیەک لە 2ـەوە تا n−1n - 195
2. only up to half of n: apart from n itself, no divisor is bigger than n÷2n \div 22. تەنها تا نیوەی n: جگە لە خودی n، هیچ دابەشکەرێک لە n÷2n \div 2 گەورەتر نییە47
3. only up to n\sqrt{n}: if n=a×bn = a \times b, the smaller of a and b is at most n\sqrt{n}3. تەنها تا n\sqrt{n}: ئەگەر n=a×bn = a \times b، بچووکترینی a و b لە n\sqrt{n} گەورەتر نییە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 91=7×1391 = 7 \times 13.

هەر چواریان هەمان وەڵام دەدەن. بۆ ⁦97⁩ بە ڕیز ⁦95⁩، ⁦47⁩، 8 و ⁦24⁩ دابەشکردن دەکەن: ⁦97⁩ سەرەتاییە، بۆیە هیچ ژمارەیەک دابەشی ناکات و هەر ڕێگایەک دەبێت هەموو لیستەکەی تاقی بکاتەوە. ئەمە . بۆ ⁦91⁩ هەموو ڕێگاکان لە 7دا دەوەستن، چونکە 91=7×1391 = 7 \times 13.

Quick checkپشکنینی خێراMethod 3 checks 97 with the divisors 2 to 9 only. Why is that enough?ڕێگای 3 تەنها بە دابەشکەرەکانی 2 تا 9 ژمارەی ⁦97⁩ دەپشکنێت. بۆچی ئەمە بەسە؟

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 97\sqrt{97}, that is 2, 3, 5 and 7 — and 4 divisions are enough.

ڕێگای 3 خێراترینی هەر چوارەکەیە و جیاوازییەکە لەگەڵ گەورەبوونی n زیاد دەبێت: بۆ ⁦1009⁩ لە جیاتی ⁦1007⁩ دابەشکردن تەنها ⁦30⁩ دەکات. ڕێگای 4 لە ڕێگاکانی 1 و 2 دابەشکردنی کەمترە، بەڵام دەبێت سەرەتا لیستی ژمارە سەرەتاییەکان لە هەڵبگیرێت. ڕێگاکانی 3 و 4 تێکەڵ بکە، واتە تەنها بەسەر ئەو ژمارە سەرەتاییە هەڵگیراوانەدا دابەش بکە کە تا 97\sqrt{97}ن (⁦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⁩ دەپێوێت: ئاڵۆزیی کات و ئاڵۆزیی بیرگە.

Quick checkپشکنینی خێراMethod 4 does fewer divisions than methods 1 and 2. What does it need in exchange?ڕێگای 4 لە ڕێگاکانی 1 و 2 دابەشکردنی کەمتر دەکات. لە بەرامبەردا پێویستی بە چییە؟

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:

بۆ ، کۆرسەکە پلانێکی سادەی پێنج بەشی بەکار هێنا. گرووپێکی قۆناغی یەکەم بۆ دروستکردنی گۆڕەرێکی بۆ پەیڕەوی کرد و تۆش دەتوانیت بۆ هەر بەکاری بهێنیت:

The five partsپێنج بەشەکە
  1. Scenarioنەخشەنامە

    Describe the aim of the project in plain words: what the program is for and how a user will use it.

    ئامانجی پڕۆژەکە بە وشەی ئاسایی باس بکە: بۆ چییە و چۆن بەکاری دەهێنێت.

  2. Flowchartهێڵکاریی ڕەوت

    Draw how the program works, with the standard symbols.

    بە هێما ستانداردەکان بیکێشە کە چۆن کار دەکات.

  3. Algorithmئەلگۆریزم

    Write the steps of the program from the very beginning, numbered, in words or pseudocode.

    هەنگاوەکانی لە سەرەتاوە، بە ژمارە، بە وشە یان بە بنووسە.

  4. Codeکۆد

    Write the source code in your programming language, following the algorithm.

    بە پەیڕەوکردنی ، بە بنووسە.

  5. Examplesنموونەکان

    Run the program on several examples and show the results, to prove that it works.

    لەسەر چەند نموونەیەک جێبەجێ بکە و ئەنجامەکان پیشان بدە، بۆ سەلماندنی ئەوەی کار دەکات.

Five numbered boxes joined by arrows: 1 Scenario, the aim of the program in words; 2 Flowchart, a picture of how it works; 3 Algorithm, numbered steps from the very beginning; 4 Code, the source code in your language; 5 Examples, test runs that show it works. A dashed arrow goes from Examples back to Flowchart: a test fails? Go back, fix the plan or the code, and test again.پێنج چوارگۆشەی ژمارەدار کە بە تیر بەیەکەوە بەستراون: 1 نەخشەنامە، ئامانجی بەرنامەکە بە وشەی ئاسایی؛ 2 هێڵکاریی ڕەوت، وێنەی ئەوەی چۆن کار دەکات؛ 3 ئەلگۆریزم، هەنگاوی ژمارەدار لە سەرەتاوە تا کۆتایی؛ 4 کۆد، کۆدی سەرچاوە بە زمانەکەی خۆت؛ 5 نموونەکان، تاقیکردنەوە کە پیشان دەدەن کار دەکات. تیرێکی پچڕپچڕ لە نموونەکانەوە دەگەڕێتەوە بۆ هێڵکاریی ڕەوت: تاقیکردنەوەیەک سەرنەکەوت؟ بگەڕێوە، پلان یان کۆدەکە چاک بکە و دووبارە تاقی بکەرەوە.
Scenario → flowchart → algorithm → code → examples, and back again when a test fails.، ، ، کۆد، نموونەکان و گەڕانەوە کاتێک تاقیکردنەوەیەک سەرنەکەوت.CêIT
Quick checkپشکنینی خێراIn which part do you describe, in plain words, what the program is for?لە کام بەشدا بە وشەی ئاسایی باس دەکەیت بۆ چییە؟

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.

دڵنیات دەکاتەوە کە کێشە دروستەکە چارەسەر دەکەیت. و ڕێگەت پێ دەدەن هەڵەکان لەسەر کاغەز بدۆزیتەوە، کە چاککردنیان هەرزانە. نموونەکان دەیسەلمێنن کە کار دەکات و کاتێک یەکێکیان سەرنەکەوت، دەگەڕێیتەوە بۆ پلانەکە، نەک تەنها بۆ کۆدەکە. ڕاپۆرتە کوردییەکەی گرووپەکە ئەم ناوانەی بۆ بەشەکان بەکار هێنا: ، «هێڵکاریی داڕژانی دراوەکان» (بۆ )، «هەنگاونامە» (بۆ )، «کۆدەکانی بەرنامەکە» و «چەند نموونەیەکی بەرنامەکە».

Quick checkپشکنینی خێراWhy draw the flowchart and write the algorithm before the code?بۆچی و پێش کۆد دەنووسرێن؟

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⁩» و دووبارە دەپرسێتەوە.

2. Flowchart: Start → INPUT distance → decision distance > 0? No: OUTPUT "Try again" and back to INPUT distance. Yes: fare ← 2000 + distance × 500 → OUTPUT fare → End. Notes: 6 km gives 5000; 0 km gives Try again.2. هێڵکاریی ڕەوت: دەستپێک، INPUT distance، بڕیاری distance > 0? نەخێر: OUTPUT "Try again" و گەڕانەوە بۆ INPUT distance. بەڵێ: fare ← 2000 + distance × 500، OUTPUT fare، کۆتایی. تێبینی: 6 کیلۆمەتر 5000 دەدات؛ 0 کیلۆمەتر Try again دەدات.
Part 2, the flowchart: a check that repeats until the distance is valid, then one calculation.بەشی 2، : پشکنینێک کە دووبارە دەبێتەوە تا دوورییەکە دروست بێت، پاشان یەک حیسابکردن.CêIT
3. Algorithm in pseudocode3. ئەلگۆریزم بە نیمچەکۆدTEXT
START
INPUT distance
WHILE distance ≤ 0 DO
    OUTPUT "Try again"
    INPUT distance
END WHILE
fare ← 2000 + distance × 500
OUTPUT fare
END
Explain 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ـدا.

Part 5: examples that test the programبەشی 5: ئەو نموونانەی تاقی دەکەنەوە
5. Example input5. نموونەExpected output چاوەڕوانکراوWhy test itبۆچی تاقی دەکرێتەوە
65000a normal trip: 2000+6×5002000 + 6 \times 500گەشتێکی ئاسایی: 2000+6×5002000 + 6 \times 500
107000a second normal trip: 2000+10×5002000 + 10 \times 500گەشتێکی ئاسایی تر: 2000+10×5002000 + 10 \times 500
12500the shortest whole tripکورتترین گەشتی تەواو
0Try againthe border case: not allowedحاڵەتی سنوور: ڕێگەپێنەدراو
−3-3Try againan impossible input نەگونجاو
Quick checkپشکنینی خێراWhy is 0 a useful example for the taxi program?بۆچی 0 نموونەیەکی بەسوودە بۆ تەکسی؟

Decomposition: divide and conquerپارچەکردن: دابەشی بکە و زاڵ بە

Definitionپێناسە

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:

هەندێک کێشە ئەوەندە گەورەن کە بە یەک جار پلانیان بۆ دانانرێت: تەواو، چالاکییەکی قوتابخانە، پێشبینیی کەشوهەوا. کێشەیەکی وەها بکە بە چەند کێشەیەکی بچووکتر و هەر یەکەشیان بکە بە بچووکتر، تا هەر پارچەیەک ئەوەندە بچووک دەبێت کە یەک کورت بەسی بێت. پاشان پارچەکان پێکەوە دابنێ. ئەمە ناونووسینی وانەکانە کە پارچە کراوە:

A tree diagram. At the top: Course-registration app. It splits into four parts: Courses (course list, timetable, rooms), Registration (choose courses, check the rules, waiting list), Fees (invoice, payment, refund) and Results (marks, transcript, graduation check). A note says each box can be split again, planned, built and tested on its own, and then the parts are joined and tested together.هێڵکارییەکی دار. لە سەرەوە: ئەپی ناونووسینی وانەکان. دەبێت بە چوار بەش: وانەکان (لیستی وانەکان، خشتەی کاتەکان، هۆڵەکان)، ناونووسین (هەڵبژاردنی وانە، پشکنینی یاساکان، لیستی چاوەڕوانی)، کرێی خوێندن (پسوولە، پارەدان، گەڕاندنەوەی پارە) و ئەنجامەکان (نمرەکان، بەڵگەی نمرەکان، پشکنینی دەرچوون). تێبینییەک دەڵێت هەر چوارگۆشەیەک دەکرێت دووبارە پارچە بکرێتەوە و بە جیا پلانی بۆ دابنرێت، دروست بکرێت و تاقی بکرێتەوە، پاشان بەشەکان پێکەوە دەبەسترێن و پێکەوە تاقی دەکرێنەوە.
Decomposition: one big problem becomes four sub-problems, and each of those becomes smaller tasks.: یەک کێشەی گەورە دەبێت بە چوار کێشەی بچووکتر و هەر یەکەشیان دەبێت بە چەند ئەرکێکی بچووکتر.CêIT

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ـدا بڕوانە پارچەی بچووک، هەریەکە بۆ یەک کار. لە ، پارچەیەک کە لە شوێنێکی تر پلانی بۆ دانراوە وەک چوارگۆشەی پرۆسەی ئامادە دەکێشرێت.

Quick checkپشکنینی خێراWhich of these is decomposition?کام لەمانە ؟

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.

پڕۆژە ڕاستەقینەکان زۆرجار هەردووکیان تێکەڵ دەکەن. بە هەر ڕێگایەک بێت، یەک کاری ڕوون، ڕوون و ڕوون بدە بە هەر پارچەیەک، بۆ ئەوەی پارچەکان وەک خشت لە دیوارێکدا پێکەوە بگونجێن.

Quick checkپشکنینی خێراA team first writes and tests a small part that checks whether a student number is valid, and later builds the registration screens that use it. Which approach is this?تیمێک سەرەتا بەشێکی بچووک دەنووسێت و تاقی دەکاتەوە کە دەپشکنێت ئایا ژمارەی خوێندکار دروستە، دواتر شاشەکانی ناونووسین دروست دەکات کە بەکاری دەهێنن. ئەمە کام ڕێگایە؟

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.

هەروەها ڕێگە بە تیمێک دەدات کارەکە دابەش بکات: کەس یان گرووپی جیاواز کێشە بچووکە جیاوازەکان وەردەگرن، باشتر وایە ئەوانەی کە باشتر دەیانناسن. سەرەتا هەر پارچەیەک بە تەنها تاقی دەکرێتەوە، پاشان پارچەکان پێکەوە دەبەسترێن و پێکەوە تاقی دەکرێنەوە: ئاستەکانی و لە تاقیکردنەوە لە چوار ئاستدا. کاری گەورەی وەک ڕۆژی کراوەی قوتابخانەیەک، خزمەتگوزاریی گەیاندن یان پێشبینیی کەشوهەوا بەم شێوەیە ڕێک دەخرێن.

Quick checkپشکنینی خێراTwo team members have each finished and tested their own part. What must happen before the program is ready?دوو ئەندامی تیمێک هەر یەکەیان بەشی خۆی تەواو کردووە و تاقی کردۆتەوە. پێش ئەوەی ئامادە بێت چی دەبێت ڕوو بدات؟

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 بکەیت بە 0Initialise 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ڕاهێنانەکان

ExerciseڕاهێنانEven or oddجووت یان تاک

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وەڵامەکە پیشان بدە
TEXT
START
INPUT n
IF the remainder of n ÷ 2 = 0 THEN
    OUTPUT "Even"
ELSE
    OUTPUT "Odd"
END IF
END

Flowchart: 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.

ExerciseڕاهێنانTrace itبەدوایدا بچۆ

Make a trace table for this pseudocode. What is the output, and what does the algorithm calculate?

بۆ ئەم دروست بکە. چییە و چی حیساب دەکات؟

TEXT
result ← 0
count ← 0
WHILE count < 3 DO
    result ← result + 4
    count ← count + 1
END WHILE
OUTPUT result
Show answerوەڵامەکە پیشان بدە
resultcountcount < 3?
00Yesبەڵێ
41Yesبەڵێ
82Yesبەڵێ
123Noنەخێر

The output is 12. The algorithm adds 4 three times, so it calculates 3×4=123 \times 4 = 12: multiplication by repeated addition.

⁦12⁩ـە. سێ جار 4 زیاد دەکات، بۆیە 3×4=123 \times 4 = 12 حیساب دەکات: لێکدان بە کۆکردنەوەی دووبارە.

ExerciseڕاهێنانFind the errorsهەڵەکان بدۆزەرەوە

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 ← 0 is a process: it belongs in a rectangle, not a parallelogram.
  • INPUT mark is 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 و هەرگیز زیاد ناکرێت، بۆیە هەرگیز کۆتایی نایەت.
  • کۆتایی نییە.
ExerciseڕاهێنانPlan a mini projectپلانی پڕۆژیلەیەک دابنێ

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%⁩ داشکاندنی هەیە؛ پسوولەکانی تر وەک خۆیان دەمێننەوە.

TEXT
START
INPUT bill
IF bill > 50000 THEN
    pay ← bill − bill × 10 / 100
ELSE
    pay ← bill
END IF
OUTPUT pay
END
InputOutput
4000040000
5000050000 (not more than 50000)⁦50000⁩ (زیاتر نییە لە ⁦50000⁩)
6000054000
ExerciseڕاهێنانThe largest of many numbersگەورەترینی چەندین ژمارە

Extend the “largest so far” idea: write pseudocode that reads 10 numbers and outputs the largest. Use a loop.

بیرۆکەی «گەورەترینی تا ئێستا» فراوان بکە: بنووسە کە ⁦10⁩ ژمارە وەردەگرێت و گەورەترینیان دەردەدات. بەکار بهێنە.

Show answerوەڵامەکە پیشان بدە
TEXT
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
END

The 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ڕاهێنانی زیاتر: هەنگاو و بڕیار

ExerciseڕاهێنانA room in metres and centimetresژوورێک بە مەتر و سانتیمەتر

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وەڵامەکە پیشان بدە
TEXT
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
END

Check with 4 m 25 cm by 3 m 60 cm: 425×360=153000425 \times 360 = 153000 cm², and because 1 m2=100×100=100001\ \text{m}^2 = 100 \times 100 = 10000 cm², the area is 15.3 m². The perimeter is 2×(425+360)=15702 \times (425 + 360) = 1570 cm, that is 15 m 70 cm.

بە 4 مەتر و ⁦25⁩ سانتیمەتر لە 3 مەتر و ⁦60⁩ سانتیمەتر بیپشکنە: 425×360=153000425 \times 360 = 153000 سانتیمەتری دووجا و چونکە 1 m2=100×100=100001\ \text{m}^2 = 100 \times 100 = 10000 سانتیمەتری دووجایە، ڕووبەرەکە ⁦15.3⁩ مەتری دووجایە. چێوەکە 2×(425+360)=15702 \times (425 + 360) = 1570 سانتیمەترە، واتە ⁦15⁩ مەتر و ⁦70⁩ سانتیمەتر.

ExerciseڕاهێنانWhen the phone will not chargeکاتێک مۆبایلەکە بارگە نابێت

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وەڵامەکە پیشان بدە
The flowchart written as pseudocodeهێڵکاریی ڕەوتەکە بە نیمچەکۆدTEXT
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
END

In 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ـێک شێوەیەکی ئەڵماسییە بە ڕێگای ناونووسکراوی بەڵێ و نەخێر، هەر کارێک لاکێشەیە و هەموو ڕێگایەک بە کۆتایی دەگات. هەر پرسیارێک هۆیەک لادەبات. بە هەمان شێوە چاک دەکرێن لە چارەسەرکردنی کێشە و بەڕێوەبەری ئەرکەکان.

ExerciseڕاهێنانWho wins the round?کێ ئەم گەڕە دەباتەوە؟

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وەڵامەکە پیشان بدە
TEXT
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کارتەکانOutputRule 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ـی سەوز دەیدۆڕاند.

ExerciseڕاهێنانAn electricity bill in stepsپسوولەی کارەبا بە پلە

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وەڵامەکە پیشان بدە
TEXT
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)پسوولە (دینار)
9090×80+200090 \times 80 + 20009200
2508000+150×120+20008000 + 150 \times 120 + 200028000
3208000+18000+70×200+20008000 + 18000 + 70 \times 200 + 200042000

A common mistake is to charge all 320 units at the top price (320×200+2000=66000320 \times 200 + 2000 = 66000). Test the borders too: 100, 101, 250 and 251 units give 10000, 10120, 28000 and 28200 dinars.

هەڵەیەکی باو ئەوەیە هەموو ⁦320⁩ یەکەکە بە بەرزترین نرخ حیساب بکرێت (320×200+2000=66000320 \times 200 + 2000 = 66000). سنوورەکانیش تاقی بکەرەوە: ⁦100⁩، ⁦101⁩، ⁦250⁩ و ⁦251⁩ یەکە دەدەن ⁦10000⁩، ⁦10120⁩، ⁦28000⁩ و ⁦28200⁩ دینار.

ExerciseڕاهێنانArmstrong numbersژمارەکانی Armstrong

A three-digit number is an Armstrong number when the sum of the cubes of its digits equals the number itself: 13+53+33=1+125+27=1531^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. Draw a flowchart, or write pseudocode, that reads a three-digit number and outputs whether it is an Armstrong number.

ژمارەیەکی سێ پێی دەوترێت ژمارەی Armstrong کاتێک کۆی سێجای یەکسان بێت بە خودی ژمارەکە: 13+53+33=1+125+27=1531^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. بکێشە، یان بنووسە، کە ژمارەیەکی سێ وەردەگرێت و دەریدەخات ئایا ژمارەی Armstrongـە یان نا.

Hintئاماژە

Take the digits apart with whole-number division and the remainder: n DIV 10 is the whole part of n÷10n \div 10 (153 DIV 10 = 15) and n MOD 10 is the remainder (153 MOD 10 = 3). Python writes them // and %.

بە دابەشکردنی تەواو و لێک جیا بکەرەوە: n DIV 10 بەشی تەواوی n÷10n \div 10ـە ⁦(153 DIV 10 = 15)⁩ و n MOD 10 ⁦(153 MOD 10 = 3). Python⁩ ئەمانە بە // و % دەنووسێت.

Show answerوەڵامەکە پیشان بدە
TEXT
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
END

The flowchart is a sequence of four process boxes followed by one decision. Check: 153 → 1, 5, 3 → 1+125+27=1531 + 125 + 27 = 153: an Armstrong number. 254 → 8+125+64=1978 + 125 + 64 = 197: not. The only three-digit Armstrong numbers are 153, 370, 371 and 407.

ڕیزێکە لە چوار لاکێشەی پرۆسە و پاشان یەک بڕیار. پشکنین: ⁦153⁩ دەبێت بە 1، 5، 3 و 1+125+27=1531 + 125 + 27 = 153: ژمارەی Armstrongـە. ⁦254⁩: 8+125+64=1978 + 125 + 64 = 197: نییە. تەنها ئەم ژمارە سێ ژمارەی Armstrongـن: ⁦153⁩، ⁦370⁩، ⁦371⁩ و ⁦407⁩.

Exercisesڕاهێنانەکان

More practice: loops and testingڕاهێنانی زیاتر: خولەکان و تاقیکردنەوە

ExerciseڕاهێنانWho gets the front seat?کێ لە کورسیی پێشەوە دادەنیشێت؟

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وەڵامەکە پیشان بدە
TEXT
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
END

Five 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 دوای سێ هەڵدان دەوەستێت: شیلان.

ExerciseڕاهێنانCollecting for a class tripکۆکردنەوەی پارە بۆ گەشتی پۆل

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وەڵامەکە پیشان بدە
TEXT
START
total ← 0
gifts ← 0
WHILE total < 100000 DO
    INPUT gift
    total ← total + gift
    gifts ← gifts + 1
END WHILE
OUTPUT total, gifts
END

The 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⁩ـە.

ExerciseڕاهێنانThe least common multipleLCMـی دوو ژمارە

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وەڵامەکە پیشان بدە
TEXT
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
END

Trace 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, lcm⁡(a,b)=a×bgcd⁡(a,b)\operatorname{lcm}(a, b) = \frac{a \times b}{\gcd(a, b)}.

بەدوای 4 و 6دا بچۆ: ⁦big = 6⁩ و ⁦small = 4⁩؛ دابەشکردنی 6 بەسەر 4دا 2ـی هەیە، بۆیە ⁦12⁩ تاقی بکەرەوە؛ ⁦12⁩ بەسەر 4دا 0ـی هەیە، بۆیە ⁦12⁩ـە. 5 و ⁦7 (35)⁩ و 6 و ⁦6 (6)⁩ـیش بپشکنە. کێشە جمکەکەی GCDـە (گەورەترین ژمارە کە هەردووکیان دابەش دەکات)، کە لە مۆدیوڵەکان و import وەک Python نووسراوە؛ بەو، lcm⁡(a,b)=a×bgcd⁡(a,b)\operatorname{lcm}(a, b) = \frac{a \times b}{\gcd(a, b)}.

ExerciseڕاهێنانTest the edgesسنوورەکان تاقی بکەرەوە

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⁩»ـە. خوێندکارێک ئەم خوارەوەی نووسیوە. (أ) تاقیکردنەوە لەسەر هەموو سنوورێک و لە تەنیشتیان هەڵبژێرە. (ب) کامیان وەڵامی هەڵە دەدەن؟ (ج) ڕاست بکەرەوە.

TEXT
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 IF
Show answerوەڵامەکە پیشان بدە
SeatکورسیOutputRight?دروستە؟
−1-1"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⁩ دەیانکێشێت.
  • دەستپێک و کۆتایی، پرۆسە، /، بڕیار، هێڵی ڕەوت، پرۆسەی ئامادە و گەیەنەر هەر یەکێکیان شێوەیەکی هەیە.
  • هەموو لە ڕیزبەندی، هەڵبژاردن و دووبارەکردنەوە دروست دەکرێت.
  • بە دەست دەپشکنێت؛ هەمیشە یەکسانەکان و سنوورەکان تاقی بکەرەوە.
  • پلانی پڕۆژە: ، ، ، کۆد، نموونەکان.
  • باش هەروەها هەموو جارێک بۆ هەمان هەمان دەدات.
  • سنوورەکان و ئەو لە تەنیشتیانن تاقی بکەرەوە: ئەو هەڵانە دەدۆزنەوە کە ئاسانەکان دەیانشارنەوە.
  • بۆ هەمان کێشە بە کات () و () بەراورد دەکرێن؛ زۆرجار دەکرێت یەکێکیان بە ئەوی تر بگۆڕیتەوە.
  • کێشەیەکی گەورە دەکات بە کێشەی بچووکتر ( یان )؛ پارچەکان سەرەتا بە تەنها و پاشان پێکەوە تاقی دەکرێنەوە.
Review questionsپرسیارەکانی پێداچوونەوە
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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

What's an algorithm? - David J. MalanTED-Ed · Englishئینگلیزی · 2.8M viewsبینین · 47K likesلایک

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زاراوە سەرەکییەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.