Computational Thinking, Study notes of Computer science

Algorithm flowchart IPO Chart Method of designing solutions LARP, Microsoft Visio National Book Foundation FBISE

Typology: Study notes

2024/2025

Uploaded on 11/07/2025

shoua-iqbal
shoua-iqbal 🇵🇰

7 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Instructor: Sartaj Aziz Khan Unit# 2 COMPUTATIONAL THINKING & ALGORITHMS 1
Computational thinking:
It is a way of solving problems by breaking them into smaller parts and using logical steps. It helps us think like a computer to
find the best and fastest solution.
Algorithm:
An algorithm is a step-by-step set of instructions to solve a problem or complete a task. It works like a recipe that tells you
exactly what to do, in what order.
Computational Problem:
A computational problem is a problem that can be solved by giving input to a computer, processing it using steps (an
algorithm), and getting the correct output.
1. Sorting numbers: Arranging a list of numbers from smallest to largest.
2. Searching a name: Finding a specific name in a list of students.
3. Calculating average: Finding the average marks of a student from given scores.
Some of the computing problems are as follows:
Decision Problem:
A decision problem is a type of problem that can be answered with a simple "Yes" or "No" based on given input.
Examples:
1. Is the number even?
2. Is the student passed the exam?
3. Is the file found in the computer?
Search Problem:
A search problem is a type of problem where the goal is to find specific information or data from a collection.
Examples:
1. Finding a name in a contact list.
2. Locating a book in a library database.
3. Searching for a file in a computer folder.
Counting Problem:
A counting problem is a problem where we need to count how many items, ways, or solutions meet certain conditions.
Examples:
1. Counting how many students scored above 80 marks.
2. Counting the number of files in a folder.
3. Counting how many times a word appears in a paragraph.
Basics of Counting Problems:
Counting problems help us find the number of ways something can happen. We use simple math rules to count without listing
all possibilities.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Computational Thinking and more Study notes Computer science in PDF only on Docsity!

Computational thinking: It is a way of solving problems by breaking them into smaller parts and using logical steps. It helps us think like a computer to find the best and fastest solution. Algorithm: An algorithm is a step-by-step set of instructions to solve a problem or complete a task. It works like a recipe that tells you exactly what to do, in what order. Computational Problem: A computational problem is a problem that can be solved by giving input to a computer, processing it using steps (an algorithm), and getting the correct output.

  1. Sorting numbers : Arranging a list of numbers from smallest to largest.
  2. Searching a name : Finding a specific name in a list of students.
  3. Calculating average : Finding the average marks of a student from given scores. Some of the computing problems are as follows: Decision Problem: A decision problem is a type of problem that can be answered with a simple "Yes" or "No" based on given input. Examples:
  4. Is the number even?
  5. Is the student passed the exam?
  6. Is the file found in the computer? Search Problem: A search problem is a type of problem where the goal is to find specific information or data from a collection. Examples:
  7. Finding a name in a contact list.
  8. Locating a book in a library database.
  9. Searching for a file in a computer folder. Counting Problem: A counting problem is a problem where we need to count how many items, ways, or solutions meet certain conditions. Examples:
  10. Counting how many students scored above 80 marks.
  11. Counting the number of files in a folder.
  12. Counting how many times a word appears in a paragraph. Basics of Counting Problems: Counting problems help us find the number of ways something can happen. We use simple math rules to count without listing all possibilities.

