Posts

Backtracking-Examples

Real-Life Examples of Backtracking 1. 🧩 Solving a Maze You start at the entrance and choose a path. Start → Path A → Path B → Dead End ✗ ↓ BACKTRACK ↓ Try Path C → Exit ✓ If a path leads to a dead end, you return to the last decision point and try another path . Key idea: Choose → Explore → Dead end → Go back → Try another path. 2. 🧩 Solving a Sudoku Puzzle You enter a possible number into an empty cell. Try 5 → Continue solving → Conflict ✗ ↓ Remove 5 ↓ Try 7 → Valid ✓ If a number creates a conflict later, you erase it and try another number . Key idea: Make a choice → Check constraints → Undo if invalid. 3. 👥 Arranging People for a Photograph Suppose four students need to stand in a row, but two particular students cannot stand next to each other. A → B → C → D ↓ Conflict ✗ ↓ Remo...

Running Python Programs-IDLE,Interactive Shell, Jupyter, How Python works

Image
  Download the latest release of Python from  www.python.org   depending on your OS Windows,Linux or Mac Complete the installation.This will also install IDLE( Integrated Development Environment). Visit  https://docs.python.org/3/library/idle.html  to get complete details of IDLE. 1.Open IDLE by clicking the application icon 2.Open File menu and click New File and type your first script ( Eg: print("welcome to Python") 3.Save your file with .py extension ( Eg:test.py) 4.From the  Run menu  click the  Run Module(  or press F5-short cut).This will run the script 5.From the  File  menu choose  Exit  to quit from IDLE How to Run Python Code Interactively A widely used way to run Python code is through an interactive session. To start a Python interactive session, just open a command-line or terminal and then type in python, or python3 depending on your Python installation, and then hit Enter. Here’s an example of how to do thi...

Algorithmic Thinking with Python KTU S1 2024 scheme - course details and syllabus

Image
SEMESTER S1 ALGORITHMIC THINKING WITH PYTHON (Common to All Branches) B.Tech 2024 –S1/S2 Course Code: UCEST105  Teaching Hours/Week (L: T:P: R) 3:0:2:0  Credits 4  ESE Marks 60 CIE Marks 40  Exam Hours 2 Hrs. 30 Min Prerequisites (if any) None  Course Type :Theory Course Objectives: 1. To provide students with a thorough understanding of algorithmic thinking and its practical applications in solving real-world problems. 2. To explore various algorithmic paradigms, including brute force, divide-and-conquer, dynamic programming, and heuristics, in addressing and solving complex problems. Course Outcome and ÇO-PO mapping SYLLABUS Module-I Contact Hours- 7 PROBLEM-SOLVING STRATEGIES:- Problem-solving strategies defined, Importance of understanding multiple problem-solving strategies, Trial and Error, Heuristics, Means-Ends Analysis, and Backtracking (Working backward). THE PROBLEM-SOLVING PROCESS:- Computer as a model of computation, Understanding the problem, Formu...

Difference Between Algorithms and Heuristics

  Difference Between Algorithms and Heuristics 1. Algorithms A step-by-step, precise, and guaranteed method for solving a problem. Always produces the correct solution (if one exists). Often requires more time or computation because it explores all necessary steps. Example: Binary search, bubble sort, Dijkstra’s algorithm, long division, etc. 2. Heuristics A rule-of-thumb , educated guess, or shortcut strategy. Not guaranteed to produce the correct or optimal solution. Trades accuracy for speed . Useful when problems are too complex or expensive to solve exactly. Example: Trial-and-error, greedy choices, “look for patterns”, “choose the most promising option first”. Key Differences  Feature Algorithm Heuristic Guarantee of correctness      ✔ Yes                ✖ No Speed           Slower but exact              ...

Problem Solving Steps to Calculate the Area of a Circle

  📌 Problem Solving Steps to Calculate the Area of a Circle 1️⃣ Problem Definition What is the problem? We need to calculate the area of a circle given the radius. Inputs: Radius ( r ) of the circle. Output: Area ( A ) of the circle. Formula: A = Ï€ × r 2 A = \pi \times r^2 (where Ï€ ≈ 3.14159) 2️⃣ Algorithm Design Here you think * how you will solve this problem in a logical sequence: Start Input the radius Set the value of Ï€ Multiply Ï€ by radius squared to get the area Output the area Stop This gives you a clear logical plan before writing any code.  🔹 Why this helps: Breaking down a problem makes it easier to convert it later into code or pseudocode. 3️⃣ Implementation (Pseudocode) Now translate the algorithm to pseudocode — a language-agnostic way to express the logic: BEGIN INPUT radius SET pi = 3.14159 SET area = pi * radius * radius OUTPUT "Area of the circle is:", area END 👉 Pseudocode helps ...

Problem Solving Process

Six Steps of Computer-Based Problem Solving 1. Problem Definition First, we must clearly understand what problem needs to be solved . We identify: What is the input ? What should be the output ? What are the constraints ? What exactly is the objective ? Example Problem: Find the largest number in a list. Input → [12, 45, 7, 32, 18] Output → 45 Before writing any code, we must clearly understand what is required. Key question: What exactly do I need to solve? 2. Algorithm Design Once the problem is understood, we develop a step-by-step procedure to solve it. For finding the largest number: 1. Assume the first number is the largest. 2. Compare it with the next number. 3. If the next number is larger, make it the largest. 4. Continue until all numbers are checked. 5. Display the largest number. This is the algorithm . Key question: How can I solve the problem step by step? 3. Implementation Now we convert the algorithm into a program using a programming language such ...

Heuristic Methods- Examples

Image
“A heuristic does not necessarily find the best solution. It tries to find a good solution quickly by using experience, intuition, rules, or simplified information.” Below are real-life examples that students can easily relate to, followed by how each connects to algorithmic thinking. Heuristic Methods of Problem Solving — Real-Life Examples 1. Rule of Thumb — Choosing the Right Queue Real-life situation You enter a supermarket and see three billing counters: Counter A → 8 people Counter B → 5 people Counter C → 3 people A simple strategy is: Join the queue with the fewest people. You don't calculate: average billing time, number of items in each trolley, cashier speed, probability of customers having payment problems. You simply use a rule of thumb . Algorithmic thinking Choose the queue having the smallest number of customers. Important point for students This may not give the shortest waiting time . For example: Queue A: 3 people, but each has 50 items Queue B: 5 people, but eac...