1. Addition Rule: Used when choosing one option from different groups. You add the number of choices. Example: If you can choose 3 fruits or 2 drinks, total choices = 3 + 2 = 5 ways. 2. Multiplication Rule: Used when making a series of choices (step by step). You multiply the number of choices. Example: If you have 3 shirts and 2 pairs of pants, total outfits = 3 × 2 = 6 combinations. 3. Permutations: Used when order is important in selection or arrangement. The same items in different orders are counted separately. Example: AB and BA are different permutations. 4. Combinations: Used when order doesn’t matter in selection. The same items in any order are counted once. Example: AB and BA are the same combination. Pigeonhole Principle: If you have more items than containers, at least one container must hold more than one item. Example: If 5 apples are placed in 4 baskets, one basket will have at least 2 apples. Inclusion Principle: When counting items that belong to at least one of two groups, add the number in each group. Example: If 10 students like football and 8 like cricket, total liking football or cricket = 10 + 8 = 18 (if no overlap). Exclusion Principle: If some items belong to both groups, subtract the overlap to avoid counting twice. Example: If 10 students like football, 8 like cricket, and 4 like both, total = 10 + 8 – 4 = 14 students. Algorithms and their characteristics: What is algorithm? An algorithm is a step-by-step plan to solve a problem. It gives clear instructions to get the desired result. Properties of algorithms: 1. Input: The data given to the algorithm to start with. 2. Output: The result produced after following the algorithm steps. 3. Definiteness: Each step in the algorithm is clear and unambiguous. 4. Finiteness: The algorithm must finish after a limited number of steps. 5. Effectiveness: Each step can be done easily and correctly. 6. Generality: The algorithm works for all valid input of the problem. Role of algorithms in computational problem solving: Algorithms provide clear step-by-step instructions to solve computational problems efficiently. They help turn complex tasks into simple, easy-to-follow processes. 1. Algorithms make computational problem solving systematic and reliable. 2. They help break complex problems into smaller, manageable tasks. 3. Algorithms provide a clear method to get from input to the desired output. 4. They ensure the solution is correct and repeatable every time.

  • Now we know blue is taken. So, for Aiza, who doesn't like green, the only remaining color is RED. (Because blue is taken by Uzair, and Aiza doesn't like green, red is the only option left for her).
  • Since blue and red are taken, the last color left is GREEN. This must be Luqman's favorite. Does this contradict "Luqman doesn't like red"? No, because he likes green, not red. So, the answer is:
  • Aiza: RED
  • Uzair: BLUE
  • Luqman: GREEN Non-Verbal Logical Reasoning Example: Example: What Shape Comes Next? Look at this row of shapes: [Square] [Triangle] [Circle] [Square] [Triangle] [Circle] [Square] [Triangle] [? ] To Solve This: Just look for a pattern in the shapes.
  • The shapes repeat: Square, Triangle, Circle.
  • Then it starts again: Square, Triangle, Circle.
  • And again: Square, Triangle... What's missing? After the Triangle (8th shape), the pattern tells us the next shape (9th) should be a Circle. So, the answer is: Circle Standard Algorithms: Standard algorithms are common methods used to solve basic problems like sorting, searching, and counting. They follow clear, step-by-step instructions that computers can easily understand. These algorithms are widely used in programming and form the foundation of computer science. 1. Sorting Algorithms Used to arrange data in a particular order (ascending or descending).
  • Bubble Sort: Repeatedly swaps adjacent elements if they are in the wrong order.
  • Selection Sort: Finds the smallest element and places it in the correct position.
  • Merge Sort: Divides the list into halves, sorts them, and then merges them. 2. Searching Algorithms Used to find a specific item in a list.
  • Linear Search : Checks each element one by one.
  • Binary Search : Repeatedly divides a sorted list in half to find the target.

Steps in an Algorithm to Solve a Problem Using Computational Thinking: Core concepts of computational thinking: Computational thinking involves solving problems logically and effectively. To design an algorithm using this approach, follow these key steps:

1. Understand the Problem (Decomposition): Break the main problem into smaller, manageable parts. Example: If you want to sort student marks, first understand what "sorting" and "marks" mean. 2. Identify Patterns (Pattern Recognition): Look for similarities or repeated actions in the problem. Example: All marks are numbers, and sorting can be done by comparing them. 3. Focus on Key Details (Abstraction): Ignore unnecessary information and focus only on what's important. Example: Ignore student names if only marks need to be sorted. 4. Design a Step-by-Step Plan (Algorithm Design): Create clear and ordered steps to solve the problem. Example: 1. Start 2. Take input of marks 3. Compare and sort marks 4. Display sorted marks 5. End Abstraction: Abstraction means hiding unnecessary details and showing only the important parts of something to make it easier to understand or use. 1. Maps - A map hides real-world complexity (trees, people, buildings) and only shows roads, cities, and directions. Only useful info is shown. 2. Symbols - Symbols like “@”, “$”, or road signs represent ideas or actions without showing everything. Simple signs = big meanings. 3. Models - A model (like a globe or 3D house model) represents something complex in a simple form. Focuses on key structure, not tiny details.

  • Use variables and loops to handle different sizes or inputs. "Test with Different Scenarios": This just means you should try out your calculator or game in many different ways. Don't just try the easy stuff! Try putting in weird numbers, or pressing buttons in a strange order, to make sure it works correctly no matter what. If you find a problem, fix it. Example: Sorting Algorithms What is "Sorting"? Sorting means putting things in order, like arranging numbers from smallest to largest, or words alphabetically.
  • Specific Case: Bubble Sort o Imagine you have a deck of cards all mixed up. o Bubble Sort is like going through the deck, two cards at a time. If the first card is bigger than the second, you swap them. You keep doing this, repeatedly, until all the cards are in the right order. It's a specific way to sort.
  • Generalized Solution: Many Ways to Sort! o While Bubble Sort is one way, there are many other ways to sort those cards! o Think of Quick Sort , Merge Sort , or Heap Sort. These are all different "recipes" or methods to sort the cards. They all aim to get the same result (a sorted deck), but they use different steps to get there. o A "generalized solution" means having a way to pick the best sorting method for whatever you're trying to sort. Example: Calculating Area of Shapes What is "Area"? Area is the amount of space inside a flat shape, like the space covered by a rug on a floor.
  • Specific Case: Area of a Rectangle o If you want to find the area of only a rectangle, you use a very specific formula: Length x Width. That's it. This formula only works for rectangles.
  • Generalized Solution: Area of Any Shape! o What if you also need to find the area of a circle, a triangle, or other shapes? o Instead of having a separate calculator for each type of shape, a "generalized solution" would be like building one super calculator. o You could tell this super calculator: "I have a rectangle, its length is X and width is Y, give me the area." o Or: "I have a circle, its radius is Z, give me the area." o This one super calculator knows all the different formulas for different shapes and can give you the right answer for any shape you give it. Modular Design: Modular design is a fundamental concept in software engineering and computational thinking, focused on breaking down a system into smaller, manageable, and interchangeable parts, known as modules. Example: In programming, functions or methods are modules that perform specific tasks. In Python, a function to calculate the area of a rectangle. Example: OOP uses classes and objects to implement modular design.

Example: In web development, modular design can be applied through components and services.

1. Define Modules : Break the complex problem into smaller sub-problems. Create a separate module to solve each core sub-problem. 2. Design Interfaces : Plan how modules will connect and share data. Define clear input and output for each module. 3. Implement Modules : Write code for each module based on its design. Follow the steps and interfaces defined earlier. 4. Integrate Modules : Combine all modules to form the full program. Ensure they work together using proper connections. 5. Test Modules : Test each module on its own. Then test the complete system to find errors. Algorithm Dry Run: Dry run means checking the algorithm step-by-step using sample input. We manually trace the values of variables to see how the algorithm works. Example Dry Run Steps (for better understanding): Let’s say we have this simple algorithm: Algorithm: Find Sum of First 3 Numbers

  1. Start
  2. Set sum = 0
  3. Read number1, number2, number
  4. sum = number1 + number2 + number
  5. Print sum
  6. End Trace Table Step number1 number2 number3 sum Output 2 — — — 0 — 3 2 4 6 0 — 4 2 4 6 12 — 5 2 4 6 12 12 Errors : There are two types of errors that we should understand to improve our problem-solving: 1. Syntax Errors
  • These are mistakes in the structure of a sentence or command.
  • It's like making a grammar mistake in a sentence.
  • Example: Forgetting to write "PKR" before 500.

Q7. The Pigeonhole Principle states that if more items are placed into containers than the number of containers, then: a) Some containers must be empty

  • b) At least one container must hold more than one item (Correct Answer) c) All containers will be full d) Each item will be placed in a different container Q8. In a set of 50 students, 30 have completed a math project, 25 have completed a science project, and 15 have completed both. How many students have completed at least one project? a) 35
  • b) 40 (Correct Answer) c) 45 d) 50 Q9. Which property of an algorithm ensures that it produces at least one output after the calculations? a) Input
  • b) Output (Correct Answer) c) Definiteness d) Finiteness Q10. Which property ensures that an algorithm will eventually end after a finite number of steps? a) Input
  • b) Finiteness (Correct Answer) c) Effectiveness d) Generality Q1. Consider 3 boys and 3 girls want to team up as pair for the 14th of August related student performance at the school. Find the total no. of ways these pairs could be formed using Counting Principle Problems. Answer: To form pairs, each boy can be paired with one of the girls. Since there are 3 boys and 3 girls, the number of ways to form pairs is 3! = 3 × 2 × 1 = 6 ways. Q2. Suppose you have selected black pant to attend school function and have three options of shirt to choose. Find the total no. of ways you can dress up using Counting Principle Problems. Answer: Since you have 1 black pant and 3 shirt options, the total number of ways to dress up is 1 × 3 = 3 ways. This is a direct application of the Multiplication Principle. Q3. You are sitting at a study table doing homework. The penholder on the table contains 2 blue pens, 1 black pen, and 2 lead pencils. How many options do you have for writing? Answer: You have 2 blue pens, 1 black pen, and 2 lead pencils. To choose one writing instrument, you have a total of 2 + 1 + 2 = 5 options. Q4. For a race on sports day activities, a group of 20 students are given a race lane at random. There are six students selected for the first race. How many different orders of the six lanes for students may be chosen? Answer: This is a permutation problem. The number of ways to order 6 students in 6 lanes is 6 != 6 × 5 × 4 × 3 × 2 × 1 = 720 different orders.

Long Answers:

Q1. Ejaz, Javeria, Liaqat, and Zainab are standing in a line. Here are the clues to determine their positions: a) Javeria is standing directly behind Ejaz.

b) Zainab is not next to Liaqat. c) Liaqat is not at the end of the line. d) Zainab is standing in the first position. In which order are they standing? Answer: Let's deduce the order step by step. From clue (d), Zainab is in the first position. From clue (a), Javeria is directly behind Ejaz, meaning they are Ejaz-Javeria. From clue (c), Liaqat is not at the end of the line, which means Liaqat must be in the middle. If Zainab is first, and Liaqat is not last, and Ejaz-Javeria are a pair, the only remaining spot for Liaqat is second or third. If Liaqat is second, the order could be Zainab, Liaqat, Ejaz, Javeria. This satisfies all conditions, including (b) as Zainab is not next to Liaqat. Therefore, the order is: Zainab, Liaqat, Ejaz, Javeria. Q2. Provide students with a detailed map of their school. Ask them to create an abstract version, highlighting only the main buildings and pathways. Answer: To create an abstract map, students should first identify the most important landmarks on the detailed map, such as main classroom blocks, the library, cafeteria, gym, and administrative offices. Then, they should trace the primary pathways or corridors that connect these essential buildings, omitting minor details like individual rooms, specific trees, or decorative elements. The goal is to simplify the complex layout into a clear, concise diagram that focuses on navigability and the overall structural relationships between key areas. This exercise promotes spatial reasoning and the ability to extract critical information from a detailed representation. Q3. Give students a problem that can be solved with a simple program. Encourage them to write functions to handle different parts of the problem, abstracting complex operations into manageable pieces. Answer: Problem: Design a program that calculates the total cost of a shopping cart. The program should apply a 10% discount if the total cost before discount exceeds $100. It should also add a 5% sales tax after any discount. Functions to encourage:

1. calculate_subtotal(item_prices): Takes a list of item prices and returns their sum. 2. apply_discount(subtotal): Takes the subtotal, checks if it's over $100, and returns the discounted amount or the original subtotal. 3. add_sales_tax(amount): Takes an amount and returns the amount with 5% sales tax added. 4. main(): Orchestrates the calls to these functions, takes user input for item prices, and prints the final total. This breakdown helps students understand modular programming, making the problem easier to solve and debug. Q4. Given the following web form inputs, identify any syntax errors and correct them: Form Inputs:

  • Name: Amjad Ali
  • Email: amjadali@gmail
  • Date: 01/01/ Answer: Syntax Errors and Corrections: