algorithms and programming: simple gcd

NOC16 CS11
27 Sept 201727:28

Summary

TLDRThis script is a detailed tutorial on the concepts of algorithms and data structures in the context of programming, specifically in Python. It introduces algorithms as a set of steps to solve problems efficiently, like a recipe for cooking. The tutorial explains the importance of algorithms in programming, how they are used to execute tasks in a step-by-step manner, and their implementation in computers. It also delves into the basics of programming languages, the role of functions, and the process of creating a program. The script further discusses the Great Common Divisor (GCD) as an algorithmic example, illustrating how to calculate it and emphasizing the significance of algorithms in everyday computational tasks.

Takeaways

  • 😀 The course introduces the basics of programming, data structures, and algorithms, starting with the fundamental concept of an algorithm.
  • 🎓 An algorithm is a set of steps that can be followed to solve a problem or perform a computation, akin to a recipe in cooking.
  • 💡 Programming languages allow us to write instructions for a computer to execute, with the goal of making tasks automated and efficient.
  • 👨‍🏫 The course emphasizes that algorithms can be executed by a human or a machine, but the expectation is that a computer will carry out the steps defined by the programmer.
  • 🔍 The example of planning an event like a function in a hall illustrates how an algorithm can involve multiple steps and considerations.
  • 📚 The script discusses the importance of detailing an algorithm at various levels of detail depending on the experience of the audience or team executing it.
  • 🔢 The concept of the greatest common divisor (GCD) is used to demonstrate how algorithms can be used to find the largest common factor between two numbers, showcasing a practical application.
  • 🛠️ The script introduces a simple algorithm to calculate the GCD by listing the factors of two numbers and finding the largest common one.
  • 💻 The course will cover how to implement algorithms in the context of computer programming, emphasizing the practical application of algorithms to solve computational problems.
  • 🌐 The script highlights the ubiquity of algorithms in everyday life, from booking flights to solving puzzles like Sudoku, emphasizing their role in optimization and data processing.

Q & A

  • What is the primary focus of the course mentioned in the script?

    -The primary focus of the course is on algorithms, data structures, and the basics of programming, starting with an introduction to algorithms.

  • What is the definition of an algorithm according to the script?

    -An algorithm is defined as a set of steps or instructions to perform a specific task or solve a particular problem, much like a recipe in cooking.

  • How are algorithms related to programming languages?

    -Algorithms are the logical procedures that programming languages use to execute tasks. The script explains that programming languages allow us to write programs that detail the order of necessary steps and handle different scenarios.

  • What is the significance of steps in an algorithm?

    -The steps in an algorithm are significant because they represent the sequence of actions that must be executable by a machine, such as a computer, to perform a specific task.

  • Why is it necessary for a program to be executable by a machine?

    -A program must be executable by a machine so that the machine can carry out the instructions as intended by the programmer, which is the common context for programming.

  • What is the role of a function in the context of the script?

    -In the context of the script, a function represents a set of instructions that perform a specific task, such as arranging chairs in a hall, and is a fundamental building block in programming.

  • Why is it important to detail the steps of an algorithm?

    -Detailing the steps of an algorithm is important to ensure that it can be understood and executed by different people or machines, and to handle any complexity or variations in the task at hand.

  • What is the purpose of discussing the greatest common divisor (GCD) in the script?

    -The purpose of discussing the GCD is to illustrate how algorithms can be used to solve mathematical problems, specifically by finding the largest common factor between two numbers.

  • How does the script describe the process of finding the GCD of two numbers?

    -The script describes the process of finding the GCD by listing the factors of the two numbers and identifying the largest factor that both numbers share.

  • What is the significance of the Euclidean algorithm in the context of the script?

    -The Euclidean algorithm is significant as it is a classic example of an efficient algorithm used to compute the GCD of two numbers, which is a fundamental concept in number theory and computer science.

  • How does the script explain the concept of data structures in relation to algorithms?

    -The script explains that data structures are used to organize and store data in a way that can be efficiently accessed and manipulated by algorithms, highlighting their importance in programming.

Outlines

00:00

💡 Introduction to Algorithms and Programming

The paragraph introduces the concept of algorithms and programming, emphasizing the importance of algorithms in defining the logic behind tasks. It explains that an algorithm is a set of steps that can be executed to achieve a desired outcome, akin to a recipe. The paragraph also touches on the basic idea of programming languages, which are used to write programs that instruct computers on how to perform tasks. The concept of executing an algorithm step by step is introduced, and the expectation that a computer or a person should be able to execute a program is set. The paragraph concludes by discussing how the course will focus on computer algorithms, starting from basic mathematical operations.

05:01

🔢 Computational Thinking and Practical Examples

This paragraph delves into computational thinking, illustrating how algorithms can be used to solve practical problems like organizing events or rearranging numbers in a spreadsheet. It mentions optimization problems, such as booking flights or solving puzzles like Sudoku, which require computational algorithms to find the best solution. The paragraph also highlights the importance of data structures in organizing information efficiently, setting the stage for a deeper exploration of algorithms and their applications in various computational tasks.

10:02

🧩 The Process of Algorithm Design and Function

The paragraph discusses the process of designing algorithms, focusing on the need for a clear and limited set of instructions. It emphasizes the importance of defining what needs to be done in a way that can be understood and executed without knowing the exact values of the input. The paragraph introduces the concept of functions and how they can be used to organize and simplify complex tasks. It uses the example of calculating the greatest common divisor (GCD) to illustrate the algorithmic process and the importance of identifying and utilizing common factors between numbers.

15:06

🔍 Detailed Explanation of GCD Algorithm

This paragraph provides a detailed explanation of the algorithm used to calculate the greatest common divisor (GCD) of two numbers. It describes the process of listing the factors of the numbers and identifying the largest common factor. The paragraph uses examples to demonstrate how the algorithm works, showing the step-by-step method of factor listing and comparison. It also discusses the practicality and efficiency of the algorithm, ensuring that the process is reliable and can be applied to any pair of positive integers.

20:06

📝 Implementing the GCD Algorithm in Python

The paragraph outlines the implementation of the GCD algorithm in Python, starting with the definition of a function to calculate the GCD. It explains how to create lists to store the factors of the numbers and how to use loops to iterate through these factors. The paragraph also covers how to check for divisibility and append factors to the list if they are common to both numbers. It concludes with the process of extracting the greatest common factor from the combined list of factors, demonstrating the practical application of the algorithm in a programming context.

25:07

💻 Deep Dive into Python Programming Constructs

This paragraph provides an in-depth look at various programming constructs in Python, such as loops, conditional statements, and data structures. It discusses how these constructs are used to build algorithms and solve problems efficiently. The paragraph emphasizes the importance of understanding how to assign and manipulate values, as well as how to use built-in functions like 'append' to modify data structures. It also touches on the significance of indentation and syntax in Python, highlighting the language's readability and ease of use for programming.

Mindmap

Keywords

💡Algorithm

An algorithm is a set of step-by-step instructions designed to accomplish a specific task or solve a particular problem. In the context of the video, algorithms are the foundation of programming, used to efficiently organize and execute a series of operations, such as calculating the greatest common divisor (GCD) of two numbers. The script mentions algorithms in relation to their execution by a machine and how they are fundamental to programming, exemplified by the process of calculating the GCD.

💡Programming

Programming refers to the process of writing, testing, debugging, and maintaining the source code of computer programs. The video script discusses programming as a means to give instructions to a computer in a certain order and to handle different operations using programming languages. It ties into the broader theme of the video by illustrating how programming allows the execution of algorithms to perform tasks like data organization and optimization.

💡Data Structures

Data structures are specialized formats for organizing, processing, and storing data. The script touches on data structures as a way to efficiently store and manage the data required for algorithms to function. In the video, lists are used as a simple data structure to store and manipulate the factors of numbers, showcasing the importance of data structures in programming and algorithm design.

💡Greatest Common Divisor (GCD)

The GCD of two or more integers is the largest positive integer that divides each of the integers without leaving a remainder. The video script uses the GCD as a practical example to demonstrate how algorithms work. It explains the process of finding the GCD of two numbers through a step-by-step algorithm, highlighting its relevance in computational mathematics and problem-solving.

💡Function

In programming, a function is a reusable block of code that performs a specific task and returns a result. The script mentions functions in the context of executing a set of instructions to achieve a goal, such as building a hall or calculating mathematical operations. Functions are a fundamental concept in the video, illustrating how they encapsulate logic within a program, making it reusable and modular.

💡Machine

A machine, as referenced in the script, is a device that executes instructions, particularly in the context of computers executing programs. The video discusses how machines carry out the steps outlined by algorithms, emphasizing the role of machines in the field of computer science and programming, and how they are essential for algorithm execution.

💡List

A list, in the context of the video, is a data structure that stores an ordered collection of items, which can be elements of any data type. The script uses lists to demonstrate how data can be organized and iterated over, such as when generating and storing the factors of a number. Lists are a simple yet powerful tool in programming, allowing for the collection and management of data points.

💡Execution

Execution in programming refers to the process of running a program or algorithm, where the machine follows the instructions step by step. The video script explains execution in the context of how a computer follows the steps of an algorithm to perform a task, like calculating the GCD. It highlights the importance of execution in bringing algorithms to life within a programming environment.

💡Optimization

Optimization in the video script refers to the process of making a program or algorithm as efficient or functional as possible. It is discussed in the context of solving problems like finding the minimum time or cost for flights, which involves organizing and selecting data to achieve the best outcome. Optimization is a key theme in the video, showcasing its importance in algorithm design and problem-solving.

💡Spreadsheet

A spreadsheet is a type of computer application for data organization, analysis, and storage. The script mentions spreadsheets as an example of a tool used for computational tasks, such as organizing and reordering data. It illustrates how spreadsheets can be utilized to perform algorithmic tasks, like sorting numbers in ascending or descending order, which is a common operation in data processing.

💡Variable

A variable in programming is a storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value. The video script discusses variables in the context of storing and manipulating data, such as the factors of numbers during the calculation of the GCD. Variables are crucial for holding intermediate results and allowing for dynamic data manipulation within a program.

Highlights

Welcome to the course on Python programming, data structures, and algorithms.

An algorithm is a set of steps to perform a task efficiently.

Programming is about writing instructions for a computer to follow.

Algorithms can be executed step by step to achieve a desired outcome.

The course will focus on computer algorithms and their practical applications.

Functions are a fundamental concept in programming, used to perform specific tasks.

Data structures are used to organize and store data efficiently.

The greatest common divisor (GCD) is an important concept in number theory.

The Euclidean algorithm is a method for finding the GCD of two numbers.

The course will explore various algorithms for sorting and optimization.

Understanding algorithms is crucial for solving computational problems.

The course will cover the implementation of algorithms in Python.

The importance of loops and conditional statements in programming will be discussed.

The course will teach how to write clean and efficient code.

Data structures like lists and their operations will be explained.

The concept of variables and assignment in programming will be covered.

The course will also delve into functions and how to define them in Python.

Error handling and debugging techniques will be an essential part of the course.

The practical applications of algorithms in everyday life will be highlighted.

The course aims to bridge the gap between theoretical concepts and practical programming.

Transcripts

play00:01

പൈത്തണിലെ(phython) പ്രോഗ്രാമിംഗ്(programming), ഡാറ്റാ സ്ട്രക്ചറുകൾ(data

play00:05

structures), അൽഗോരിതം(algorithm) എന്നിവയെക്കുറിച്ചുള്ള

play00:08

കോഴ്സിലെ(course) ആദ്യ പ്രഭാഷണത്തിലേക്ക്

play00:10

സ്വാഗതം.

play00:11

ഒരു അൽ‌ഗോരിതം(algorithm) എന്താണ് അർത്ഥമാക്കുന്നത്,

play00:15

എന്താണ് പ്രോഗ്രാമിംഗ്(programming) എന്നതിന്റെ അടിസ്ഥാന

play00:19

നിർവചനത്തിൽ നിന്ന് നമുക്ക് ആരംഭിക്കാം.

play00:23

നിങ്ങളിൽ മിക്കവർക്കും അറിയാവുന്നതുപോലെ,

play00:26

ചില ജോലികൾ എങ്ങനെ ചിട്ടയായി നിർവഹിക്കാം

play00:31

എന്നതിന്റെ വിവരണമാണ് അൽഗോരിതം(algorithm). ഒരു

play00:34

അൽ‌ഗോരിതം(algorithm) എന്തെങ്കിലും നേടുന്നതിനായി ഉള്ള

play00:38

ഘട്ടങ്ങളുടെ ഒരു ശ്രേണി ഉൾക്കൊള്ളുന്നു,

play00:42

അത് ഒരു പാചകക്കുറിപ്പായി കണക്കാക്കാം. അതിനാൽ,

play00:47

തീർച്ചയായും പാചകക്കുറിപ്പ് എന്ന പദം പാചകത്തിൽ

play00:52

നിന്നാണ് വരുന്നത്, അവിടെ നമുക്ക് ചേരുവകളുടെ

play00:57

ലിസ്റ്റും(list) തുടർന്ന് ഒരു വിഭവം തയ്യാറാക്കുന്നതിനുള്ള

play01:01

ഘട്ടങ്ങളും ഉണ്ട്. അതുപോലെ തന്നെ, എന്തെങ്കിലും

play01:06

തയ്യാറാക്കുന്നതിനോ അല്ലെങ്കിൽ നൽകിയ

play01:09

ചുമതല നേടുന്നതിനോ ഉള്ള ഒരു മാർഗമാണ്

play01:14

അൽഗോരിതം(algorithm). ഈ കാര്യത്തിന്റെ പശ്ചാത്തലത്തിൽ,

play01:18

ഒരു പാചകക്കുറിപ്പിനെയാണ് നമ്മൾ ഒരു പ്രോഗ്രാം(program)

play01:23

എന്ന് വിളിക്കുന്നത്. ഒരു പ്രോഗ്രാമിംഗ്(programming)

play01:26

ഭാഷ ഉപയോഗിച്ച് നമ്മൾ ഒരു പ്രോഗ്രാം(program)

play01:31

എഴുതുന്നു. അതിനാൽ, ആവശ്യമുള്ള ഘട്ടങ്ങളുടെ

play01:35

ക്രമം വിവരിക്കാനും അതിനിടയിൽ വ്യത്യസ്ത

play01:39

കാര്യങ്ങൾ സംഭവിക്കുകയാണെങ്കിൽ വ്യത്യസ്ത ഘട്ടങ്ങൾ

play01:43

എങ്ങനെ പിന്തുടരാമെന്നും വിവരിക്കുക എന്നതാണ്

play01:47

പ്രോഗ്രാമിംഗ്(programming) ഭാഷയുടെ ലക്ഷ്യം.

play01:49

അൽ‌ഗോരിതം(algorithm) എക്സിക്യൂട്ട്(execute) ചെയ്യുന്നതെന്തും

play01:52

ചെയ്യാൻ‌ കഴിയുന്ന ഒന്നാണ് സ്റ്റെപ്പ്(step)

play01:56

എന്ന ആശയം. ഇപ്പോൾ ഒരു മെഷീൻ(machine) ഒരു

play02:02

പ്രോഗ്രാം(program) എക്സിക്യൂട്ട്(execute) ചെയ്യേണ്ടതില്ല,

play02:05

എന്നിരുന്നാലും കമ്പ്യൂട്ടർ(computer)

play02:07

നമ്മുടെ ഘട്ടങ്ങൾ നടപ്പിലാക്കുമെന്ന്

play02:10

നമ്മൾ പ്രതീക്ഷിക്കുന്ന കമ്പ്യൂട്ടർ(computer)

play02:13

പ്രോഗ്രാമിംഗിന്റെ(programming) സാധാരണ സന്ദർഭമാണിത്.

play02:15

ഒരു വ്യക്തിക്കും ഒരു പ്രോഗ്രാം(program)

play02:19

എക്സിക്യൂട്ട്(execute) ചെയ്യാൻ കഴിയും.

play02:22

ഉദാഹരണത്തിന്, ഒരു ഫംഗ്ഷനായി(function) ഒരു

play02:26

ഹാൾ(hall) തയ്യാറാക്കുക എന്നതാണ് കയ്യിലുള്ള

play02:30

ചുമതലയെന്ന് കരുതുക. അതിനാൽ, മുറി വൃത്തിയാക്കൽ,

play02:35

സ്റ്റേജ്(stage) തയ്യാറാക്കൽ, അലങ്കാരം ഉണ്ടെന്ന്

play02:38

ഉറപ്പുവരുത്തുക, കസേരകൾ ക്രമീകരിക്കുക

play02:41

തുടങ്ങി വിവിധ ഘട്ടങ്ങൾ ഇതിൽ ഉൾപ്പെടും.

play02:46

ഒരു കൂട്ടം ആളുകൾ ഇത് നിർവ്വഹിക്കും.

play02:51

ഇപ്പോൾ ഈ ഗ്രൂപ്പിന്റെ(group) വൈദഗ്ധ്യവും അനുഭവവും

play02:56

അനുസരിച്ച്, നിങ്ങൾക്ക് ഈ അൽഗോരിതം(algorithm) വിവിധ

play03:01

തലങ്ങളിൽ വിശദമായി വിവരിക്കാൻ കഴിയും.

play03:04

ഉദാഹരണത്തിന്, കസേര ക്രമീകരിക്കുക പോലുള്ള

play03:08

ഒരു നിർദ്ദേശം, ആളുകൾക്ക് പ്രതീക്ഷിക്കേണ്ടതെന്താണെന്ന്

play03:12

കൃത്യമായി അറിയാമെങ്കിൽ അർത്ഥമുണ്ട്. മറുവശത്ത്,

play03:16

ഇത് മുമ്പൊരിക്കലും ചെയ്യാത്ത ഒരു പുതിയ

play03:21

കൂട്ടം ആളുകളാണെങ്കിൽ; നിങ്ങൾ ഘട്ടം കൂടുതൽ

play03:26

വിശദമായി വിവരിക്കേണ്ടതുണ്ട്. ഉദാഹരണത്തിന്, നിങ്ങൾ

play03:29

അത് പറയണം, 8 വരികളിൽ കസേരകൾ ക്രമീകരിക്കുക,

play03:35

ഓരോ വരിയിലും 10 കസേരകൾ ഇടുക. അതിനാൽ, ഒരു

play03:42

ഘട്ടത്തിന്റെ ആശയം ആത്മനിഷ്ഠമാണ്, അത്

play03:46

വ്യക്തിയിൽ നിന്നോ അൽഗോരിതം(algorithm) നടപ്പിലാക്കുന്ന

play03:50

യന്ത്രത്തിൽ നിന്നോ നമ്മൾ പ്രതീക്ഷിക്കുന്നതിനെ

play03:53

ആശ്രയിച്ചിരിക്കുന്നു. ആ ശേഷിയുടെ അടിസ്ഥാനത്തിൽ,

play03:57

നമ്മൾ അൽഗോരിതം(algorithm) തന്നെ വിവരിക്കുന്നു.

play04:01

ഈ കോഴ്സിലെ(course) നമ്മുടെ ശ്രദ്ധ കമ്പ്യൂട്ടർ(computer)

play04:06

അൽ‌ഗോരിതംസിലായിരിക്കും(algorithm), സാധാരണയായി, ഈ അൽ‌ഗോരിതംസ്(algorithm)

play04:10

വിവരങ്ങൾ കൈകാര്യം ചെയ്യുന്നു. ഹൈസ്കൂളിൽ(highschool)

play04:14

നിന്ന് തുടങ്ങി നമുക്കെല്ലാവർക്കും പരിചിതമായ ഏറ്റവും

play04:18

അടിസ്ഥാനപരമായ അൽഗോരിതം(algorithm), സംഖ്യാ പ്രവർത്തനങ്ങൾ

play04:22

കണക്കാക്കുന്ന ഒരു അൽഗോരിതം(algorithm) ആണ്.

play04:26

ഉദാഹരണത്തിന്, നമുക്ക് x, y എന്നീ രണ്ട് അക്കങ്ങൾ

play04:32

എടുത്ത് x പവർ(power) y കണക്കാക്കുന്ന ഒരു

play04:37

അൽഗോരിതം(algorithm) ഉണ്ടായിരിക്കാം. അതിനാൽ, സ്കൂളിൽ(school)

play04:42

അത്തരം നിരവധി ഫംഗ്ഷനുകൾ(function) നമ്മൾ കണ്ടു.

play04:47

ഉദാഹരണത്തിന്, x- ന്റെ സ്‌ക്വയർ റൂട്ട്(square

play04:52

root) കണക്കുകൂട്ടാൻ, സ്കൂളിൽ(school) നമ്മൾ

play04:56

ചെയ്യുന്നത് x- ന്റെ സ്‌ക്വയർ റൂട്ട്(square

play05:01

root) കണക്കുകൂട്ടുന്നതിനുള്ള സങ്കീർണ്ണമായ മാർഗ്ഗമാണ്

play05:04

അല്ലെങ്കിൽ x- നെ y കൊണ്ട് ഹരണം നടത്തുന്നു.

play05:10

ഇവയെല്ലാം മൂല്യങ്ങൾ കണക്കുകൂട്ടുന്ന

play05:13

അൽ‌ഗോരിതം(algorithm) ആണ്, ഒന്നോ അതിലധികമോ

play05:16

സംഖ്യകൾ നൽകിയാൽ ഈ ഫംഗ്ഷന്റെ(function)

play05:20

ഔട്ട്‌പുട്ട്(output) കണക്കാക്കുന്നു.

play05:22

എന്നാൽ കമ്പ്യൂട്ടർ(computer) ഉപയോഗിച്ച നമുക്കെല്ലാവർക്കും

play05:25

മറ്റ് പല കാര്യങ്ങളും കണക്കുകൂട്ടലിന്റെ

play05:29

പരിധിയിൽ വരുന്നതായി അറിയാം. ഉദാഹരണത്തിന്,

play05:33

വിവരങ്ങൾ ക്രമീകരിക്കുന്നതിന് നമ്മൾ ഒരു സ്പ്രെഡ്ഷീറ്റ്(spreadsheet)

play05:37

ഉപയോഗിക്കുന്നു, അതിൽ ഒരു നിര അടുക്കാൻ

play05:42

നമ്മൾ ആഗ്രഹിക്കുന്നു. അതിനാൽ, നിരയിലെ

play05:45

ഇനങ്ങൾ‌ ആരോഹണ ക്രമത്തിലോ അവരോഹണ ക്രമത്തിലോ

play05:50

പുനഃക്രമീകരിക്കുന്നത് ഇതിൽ ഉൾപ്പെടുന്നു.

play05:52

അതിനാൽ, വിവരങ്ങൾ പുനഃക്രമീകരിക്കുക

play05:55

എന്നത് ഒരു കമ്പ്യൂട്ടേഷണൽ(computational) ചുമതലയാണ്, അൽഗോരിതം(algorithm)

play06:00

ഉപയോഗിച്ച് ഇത് എങ്ങനെ ചെയ്യണമെന്ന് നമ്മൾ

play06:04

അറിയേണ്ടതുണ്ട്. ഇന്നത്തെ ജീവിതത്തിൽ

play06:07

നമുക്ക് ചുറ്റും കണക്കുകൂട്ടലുകൾ

play06:10

കാണുന്നു. ഉദാഹരണത്തിന്, നമ്മൾ ഒരു ട്രാവൽ

play06:14

ബുക്കിംഗ്(travel booking) സൈറ്റിലേക്ക്(site)

play06:17

പോയി, ഒരു നഗരത്തിൽ നിന്ന് മറ്റൊരു നഗരത്തിലേക്ക്

play06:22

ഒരു ഫ്ലൈറ്റ്(flight) ബുക്ക്(book) ചെയ്യാൻ

play06:26

നമ്മൾ ശ്രമിക്കുമ്പോൾ, മിനിമം(minimum) സമയം അല്ലെങ്കിൽ

play06:30

കുറഞ്ഞ ചെലവ് കണക്കിലെടുത്ത് ഫ്ലൈറ്റുകൾ(flight) ക്രമീകരിക്കാൻ

play06:35

ഇത് വാഗ്ദാനം ചെയ്യും. അതിനാൽ, ഇവ ഒപ്റ്റിമൈസേഷൻ(optimization)

play06:40

പ്രശ്നങ്ങളാണ്. ഒരു പ്രത്യേക രീതിയിൽ

play06:44

വിവരങ്ങൾ ക്രമീകരിക്കുന്നതും നമ്മൾ ആഗ്രഹിക്കുന്ന

play06:47

അളവ് കണക്കാക്കുന്നതും ഇതിൽ ഉൾപ്പെടുന്നു.

play06:51

ഈ സാഹചര്യത്തിൽ, നമുക്ക് a മുതൽ b വരെ

play06:57

എങ്ങനെ പോകാമെന്ന് അറിയാൻ നമ്മൾ ആഗ്രഹിക്കുന്നു,

play07:00

കൂടാതെ a മുതൽ b വരെ പോകാൻ കഴിയുന്ന എല്ലാ

play07:07

വഴികളിലും, നമുക്ക് ഒപ്റ്റിമൽ(optimal) ആയ

play07:11

ഒന്ന് വേണം. തീർച്ചയായും, കമ്പ്യൂട്ടർ(computer)

play07:15

പ്രോഗ്രാമുകൾ(program) നടപ്പിലാക്കുന്ന

play07:17

നിരവധി കാര്യങ്ങൾ ഇന്ന് നാം കാണുന്നു.

play07:22

നമുക്ക് ഗെയിമുകൾ(game) കളിക്കാൻ കഴിയും.

play07:26

ഉദാഹരണത്തിന്, നമുക്ക് സുഡോകു(sudoku) പരിഹരിക്കാനാകും

play07:30

അല്ലെങ്കിൽ ഒരു പ്രോഗ്രാമിനെതിരെ(program) ചെസ്സ്(chess) കളിക്കാം.

play07:34

ഒരു പ്രമാണം ടൈപ്പു(type) ചെയ്യാൻ നമ്മൾ വേഡ്

play07:40

പ്രോസസർ(word processor) ഉപയോഗിക്കുമ്പോൾ അല്ലെങ്കിൽ sms സന്ദേശങ്ങൾ

play07:46

ടൈപ്പുചെയ്യാൻ നമ്മുടെ സെൽ ഫോണുകൾ(cell phone) ഉപയോഗിക്കുമ്പോഴും,

play07:52

കമ്പ്യൂട്ടർ(computer) നമ്മുടെ അക്ഷരവിന്യാസത്തിൽ

play07:55

തിരുത്തൽ നിർദ്ദേശിക്കുന്നു. ഈ കോഴ്‌സിൽ(course) ഇവയിൽ

play08:00

ചിലത് നമ്മൾ പരിശോധിക്കും, പക്ഷേ നമ്മുടെ സന്ദർഭത്തിലെ

play08:05

ഒരു പ്രോഗ്രാം(program) വിവരങ്ങൾ നോക്കുകയും

play08:09

അത് ഒരു നിർദ്ദിഷ്ട ആവശ്യകതയിലേക്ക്

play08:13

കൈകാര്യം ചെയ്യുകയും ചെയ്യുന്ന ഒന്നാണ്.

play08:17

അതിനാൽ, ഇത് ഒരു നമ്പർ(number) എടുത്ത് നമ്പർ(number)

play08:23

പുറത്തെടുക്കുന്നതിനുള്ള ഒരു ചോദ്യം മാത്രമല്ല.

play08:27

അതിൽ കാര്യങ്ങൾ പുനഃക്രമീകരിക്കുന്നതിൽ ഉൾപ്പെടാം. കൂടുതൽ

play08:32

സങ്കീർണ്ണമായ കാര്യങ്ങൾ കമ്പ്യൂട്ടിംഗ്(computing)

play08:34

ചെയ്യുന്നത് ഇതിൽ ഉൾപ്പെടാം. ഒരു പ്രത്യേക

play08:39

രീതിയിൽ വിവരങ്ങൾ ഓർഗനൈസു(organise) ചെയ്യുന്നത്

play08:43

ഇതിൽ ഉൾപ്പെടാം, അതിനാൽ ഈ കണക്കുകൂട്ടലുകൾ

play08:48

കൂടുതൽ ലഘുലേഖയായിത്തീരുന്നു, അതിനെയാണ് നമ്മൾ

play08:52

ഒരു ഡാറ്റാ(data) ഘടന എന്ന് വിളിക്കുന്നത്.

play08:57

അതിനാൽ ഇത് വിശദീകരിക്കുന്നതിന്, നമ്മളിൽ ഭൂരിഭാഗവും

play09:02

കണ്ടതും അൽഗോരിതം(algorithm) മനസിലാക്കാൻ ശ്രമിച്ചതുമായ

play09:05

ഫംഗ്ഷൻ(function) നോക്കാം. m, n എന്നീ രണ്ട് പോസിറ്റീവ്(positive)

play09:12

സംഖ്യകളുടെ ഏറ്റവും വലിയ പൊതു ഹാരകമാണ്

play09:17

ഞാൻ കണക്കാക്കാൻ ആഗ്രഹിക്കുന്ന പ്രോപ്പർട്ടി(property).

play09:21

നമുക്കറിയാവുന്നതുപോലെ, വിഭജിക്കുന്ന ഒരു

play09:24

സംഖ്യയാണ് ഹാരകം. എനിക്ക് m കൊണ്ട്

play09:32

k യെ ഹരിക്കാൻ കഴിയുകയും മിച്ചം ലഭിക്കുന്നില്ലെങ്കിൽ,

play09:38

k എന്നത് m ന്റെ ഹാരകമാണ്.അതിനാൽ, m, n എന്നിവയുടെ ഏറ്റവും

play09:52

വലിയ പൊതുവായ ഹാരകമായിരിക്കണം. അതിനാൽ, പൊതുവായ

play09:57

എന്നതിൻറെ അർത്ഥം ഇത് ഇവ രണ്ടിനെയും

play10:02

ഹരിക്കണം, ഇത് ഇവയിൽ ഏറ്റവും വലുതുമായിരിക്കണം.

play10:06

ഏറ്റവും വലിയ k എന്നത് k , m നെയും k , n നെയും

play10:13

ഹരിക്കുന്നതായിരിക്കണം. ഉദാഹരണത്തിന്, നമ്മൾ

play10:16

8 ഉം 12 ഉം നോക്കുകയാണെങ്കിൽ, 4 എന്നത് 8 ന്റെ ഘടകമാണെന്നും

play10:26

4 എന്നത് 8 ന്റെ ഹാരകമാണെന്നും 4 എന്നത് 12 ന്റെ ഹാരകമാണെന്നും

play10:36

12 ന്റെ മറ്റൊരു ഹാരകം 6 ആണെന്നും എന്നാൽ

play10:43

6 എന്നത് 8 ന്റെ ഹാരകം അല്ലെന്നും കാണാം.

play10:50

അതിനാൽ, 8, 12 എന്നിവയുടെ ഹാരകങ്ങളിലൂടെ കടന്നുപോകുകയാണെങ്കിൽ,

play10:55

8 നെയും 12 നെയും ഹരിക്കുന്ന ഏറ്റവും വലിയ സംഖ്യ

play11:03

4 ആണെന്ന് പരിശോധിക്കുന്നത് എളുപ്പമാണ്. അതിനാൽ,

play11:08

8, 12 എന്നിവയുടെ gcd 4 ആണ്. 18 ഉം 25 ഉം ആണെങ്കിൽ

play11:19

എങ്ങനെയാണ്. 25 എന്നത് 5 ഗുണം 5 ആണ്. അതിനാൽ,

play11:27

ഇതിന് 1 ഉം 25 ഉം ഒഴികെയുള്ള ഒരു ഹാരകം മാത്രമേയുള്ളൂ,

play11:36

അത് 5 ആണ്. കൂടാതെ 5 എന്നത് 18 ന്റെ ഹാരകമല്ല,

play11:45

പക്ഷേ ഭാഗ്യവശാൽ 1 എന്നത് 18 ന്റെ ഹാരകമാണ്.

play11:52

അതിനാൽ, നമുക്ക് പറയാൻ കഴിയും, 18 ൻറെയും

play11:58

25 ൻറെയും gcd 1 ആണ്; 18 നെയും 25 നെയും ഹരിക്കുന്ന

play12:08

1 നെക്കാൾ വലിയ സംഖ്യ ഒന്നുമില്ല. 1 എല്ലാ

play12:15

സംഖ്യകളെയും ഹരിക്കുന്നതിനാൽ, 18, 25 എന്നീ കാര്യങ്ങളിൽ

play12:21

നമ്മൾ കണ്ടതുപോലെ, രണ്ട് സംഖ്യകളിൽ

play12:25

എല്ലായ്പ്പോഴും ഒരു പൊതു ഹാരകമെങ്കിലും

play12:29

ഉണ്ടായിരിക്കും. gcd എല്ലായ്പ്പോഴും

play12:31

നന്നായി നിർവചിക്കപ്പെടും; പൊതുവായ ഹാരകത്തെ

play12:35

കണ്ടെത്താൻ നമുക്ക് ഒരിക്കലും കഴിയില്ല

play12:38

എന്നു വരില്ല എന്നു മാത്രമല്ല എല്ലാ

play12:42

പൊതു ഹാരകങ്ങളും അക്കങ്ങളായിരിക്കുമെന്നതിനാൽ,

play12:45

നമുക്ക് അവയെ ചെറുത് മുതൽ വലുത് വരെ ക്രമീകരിക്കാനും

play12:51

ഏറ്റവും വലിയവയെ ഏറ്റവും വലിയ പൊതുവായ

play12:55

ഹാരകം ആയി തിരഞ്ഞെടുക്കാനും കഴിയും. അതിനാൽ, m,

play13:00

n എന്നീ ഏതെങ്കിലും പോസിറ്റീവ്(positive) സംഖ്യകൾ

play13:03

നൽകിയാൽ, നമുക്ക് തീർച്ചയായും ഈ രണ്ട്

play13:08

അക്കങ്ങളുടെ gcd കണക്കാക്കാം.

play13:11

അപ്പോൾ m, n എന്നിവയുടെ gcd എങ്ങനെ കണക്കു

play13:16

കൂട്ടാം? ഇവിടെയാണ് നമ്മൾ അൽഗോരിതം(algorithm)

play13:20

വഴിയിലേക്ക് വരുന്നത്, ഏത് m അല്ലെങ്കിൽ

play13:25

ഏതെങ്കിലും n നായി m n ന്റെ gcd വ്യവസ്ഥാപിതമായി

play13:38

കണക്കുകൂട്ടുന്നതിനുള്ള ഏകീകൃത മാർഗം വിവരിക്കാൻ

play13:42

നമ്മൾ ആഗ്രഹിക്കുന്നു. വളരെ ലളിതമായ ഒരു

play13:48

നടപടിക്രമമുണ്ട്. ഇത് ഏറ്റവും കാര്യക്ഷമമല്ല;

play13:52

മുന്നോട്ടുപോകുന്നതിന് അനുസരിച്ച് നമുക്ക്

play13:56

നന്നായി മനസ്സിലാക്കാൻ കഴിയും. എന്നാൽ gcdയുടെ

play14:01

നിർവചനം നോക്കുകയാണെങ്കിൽ, അത് പറയുന്നു, m ന്റെ

play14:08

എല്ലാ ഘടകങ്ങളും നോക്കുക, n ന്റെ എല്ലാ

play14:13

ഘടകങ്ങളും നോക്കുക, രണ്ടിന്റെയും ഘടകമായ

play14:15

ഏറ്റവും വലിയ ഘടകം കണ്ടെത്തുക. അതിനാൽ,

play14:19

ഇത് ചെയ്യുന്നതിനുള്ള നിഷ്കളങ്കമായ മാർഗ്ഗം,

play14:21

ആദ്യം m ന്റെ ഘടകങ്ങൾ പട്ടികപ്പെടുത്തുക,

play14:25

തുടർന്ന് രണ്ടാമത്തെ സംഖ്യ n ന്റെ എല്ലാ

play14:30

ഘടകങ്ങളും പട്ടികപ്പെടുത്തുക, തുടർന്ന് ഈ രണ്ട്

play14:35

ലിസ്റ്റുകളിൽ(list), രണ്ട് ലിസ്റ്റുകളിലും(list)

play14:37

ദൃശ്യമാകുന്ന ഏറ്റവും വലിയ സംഖ്യ റിപ്പോർട്ടുചെയ്യുക.

play14:42

ഇത് മിക്കവാറും അക്ഷരാർത്ഥത്തിൽ gcdയുടെ നിർവചനമാണ്.

play14:46

ഇത് ഒരു അൽഗോരിതം(algorithm) ഉൾക്കൊള്ളുന്നുണ്ടോ

play14:50

എന്നതാണ് ഇവിടുത്തെ ചോദ്യം. ഉയർന്ന തലത്തിൽ,

play14:54

ഘടകങ്ങളെ ഒരൊറ്റ ഘട്ടമായി ലിസ്റ്റ്

play14:58

ഔട്ട്(list out) ചെയ്യുന്നതിനെക്കുറിച്ച് ചിന്തിക്കുകയാണെങ്കിൽ,

play15:01

ഒരു അൽഗോരിതത്തിൽ(algorithm) നിന്ന് നമുക്ക് വേണ്ടത്

play15:05

രണ്ട് കാര്യങ്ങളാണ്. ഒന്ന്, എന്തുചെയ്യണമെന്നതിന്റെ

play15:09

വിവരണം പരിമിതമായ രീതിയിൽ എഴുതിയിരിക്കണം.

play15:12

ആ അർത്ഥത്തിൽ, m, n എന്നിവയുടെ മൂല്യം കണക്കിലെടുക്കാതെ

play15:17

തന്നെ അത് വായിക്കാനും മനസിലാക്കാനും കഴിയുന്ന

play15:20

തരത്തിൽ നിർദ്ദേശങ്ങൾ എഴുതാൻ എനിക്ക് കഴിയണം.

play15:23

ഇവിടെ വളരെ വ്യക്തമാണ്, നമുക്ക് കൃത്യമായി

play15:26

മൂന്ന് ഘട്ടങ്ങളുണ്ട്. അതിനാൽ, അൽ‌ഗോരിതം(algorithm)

play15:28

രൂപീകരിക്കുന്നതിന് നമുക്ക് മൂന്ന് ഘട്ടങ്ങളുണ്ട്,

play15:30

അതുവഴി ഇത് ഒരു പരിമിത രീതിയിൽ അവതരിപ്പിക്കാൻ

play15:34

കഴിയും. ഒരു അൽ‌ഗോരിതത്തിന്റെ(algorithm) മറ്റൊരു ആവശ്യകത,

play15:37

പരിമിതമായ എണ്ണം ഘട്ടങ്ങൾക്ക് ശേഷം

play15:39

നമുക്ക് ഉത്തരം ലഭിക്കണം എന്നതാണ്. ഇതിൽ, m,

play15:42

n എന്നിവയുടെ വ്യത്യസ്ത മൂല്യങ്ങൾക്ക് പരിമിതമായ

play15:44

എണ്ണം ഘട്ടങ്ങൾ വ്യത്യസ്തമായിരിക്കാം, നിങ്ങൾക്ക് n- ന് വളരെ

play15:48

ചെറിയ സംഖ്യയുണ്ടെങ്കിൽ ധാരാളം ഘടകങ്ങളില്ലെന്ന്

play15:50

നിങ്ങൾക്ക് ഊഹിക്കാനാകും, n ഒരു വളരെ വലിയ സംഖ്യയാണെങ്കിൽ

play15:56

നിങ്ങൾക്ക് നിരവധി ഘടകങ്ങളുണ്ടാകാം.

play15:59

അതിനാൽ, m, n എന്നിവയുടെ ഘടകങ്ങൾ ലിസ്റ്റു(list)

play16:02

ചെയ്യുന്നതിന് വളരെയധികം സമയമെടുക്കും; എന്നിരുന്നാലും,

play16:03

ഈ പ്രക്രിയ എല്ലായ്പ്പോഴും അവസാനിക്കുമെന്ന്

play16:04

നമ്മൾ ഉറപ്പുനൽകാൻ ആഗ്രഹിക്കുന്നു,

play16:05

തുടർന്ന് ഇത് ചെയ്തുകഴിഞ്ഞാൽ രണ്ട് ലിസ്റ്റുകളിലും(list)

play16:06

ദൃശ്യമാകുന്ന ഏറ്റവും വലിയ സംഖ്യ കണ്ടെത്താൻ

play16:07

നമുക്ക് കഴിയും.

play16:08

ഈ പ്രക്രിയ നന്നായി നിർവചിക്കപ്പെട്ടിട്ടുണ്ടെന്ന്

play16:09

വാദിക്കാൻ, നമ്മൾ തിരിച്ചറിയേണ്ടത്

play16:10

m ന്റെ ഘടകങ്ങൾ 1 നും m നും ഇടയിലായിരിക്കണം

play16:12

എന്നതാണ്. മറ്റൊരു വിധത്തിൽ പറഞ്ഞാൽ,

play16:14

ഘടകങ്ങളായി അനന്തമായ വ്യത്യസ്ത സാധ്യതകളുണ്ടെങ്കിലും,

play16:17

m നെക്കാൾ വലിയ ഒരു സംഖ്യയും നാം നോക്കേണ്ടതില്ല,

play16:22

അതിനാൽ, m ന്റെ ഘടകങ്ങൾ കണക്കുകൂട്ടാൻ നമ്മൾ

play16:23

ചെയ്യേണ്ടത്, ഒന്ന് മുതൽ m വരെയുള്ള ശ്രേണിയിലെ

play16:26

ഓരോ സംഖ്യയും പരിശോധിക്കുക എന്നതാണ്, കൂടാതെ

play16:31

ശിഷ്ടം ഇല്ലാതെ m നെ ഹരിക്കാൻ പറ്റുകയാണെങ്കിൽ,

play16:35

നമ്മൾ അതിനെ ഘടകങ്ങളുടെ പട്ടികയിലേക്ക്

play16:39

ചേർക്കുന്നു. ഘടകങ്ങളുടെ ശൂന്യമായ ലിസ്റ്റിൽ(list)

play16:42

നിന്നാണ് നമ്മൾ ആരംഭിക്കുന്നത്, അത് 1, 2, 3, 4 മുതൽ m വരെ

play16:50

പരിഗണിക്കുന്നു, അത്തരം ഓരോ സംഖ്യയ്ക്കും,

play16:52

ഈ സംഖ്യയെ m കൊണ്ട് ഹരിച്ചാൽ നമുക്ക്

play16:55

0 ശിഷ്ടം ആയി ലഭിക്കുന്നുണ്ടോ എന്ന് നമ്മൾ പരിശോധിക്കുന്നു,

play17:01

നമുക്ക് 0 ശിഷ്ടം ലഭിക്കുകയാണെങ്കിൽ

play17:05

നമ്മൾ അത് പട്ടികയിലേക്ക് ചേർക്കുന്നു.

play17:08

നമുക്ക് വ്യക്തമായ ഉദാഹരണം നോക്കാം,

play17:12

നമുക്ക് 14, 63 എന്നിവയുടെ gcd കണക്കുകൂട്ടാൻ

play17:17

ശ്രമിക്കാം. അതിനാൽ, നമ്മുടെ അൽഗോരിതത്തിന്റെ(algorithm)

play17:20

ആദ്യ ഘട്ടം 14 ന്റെ ഘടകങ്ങൾ കണക്കുകൂട്ടാൻ

play17:26

പറയുന്നു. മുകളിലുള്ള നമ്മുടെ നിരീക്ഷണത്തിലൂടെ,

play17:29

14 ന്റെ ഘടകങ്ങൾ ഒന്നിനും 14 നും ഇടയിൽ ഉണ്ടാവണം,

play17:36

14 നെക്കാൾ വലുതായ ഒന്നും ഒരു ഘടകമാകില്ല.

play17:41

അതിനാൽ, ഒന്ന് മുതൽ 14 വരെ സാധ്യമായ എല്ലാ

play17:47

ഘടകങ്ങളും ലിസ്റ്റു(list) ചെയ്യാനും അവ പരീക്ഷിക്കാനും

play17:51

നമ്മൾ ആരംഭിക്കുന്നു. 1 എല്ലായ്പ്പോഴും

play17:55

ഹരിക്കുമെന്ന് നമുക്കറിയാം; ഈ സാഹചര്യത്തിൽ 14

play17:59

നെ 2 ഹരിക്കുന്നു, കാരണം 14 നെ 2 കൊണ്ട്

play18:06

ഹരിച്ചാൽ ശിഷ്ടം ഇല്ലാതെ 7 ശേഷിക്കുന്നു.

play18:10

ഇപ്പോൾ 3 ഹരിക്കുന്നില്ല, 4 ഹരിക്കുന്നില്ല,

play18:14

5 ഹരിക്കുന്നില്ല, 6 ഹരിക്കുന്നില്ല;

play18:18

എന്നാൽ 7 ചെയ്യുന്നു, കാരണം 14 നെ 7 കൊണ്ട്

play18:25

ഹരിച്ചാൽ നമുക്ക് 0 ശിഷ്ടം ആയി ലഭിക്കും.

play18:30

പിന്നീട് 8 ഹരിക്കപ്പെടുന്നില്ല, ഒമ്പത് ഹരിക്കുന്നില്ല,

play18:34

അങ്ങനെ. അവസാനമായി, അവശേഷിക്കുന്ന

play18:37

മറ്റൊരു ഘടകം 14 തന്നെയാണെന്ന് നമ്മൾ കണ്ടെത്തി.

play18:42

അതിനാൽ m എന്ന ഓരോ സംഖ്യയ്ക്കും, 1, m

play18:45

എന്നിവ ഘടകങ്ങളായിരിക്കും, അതിനിടയിൽ ഘടകങ്ങൾ

play18:47

ഉണ്ടാകാം.

play18:48

അതിനാൽ, ഇത് ചെയ്തുകഴിഞ്ഞാൽ, 14 ന്റെ ഘടകങ്ങൾ നമ്മൾ

play18:52

തിരിച്ചറിഞ്ഞു, ഈ ഘടകങ്ങൾ കൃത്യമായി

play18:54

1, 2, 7, 14 എന്നിവയാണ്.

play18:57

14, 63 എന്നിവയുടെ gcd കണക്കുകൂട്ടുന്നതിനുള്ള

play19:00

അടുത്ത ഘട്ടം 63 ന്റെ ഘടകങ്ങൾ കണക്കുകൂട്ടുക

play19:04

എന്നതാണ്. അതിനാൽ, അതുപോലെ തന്നെ, 1 മുതൽ

play19:07

63 വരെയുള്ള എല്ലാ അക്കങ്ങളും നമ്മൾ

play19:10

എഴുതുകയും ഏതെല്ലാം സംഖ്യകൾ ഇവയെ ഹരിക്കുന്നുവെന്ന്

play19:14

പരിശോധിക്കുകയും ചെയ്യുന്നു. വീണ്ടും,

play19:15

1 ഹരിക്കുന്നു, ഇവിടെ 2 ഹരിക്കുന്നില്ല;

play19:18

63 എന്നത് ഇരട്ട സംഖ്യയല്ല, 3 ഹരിക്കുന്നു, എന്നിട്ട്

play19:23

ഹരിക്കാത്ത ഒരു കൂട്ടം സംഖ്യകൾ ഇവിടെ കാണാം.

play19:26

അപ്പോൾ 7 ഹരിക്കുന്നു, കാരണം 7 ഗുണം 9, 63 ആണ്.

play19:32

വീണ്ടും 8 ഹരിക്കുന്നില്ല, പക്ഷേ 9 ഹരിക്കുന്നു.

play19:35

പിന്നീട് വീണ്ടും വലിയ സംഖ്യകളുണ്ട്,

play19:38

അവ ഹരിക്കുന്നില്ല. എന്നിട്ട് 21 ഹരിക്കുന്നു,

play19:41

കാരണം 21 ഗുണം 3, 63 ആണ്. ഒടുവിൽ, നമ്മുടെ

play19:46

അവസാനത്തെ ഘടകം 63 ആണെന്ന് നമ്മൾ കണ്ടെത്തുന്നു.

play19:49

ഒന്ന് മുതൽ 63 വരെ നമ്മൾ യഥാക്രമം ആയി

play19:53

കടന്നുപോകുന്നു, ഒരു ഘടകമല്ലാത്ത

play19:55

ഓരോ സംഖ്യയും മറികടന്ന്, നമ്മൾ 1, 3, 7, 9, 21, 63 പട്ടികയിൽ

play20:02

അവസാനിക്കുന്നു. 14, 63 എന്നീ രണ്ട് അക്കങ്ങളുടെ

play20:05

ഘടകങ്ങൾ കണക്കുകൂട്ടിയ ശേഷം, നമ്മുടെ അൽഗോരിതത്തിന്റെ(algorithm)

play20:08

അടുത്ത ഘട്ടം പറയുന്നു, രണ്ട് ലിസ്റ്റിലും(list)

play20:11

ദൃശ്യമാകുന്ന ഏറ്റവും വലിയ ഘടകം നമ്മൾ

play20:15

കണ്ടെത്തണം. അതിനാൽ, നമ്മൾ ഇത് എങ്ങനെ

play20:18

ചെയ്യും, പൊതുവായ ഘടകങ്ങളുടെ ഒരു പട്ടിക

play20:21

എങ്ങനെ നിർമ്മിക്കും. ഇപ്പോൾ ഇത് ചെയ്യാൻ

play20:24

കൂടുതൽ ബുദ്ധിപരമായ വഴികളുണ്ട്, എന്നാൽ

play20:26

ഇവിടെ വളരെ ലളിതമായ ഒരു മാർഗമുണ്ട്.

play20:29

നമ്മൾ ഒരു ലിസ്റ്റിലൂടെ(list) കടന്നുപോകുന്നു,

play20:31

അതായത്, 14 ന്റെ ഘടകങ്ങളുടെ പട്ടിക, പട്ടികയിലെ

play20:35

ഓരോ ഇനവും 63 ന്റെ ഘടകമാണോ എന്ന് നമ്മൾ

play20:39

പരിശോധിക്കുന്നു. അതിനാൽ, നമ്മൾ 1 ൽ

play20:42

നിന്ന് ആരംഭിക്കുന്നു, 1 എന്നത് 63 ന്റെ ഘടകമായി

play20:47

കാണപ്പെടുന്നുണ്ടോ എന്ന് നോക്കുന്നു.

play20:48

ഇത് കാണപ്പെടുന്നുണ്ട്, അതിനാൽ നമ്മൾ ഇത്

play20:51

പൊതു ഘടകങ്ങളുടെ പട്ടികയിലേക്ക്

play20:53

ചേർക്കുന്നു. അപ്പോൾ ഇനി നമ്മൾ 2 നോക്കുന്നു,

play20:57

എന്നിട്ട് അത് ദൃശ്യമാകുമോ എന്ന് നമ്മൾ ചോദിക്കുന്നു;

play21:00

അത് ദൃശ്യമാകാത്തതിനാൽ നമ്മൾ അത് ഒഴിവാക്കുന്നു.

play21:03

എന്നിട്ട് നമ്മൾ 3 നോക്കുകയും 7 നോക്കുകയും

play21:07

ചെയ്യുന്നു, എന്നാൽ 7 ദൃശ്യമാകുന്നതിനാൽ

play21:09

നമ്മൾ 7 ചേർക്കുകയും ചെയ്യുന്നു. ഒടുവിൽ,

play21:13

നമ്മൾ 14 നോക്കുകയും 14 ദൃശ്യമാകുന്നില്ലെന്ന്

play21:16

കണ്ടെത്തുകയും അതിനാൽ അത് ഒഴിവാക്കുകയും

play21:18

ചെയ്യുന്നു. ഈ രീതിയിൽ നമ്മൾ യഥാക്രമം ആയി

play21:22

1, 2, 7, 14 എന്നിവയിലൂടെ കടന്നുപോയി, ഇവയിൽ

play21:26

1, 7 എന്നിവ മാത്രമേ രണ്ട് ലിസ്റ്റിലും(list)

play21:29

ദൃശ്യമാകൂ എന്ന് നിഗമനം ചെയ്തു.

play21:32

ഇപ്പോൾ ഇത് ചെയ്തുകഴിഞ്ഞാൽ, ചെറിയതിൽ നിന്ന്

play21:35

വലിയതിലേക്ക് നമ്മൾ കണക്കാക്കിയ പൊതുവായ

play21:37

എല്ലാ ഘടകങ്ങളുടെയും ഒരു ലിസ്റ്റ്(list) നമ്മുടെ

play21:40

പക്കലുണ്ട്, കാരണം ആരോഹണ ക്രമത്തിൽ

play21:43

14 ന്റെ ഘടകങ്ങളിലേക്ക് നമ്മൾ പോയി. അതിനാൽ,

play21:46

ഈ ലിസ്റ്റും(list) ആരോഹണ ക്രമത്തിലായിരിക്കും.

play21:49

വലിയ ഘടകം റിട്ടേൺ(return) ചെയ്യുക എന്ന് പറയുന്നത്,

play21:52

ഈ ലിസ്റ്റിലെ(list) ഏറ്റവും വലതുവശത്തെ ഘടകം

play21:55

റിട്ടേൺ(return) ചെയ്യുക എന്നുള്ളതാണ്, അതായത്

play21:58

7. അപ്പോൾ ഇതാണ് നമ്മുടെ ഫംഗ്ഷന്റെ(function) ഔട്ട്‌പുട്ട്(output).

play22:01

നമ്മൾ 14 ന്റെ ഘടകങ്ങൾ കണക്കുകൂട്ടി, 63 ന്റെ

play22:06

ഘടകങ്ങൾ കണക്കുകൂട്ടി, 14 ന്റെ ഓരോ ഘടകങ്ങളും

play22:09

യഥാക്രമം ആയി പരിശോധിച്ചു, ഇത് 63 ന്റെ ഒരു ഘടകമാണോ

play22:14

എന്ന് പരിശോധിക്കുകയും ഇവിടെയുള്ള പൊതു

play22:17

ഘടകങ്ങളുടെ പട്ടിക കണക്കുകൂട്ടുകയും,

play22:18

തുടർന്ന് ഈ പട്ടികയിൽ നിന്ന് നമ്മൾ ഏറ്റവും

play22:22

വലുത് എക്‌സ്‌ട്രാക്റ്റു(extract) ചെയ്യുകയും ചെയ്തു,

play22:24

ഇത് വാസ്തവത്തിൽ, നമ്മുടെ gcd ആണ്. ഈ അൽഗോരിതം(algorithm)

play22:27

എങ്ങനെ പ്രവർത്തിപ്പിക്കും എന്നതിന്റെ ഒരു ഉദാഹരണമാണിത്.

play22:28

നിങ്ങൾ‌ക്കത് കുറച്ചുകൂടി വിശദമായി എഴുതേണ്ടിവന്നാൽ‌,

play22:29

ഈ ലിസ്റ്റുകൾ‌(list) നമ്മൾ ഓർത്തിരിക്കേണ്ടതുണ്ടെന്ന്

play22:30

നമ്മൾ ശ്രദ്ധിക്കേണ്ടതുണ്ട്, തുടർന്ന്‌ അവയിലേക്ക്

play22:31

മടങ്ങുക. അതിനാൽ, നമ്മൾ 14 ന്റെ ഘടകങ്ങൾ

play22:32

കണക്കുകൂട്ടേണ്ടതുണ്ട്, അത് ഒരു വശത്ത് വയ്ക്കുക,

play22:33

അത് എവിടെയെങ്കിലും എഴുതുക, 63 ന്റെ ഘടകം

play22:34

കണക്കുകൂട്ടേണ്ടതുണ്ട്, അത് എവിടെയെങ്കിലും

play22:35

എഴുതുക, തുടർന്ന് ഈ രണ്ട് ലിസ്റ്റുകളും(list)

play22:36

താരതമ്യം ചെയ്യുക. അതിനാൽ, മറ്റൊരു

play22:37

വിധത്തിൽ പറഞ്ഞാൽ ഇവ സംഭരിക്കുന്നതിന്

play22:38

നമ്മൾ ചില പേരുകൾ നൽകേണ്ടതുണ്ട്. m

play22:39

ന്റെ ഘടകങ്ങൾക്ക് fm എന്നും n ന്റെ ഘടകങ്ങൾക്ക്

play22:43

fn എന്നും ഈ ലിസ്റ്റുകൾക്ക്(list) പേരുകൾ നൽകാം. അതിനാൽ,

play22:50

നമ്മൾ ചെയ്യുന്നത് ഒന്ന് മുതൽ m വരെയുള്ള

play22:54

അക്കങ്ങളിലൂടെ കടന്നുപോകുക എന്നതാണ്. ഓരോ i നും,

play22:56

ഈ പട്ടിക 1 മുതൽ m വരെ, i m ഹരിക്കുന്നുണ്ടോ,

play22:59

i m കൊണ്ട് ഹരിച്ചാൽ എനിക്ക് ശിഷ്ടം 0

play23:04

ലഭിക്കുന്നുണ്ടോ എന്ന് പരിശോധിക്കുന്നു,

play23:06

അങ്ങനെയാണെങ്കിൽ m അല്ലെങ്കിൽ fm ന്റെ

play23:09

ലിസ്റ്റ്(list) ഘടകങ്ങളിലേക്ക് നമ്മൾ ഇത് ചേർക്കുന്നു.

play23:11

അതുപോലെ, 1 മുതൽ n വരെ ഉള്ള ഓരോ j നും, j n നെ

play23:15

ഹരിക്കുന്നുണ്ടോയെന്ന് പരിശോധിക്കുന്നു,

play23:16

അങ്ങനെയാണെങ്കിൽ നമ്മൾ അത് fn പട്ടികയിലേക്ക്

play23:17

ചേർക്കുന്നു. ഇപ്പോൾ നമുക്ക് fm,

play23:18

fn എന്നീ രണ്ട് ലിസ്റ്റുകൾ(list) ഉണ്ട്, അവ m ന്റെ ഘടകങ്ങളും

play23:21

n ന്റെ ഘടകങ്ങളുമാണ്. ഇപ്പോൾ നമ്മൾ പൊതു

play23:26

ഘടകങ്ങളുടെ പട്ടിക കണക്കുകൂട്ടാൻ ആഗ്രഹിക്കുന്നു,

play23:29

അതിനെ നമ്മൾ cf എന്ന് വിളിക്കും. അതിനാൽ,

play23:34

നമ്മൾ ചെയ്യുന്നത്, ആദ്യത്തെ സംഖ്യയുടെ

play23:37

ഘടകമായ ഓരോ f നും, നമ്മുടെ കാര്യത്തിൽ

play23:42

14 ആയിരുന്നു എന്ന് ഓർക്കുക, അവിടെ ഓരോ

play23:47

f നും 1, 2, 7, 14 എന്നിവയിലൂടെ കടന്നുപോകാം. അതിനാൽ,

play23:55

ഓരോ f നും, മറ്റ് ലിസ്റ്റിലും(list) ഉണ്ടെങ്കിൽ, പൊതു

play24:01

ഘടകങ്ങളുടെ പട്ടികയിലേക്ക് നമ്മൾ f ചേർക്കുന്നു.

play24:04

അതിനാൽ, മറ്റ് പട്ടികയിൽ‌, നിങ്ങളുടെ നമ്പർ‌(number)

play24:06

1, 3, 7, 9, 21, 63 ആണെങ്കിൽ‌, അതിനാൽ‌, നമ്മൾ ഈ

play24:10

പട്ടികയുമായി f നെ താരതമ്യം ചെയ്യുന്നു,

play24:13

നമ്മൾ അത് കണ്ടെത്തിയാൽ‌ അത് cf ലേക്ക് ചേർ‌ക്കുന്നു.

play24:16

ഇപ്പോൾ ഇത് ചെയ്തുകഴിഞ്ഞാൽ, പൊതു ഘടകങ്ങളുടെ

play24:18

പട്ടികയുടെ ഏറ്റവും വലിയ മൂല്യം തിരികെ

play24:19

നൽകാൻ നമ്മൾ ആഗ്രഹിക്കുന്നു. ഒന്ന് എല്ലായ്പ്പോഴും

play24:21

ഒരു പൊതു ഘടകമായിരിക്കുമെന്ന് ഓർമ്മിക്കുക. അതിനാൽ,

play24:23

cf ലിസ്റ്റ്(list) ശൂന്യമായിരിക്കില്ല. കുറഞ്ഞത് ഒരു മൂല്യമെങ്കിലും

play24:25

ഉണ്ടാകും, പക്ഷേ നമ്മൾ അവയെ ആരോഹണ

play24:26

ക്രമത്തിൽ ചേർത്തതിനാൽ, fm ലിസ്റ്റ്(list) 1 മുതൽ

play24:28

m വരെയും fn ലിസ്റ്റ്(list) 1 മുതൽ n വരെയും നിർമ്മിച്ചതിനാൽ,

play24:30

ഏറ്റവും വലിയ മൂല്യം ഏറ്റവും വലതുവശത്തെ

play24:33

മൂല്യമായിരിക്കും. ഇത് gcdക്ക് കുറച്ചുകൂടി

play24:36

വിശദമായ അൽഗോരിതം(algorithm) നൽകുന്നു. m ന്റെ ഘടകങ്ങളുടെ

play24:38

പട്ടിക എങ്ങനെ കണക്കാക്കാം, n ന്റെ ഘടകങ്ങളുടെ

play24:39

പട്ടിക എങ്ങനെ കണക്കാക്കാം, ഈ രണ്ട് ലിസ്റ്റുകൾക്കിടയിലെ(list)

play24:42

ഏറ്റവും വലിയ ഘടകത്തെ എങ്ങനെ കണക്കാക്കാം

play24:44

എന്നതിനെക്കുറിച്ചുള്ള കൂടുതൽ വിശദാംശങ്ങൾ

play24:45

നൽകുന്നത് ഒഴികെ ഇത് മുൻപത്തേതു പോലെ

play24:47

തന്നെയാണ്. അതിനാൽ, നേരത്തെ നമുക്ക്

play24:49

മൂന്ന് സംഗ്രഹ പ്രസ്താവനകൾ ഉണ്ടായിരുന്നു, ഇപ്പോൾ

play24:51

നമ്മൾ 6 കുറച്ചുകൂടി വിശദമായ പ്രസ്താവനകൾ

play24:53

ആയി വികസിപ്പിച്ചു.

play24:54

നമ്മുടെ ആദ്യത്തെ പൈത്തൺ(python) പ്രോഗ്രാം(program)

play24:56

എഴുതാൻ ഇത് ഇതിനകം തന്നെ മതിയായ വിവരങ്ങൾ

play24:58

നൽകുന്നു. തീർച്ചയായും, ഇത് എങ്ങനെ എഴുതണമെന്ന്

play25:00

അറിയുന്നതിനുമുമ്പ് നമ്മൾ കുറച്ചുകൂടി

play25:02

പഠിക്കേണ്ടതുണ്ട്, പക്ഷേ അത് എങ്ങനെ

play25:03

വായിക്കാമെന്ന് നമുക്ക് തീർച്ചയായും

play25:05

കണ്ടെത്താനാകും. അതിനാൽ, ഈ പൈത്തൺ

play25:06

പ്രോഗ്രാമിംഗ്(python programming) ചെയ്യുന്നത്

play25:08

നമ്മൾ മുമ്പത്തെ ഘട്ടത്തിൽ അനൗപചാരികമായി

play25:09

വിവരിച്ചതാണ്. പൈത്തൺ പ്രോഗ്രാമിലെ(python

play25:11

program) ആദ്യ കാര്യം ഫംഗ്ഷനെ(function) നിർവചിക്കുന്ന ഒരു

play25:13

വരിയാണ്. അതിനാൽ, m, n ന്റെ gcd എന്ന ഫംഗ്ഷൻ(function)

play25:17

നമ്മൾ നിർവചിക്കുന്നു. അതിനാൽ, ഏതൊരു ഫംഗ്ഷനും(function)

play25:18

പോലെ ഏത് സംഖ്യയും ആകാവുന്ന രണ്ട് ആർഗ്യുമെന്റുകളാണ്(argument)

play25:19

m, n എന്നിവ. ഗണിതശാസ്ത്രത്തിൽ നമ്മൾ f (x, y) എന്ന് വായിക്കുന്നത്

play25:24

പോലെയാണ്, ഇതിനർത്ഥം x, y എന്നിവ മദ്ധ്യസ്ഥ

play25:27

മൂല്യങ്ങളാണെന്നും, ഓരോ x, y എന്നിവയ്‌ക്കും,

play25:30

നമ്മൾ ഫംഗ്ഷൻ(function) വിളിക്കാൻ ഉപയോഗിക്കുന്ന

play25:31

മൂല്യങ്ങളെ ആശ്രയിച്ച് എന്തെങ്കിലും ചെയ്യുക.

play25:32

അതിനാൽ, ഇത് ഒരു നിർവചനമാണെന്ന് ഇത് പറയുന്നു, അതിനാൽ

play25:34

gcd (m, n) എന്ന ഫംഗ്ഷന്റെ(function) നിർവചനത്തിനായി

play25:35

def. ഇപ്പോൾ ആദ്യപടിയായി

play25:36

m ന്റെ ഘടകങ്ങളുടെ പട്ടിക കണക്കുകൂട്ടുക.

play25:37

പൈത്തണിൽ(python) ചതുര ബ്രാക്കറ്റുകൾ(bracket)

play25:38

ഉപയോഗിച്ച് നമ്മൾ ഒരു ലിസ്റ്റ്(list) എഴുതുന്നു.

play25:39

അതിനാൽ, പട്ടിക [x, y, z] എന്നിങ്ങനെ എഴുതിയിരിക്കുന്നു.

play25:40

അതിനാൽ, ശൂന്യമായ പട്ടിക രണ്ടു സ്ക്വയർ

play25:41

ബ്രാക്കറ്റുകൾ (bracket) മാത്രമാണ്. അതിനാൽ,

play25:42

ഘടകങ്ങളുടെ ശൂന്യമായ ഒരു പട്ടിക ഉപയോഗിച്ച്

play25:43

നമ്മൾ ആരംഭിക്കുന്നു. ഈ സമത്വം അർത്ഥമാക്കുന്നത്

play25:44

ഒരു മൂല്യം നൽകുക എന്നാണ്. അതിനാൽ,

play25:45

fm എന്ന m ന്റെ ഘടകങ്ങളുടെ പട്ടിക ശൂന്യമായ

play25:46

പട്ടികയായി നൽകുന്നു. 1 മുതൽ n വരെയുള്ള

play25:47

ശ്രേണിയിലെ എല്ലാ മൂല്യങ്ങളും ഇപ്പോൾ

play25:48

പരിശോധിക്കേണ്ടതുണ്ട്. ഇപ്പോൾ പൈത്തണിന്(python)

play25:49

റേഞ്ച്(range) എന്ന് വിളിക്കുന്ന ഒരു

play25:50

ബിൽറ്റ് ഇൻ ഫംഗ്ഷൻ(built in function) ഉണ്ട്, എന്നാൽ

play25:54

പൈത്തണിന്റെ(python) പ്രത്യേകത കാരണം

play25:56

ഇത് നിങ്ങൾ പ്രതീക്ഷിക്കുന്ന ശ്രേണി നൽകില്ല,

play26:00

പക്ഷേ അതിൽ ഒന്ന് കുറവാണ് നൽകുന്നത്.

play26:04

അതിനാൽ, 1 മുതൽ n +1 വരെയുള്ള ശ്രേണിയിലെ സംഖ്യകൾ

play26:08

നൽകുക, അത് എനിക്ക് ഒന്ന് മുതൽ m വരെയുള്ള

play26:10

ശ്രേണിയിൽ ഒന്ന് നൽകുന്നു, ഒന്ന്

play26:11

മുതൽ മുകളിലെ പരിധി വരെ, എന്നാൽ ഉയർന്ന

play26:12

പരിധി ഉൾപ്പെടുന്നില്ല. അതിനാൽ, ഞാൻ 1,2,3 മുതൽ

play26:13

m വരെ ഉള്ള മൂല്യങ്ങൾ എടുക്കുന്നുവെന്ന്

play26:14

ഇത് പറയും. i ന്റെ ഈ ഓരോ മൂല്യങ്ങൾക്കും,

play26:15

ഇത് ശരിയാണോ എന്ന് പരിശോധിക്കുന്നു.

play26:16

ഇവിടെ ശിഷ്ടത്തിൻറെ ചിഹ്നമാണ് %.

play26:17

i m നെ ഹരിച്ചാൽ ശിഷ്ടം 0 ആണോ കിട്ടുന്നത്

play26:19

എന്ന് പരിശോധിക്കുക. i m നെ ഹരിച്ചാൽ ശിഷ്ടം

play26:20

0 ആണെങ്കിൽ, അതിനുശേഷം നമ്മൾ fn ലിസ്റ്റിലേക്ക്(list)

play26:21

i കൂട്ടിച്ചേർക്കും, നമ്മൾ അത് വലതുവശത്ത്

play26:23

ചേർക്കും, ലിസ്റ്റിന്റെ(list) അവസാനത്തിൽ ചേർക്കുക

play26:25

എന്ന് അർത്ഥം വരുന്ന ഇംഗ്ലീഷ്(English) പദമാണ്

play26:28

അപ്പൻഡ്(append). അതിനാൽ, നമ്മൾ i n ലേക്ക് കൂട്ടിച്ചേർക്കുന്നു.

play26:31

അതിനാൽ, ഈ ഘട്ടത്തിൽ, നമ്മൾ fm കണക്കുകൂട്ടി.

play26:32

മുമ്പത്തെ ഉദാഹരണത്തിൽ‌ നമ്മൾ അനൗപചാരികമായി

play26:33

എഴുതിയത് ഇതാണ്, 1 മുതൽ m വരെ ഓരോ i നും,

play26:34

i m നെ ഹരിച്ചാൽ i fm ലേക്ക് ചേർക്കുക, ഇപ്പോൾ

play26:35

നമ്മൾ അത് പൈത്തൺ(python) വാക്യഘടനയിൽ ചെയ്തു.

play26:36

നമ്മൾ ഘടകങ്ങളുടെ ഒരു ശൂന്യമായ ലിസ്റ്റ്(list)

play26:37

നിർ‌വ്വചിച്ചു, ആ ശ്രേണിയിലെ ഓരോ നമ്പറിനെയും(number)

play26:38

ഇത് ഒരു ഹാരകമാണോയെന്ന് പരിശോധിച്ച് അത്

play26:39

ചേർക്കുക. ഇപ്പോൾ ഇവിടെ നമ്മൾ

play26:40

n നും ഇതു പോലെ തന്നെ ചെയ്യുന്നു. അതിനാൽ,

play26:41

n ന്റെ ഘടകങ്ങളുടെ ശൂന്യമായ പട്ടികയിൽ‌

play26:42

നിന്നാണ് നമ്മൾ ആരംഭിക്കുന്നത്, ഈ ശ്രേണിയിലെ ഓരോ

play26:43

j യും ഹരിച്ചാൽ‌ നമ്മൾ അതിനെ കൂട്ടിച്ചേർക്കുന്നു.

play26:44

ഇപ്പോൾ, ഈ സമയത്ത് നമുക്ക് രണ്ട് പട്ടിക

play26:45

fm ഉം fn ഉം ഉണ്ട്. ഇപ്പോൾ, പൊതു ഘടകങ്ങളുടെ

play26:46

പട്ടിക കണക്കാക്കാൻ നമ്മൾ ആഗ്രഹിക്കുന്നു.

play26:47

അതിനാൽ, പൊതു ഘടകങ്ങളുടെ പട്ടിക സൂചിപ്പിക്കാൻ

play26:48

നമ്മൾ cf ഉപയോഗിക്കുന്നു. തുടക്കത്തിൽ പൊതു

play26:49

ഘടകങ്ങളൊന്നുമില്ല. ഇപ്പോൾ, ആദ്യ പട്ടികയിലെ

play26:50

ഓരോ ഘടകത്തിനും രണ്ടാമത്തെ പട്ടികയിൽ‌ ഘടകം

play26:51

പ്രത്യക്ഷപ്പെടുകയാണെങ്കിൽ‌ നമ്മൾ അതിനെ cf ലേക്ക്

play26:52

കൂട്ടിച്ചേർക്കുന്നു. അതിനാൽ, അപ്പൻഡ്(append)

play26:53

എന്ന അതേ ഫംഗ്ഷൻ(function) ഉടനീളം ഉപയോഗിക്കുന്നു.

play26:54

ഒരു ലിസ്റ്റ്(list) എടുത്ത് ഒരു മൂല്യം ചേർക്കുക.

play26:55

ഏത് മൂല്യം? നിബന്ധനകളെ തൃപ്തിപ്പെടുത്തുന്നുവെങ്കിൽ,

play26:56

നമ്മൾ ഇപ്പോൾ നോക്കുന്ന മൂല്യം നമ്മൾ ചേർക്കുന്നു.

play26:57

അതിനാൽ, നേരത്തെ നമ്മൾ ശിഷ്ടം 0 ആണെങ്കിൽ

play26:58

ചേർക്കുകയായിരുന്നു, ഇപ്പോൾ ഇത് രണ്ട്

play26:59

ലിസ്റ്റിലും(list) ദൃശ്യമാകുമ്പോൾ നമ്മൾ ഇത് ചേർക്കുന്നു.

play27:00

ആദ്യ പട്ടികയിലെ ഓരോ f ഉം രണ്ടാമത്തെ

play27:01

പട്ടികയിലും പ്രത്യക്ഷപ്പെടുകയാണെങ്കിൽ, അത് ചേർക്കുക.

play27:02

ഇതിനുശേഷം നമ്മൾ fm, cf കണക്കുകൂട്ടി.

play27:03

ഇപ്പോൾ നമുക്ക് ഏറ്റവും വലതുവശത്തെ ഘടകം

play27:04

വേണം. അതിനാൽ, ഇത് ചില പൈത്തൺ(python) വാക്യഘടന

play27:05

മാത്രമാണ്, പകരം ഇടതുവശത്ത് നിന്ന്

play27:06

എണ്ണാൻ തുടങ്ങിയാൽ പട്ടികയിലെ സ്ഥാനങ്ങളുടെ

play27:07

നമ്പർ(number) 0, 1, 2, 3, 4 എന്നിങ്ങനെയാണ്. എന്നാൽ പൈത്തണിന്(python)

play27:08

ഒരു കുറുക്കുവഴി ഉണ്ട് നിങ്ങൾക്ക്

play27:09

വലതുവശത്ത് നിന്ന് എണ്ണാൻ താൽപ്പര്യമുണ്ട്,

play27:10

തുടർന്ന് നമ്മൾ അക്കങ്ങളെ മൈനസ്(minus) 1, മൈനസ്(minus)

play27:11

2 എന്നിങ്ങനെ കണക്കാക്കുന്നു. അതിനാൽ, cfന്റെ മൈനസ്(minus)

play27:12

ഒന്നാമത്തെ ഘടകം റിട്ടേൺ(return) ചെയ്യുക,

play27:13

പൈത്തൺ(python) പദപ്രയോഗത്തിൽ ഏറ്റവും വലതുവശത്തെ

play27:14

മൂലകം റിട്ടേൺ(return) ചെയ്യുക. അതിനാൽ,

play27:15

ഇത് ഏറ്റവും വലതുവശത്തെ ഘടകമാണ്.

play27:16

ഈ സമയത്ത്, ചില സ്ഥലങ്ങളിൽ നമ്മൾ കോളൻ(colon) ഉപയോഗിക്കുന്നത്

play27:17

എന്തുകൊണ്ടാണെന്നും, എന്തുകൊണ്ടാണ് നമ്മൾ

play27:18

എന്തെങ്കിലും പുഷ്(push) ചെയ്യുന്നതെന്നും

play27:19

കൃത്യമായി മനസ്സിലായില്ലെങ്കിലും ഈ കോഡ്(code), ഈ പ്രോഗ്രാം(program)

play27:20

ഡീകോഡ്(decode) ചെയ്യാൻ നമുക്ക് ശ്രമിക്കാമെന്ന്

play27:21

മനസിലാക്കാൻ ഇത് മതിയാകും. ഇവിടെ

play27:22

മറ്റ് വാക്യഘടനാപരമായ കാര്യങ്ങളുണ്ടെന്ന്

play27:23

ശ്രദ്ധിക്കുക, അതിനാൽ ഉദാഹരണത്തിന്, നിങ്ങൾക്ക്

play27:24

ഈ വിരാമചിഹ്നങ്ങളുണ്ട്, അവ ഈ കോളനുകളെപ്പോലെ(colon)

play27:25

അൽപ്പം വിചിത്രമാണ്. ഈ വരിയുമായി ബന്ധപ്പെട്ട്

play27:26

ഈ വരി ഇൻഡന്റ്(intend) ചെയ്‌തിരിക്കുന്നു

play27:27

എന്ന വസ്തുത നിങ്ങൾക്കുണ്ട്, ഈ വരി ഈ വരിയിലേക്ക്

play27:28

ഇൻഡന്റ്(intend) ചെയ്‌തിരിക്കുന്നു. മറ്റ് ഭാഷകളിലെ പ്രോഗ്രാമുകളേക്കാൾ(program)

play27:29

പൈത്തൺ പ്രോഗ്രാമുകൾ(python program) വായിക്കാനും

play27:30

എഴുതാനും അൽപ്പം എളുപ്പമാക്കുന്ന

play27:31

സവിശേഷതകളാണ് ഇവയെല്ലാം. അതിനാൽ, പൈത്തൺ(python)

play27:32

വാക്യഘടന കൂടുതൽ ഔപചാരികമായി പഠിക്കുമ്പോൾ

play27:33

നമ്മൾ ഇവയിലേക്ക് വരും. മുമ്പത്തെ

play27:34

സ്ലൈഡിൽ(slide) നമ്മൾ എഴുതിയ അനൗപചാരിക

play27:35

അൽഗോരിതത്തിന്റെ(algorithm) വളരെ വിശ്വസ്തമായ

play27:36

റെൻഡറിംഗാണ്(rendering) ഈ പൈത്തൺ(python) ഘട്ടങ്ങൾ

play27:37

എന്ന് ഈ ഘട്ടത്തിൽ നിങ്ങൾക്ക് സ്വയം

play27:38

ബോധ്യപ്പെടുത്താൻ കഴിയും.

play27:39

ഈ പ്രത്യേക ഉദാഹരണത്തിൽ നിന്ന് ഇതിനകം തന്നെ

play27:40

ഒഴിവാക്കാൻ കഴിയുന്ന ചില പോയിന്റുകൾ(point)

play27:41

നമുക്ക് ശ്രദ്ധിക്കാം. അതിനാൽ, ഇന്റർമീഡിയറ്റ്(intermediate)

play27:42

മൂല്യങ്ങളുടെ വിവരങ്ങൾ സൂക്ഷിക്കാൻ നമുക്ക്

play27:43

ഒരു മാർഗം ആവശ്യമാണ് എന്നതാണ് ആദ്യത്തെ

play27:44

പ്രധാന കാര്യം. അതിനാൽ, നമുക്ക് ആരംഭിക്കാൻ

play27:45

രണ്ട് പേരുകളുണ്ട്, നമ്മുടെ ആർഗ്യുമെന്റുകളുടെ(argument)

play27:46

പേരുകൾ m, n. ഈ ഘടകങ്ങളുടെയും പൊതുവായ ഘടകങ്ങളുടെയും

play27:47

പട്ടിക കണക്കാക്കാൻ നമ്മൾ ഈ മൂന്ന് പേരുകൾ

play27:48

ഉപയോഗിക്കുന്നു, കൂടാതെ i, j, f പോലുള്ള

play27:49

മറ്റ് പേരുകളും നമ്മൾ ഉപയോഗിക്കുന്നു.

play27:50

നമുക്ക് i 1 മുതൽ n വരെ പ്രവർത്തിക്കേണ്ടത്

play27:51

ആവശ്യമാണ്. നമുക്ക് j 1 മുതൽ n വരെ പ്രവർത്തിക്കേണ്ടത്

play27:52

ആവശ്യമാണ്. തീർച്ചയായും, നമുക്ക് വീണ്ടും

play27:53

ഉപയോഗിക്കാം. പക്ഷെ കുഴപ്പമില്ല. cf ലെ

play27:54

എല്ലാ ഘടകങ്ങളിലൂടെയും പ്രവർത്തിക്കാൻ

play27:55

നമ്മൾ f ഉപയോഗിക്കുന്നു. അതിനാൽ, ഇന്റർമീഡിയറ്റ്(intermediate)

play27:56

മൂല്യങ്ങളുടെ വിവരങ്ങൾ സൂക്ഷിക്കുന്നതിനുള്ള

play27:57

വഴികളാണ് ഇവ. ശ്രദ്ധിക്കേണ്ട രണ്ടാമത്തെ കാര്യം,

play27:58

ഒരു മൂല്യം ഒരൊറ്റ ഇനമാകാം എന്നതാണ്.

play27:59

ഉദാഹരണത്തിന്, m n എന്നത് അക്കങ്ങളാണ്,

play28:00

അതുപോലെ തന്നെ ഓരോ ഘട്ടത്തിലും i, j, f

play28:01

എന്നിവ അക്കങ്ങളാണ്. അതിനാൽ, ഇവ ഒരൊറ്റ

play28:02

മൂല്യങ്ങളായിരിക്കും അല്ലെങ്കിൽ അവ ശേഖരങ്ങളാകാം.

play28:03

ലിസ്റ്റുകൾ(list) ഉണ്ട്. അതിനാൽ fm ഒരു പട്ടികയാണ്,

play28:04

fn ഒരു പട്ടികയാണ്. ഇത് മൂല്യങ്ങളുടെ

play28:05

ശേഖരം സൂചിപ്പിക്കുന്ന ഒരൊറ്റ പേരാണ്, ഈ

play28:06

സാഹചര്യത്തിൽ, ഒരു പട്ടിക എന്നത് ഒരു

play28:07

സ്ഥാനവും ആദ്യ സ്ഥാനവും അവസാന സ്ഥാനവും ഉള്ള

play28:08

ഒരു ശ്രേണിയാണ്. ഇവ അക്കങ്ങളുടെ പട്ടികയാണ്.

play28:09

ഒരാൾ‌ക്ക് മറ്റ് ശേഖരങ്ങൾ‌ സങ്കൽപ്പിക്കാൻ‌

play28:10

കഴിയും, ഒപ്പം മുന്നോട്ട് പോകുന്നതിനനുസരിച്ച്

play28:11

ഇവയെ കാണുകയും ചെയ്യാം. അതിനാൽ, ശേഖരങ്ങൾ

play28:12

പ്രധാനമാണ്, കാരണം m ന്റെ ഓരോ ഘടകങ്ങൾക്കും

play28:13

വെവ്വേറെ പേര് നിർമ്മിക്കുന്നത് തുടരുകയാണെങ്കിൽ

play28:14

ഒരു പ്രോഗ്രാം(program) എഴുതുന്നത് വളരെ

play28:15

ബുദ്ധിമുട്ടാണ്. m എത്ര വലുതാണെന്നത്

play28:16

പരിഗണിക്കാതെ തന്നെ m ന്റെ എല്ലാ ഘടകങ്ങൾക്കും

play28:17

നമുക്ക് ഒരു പേര് ആവശ്യമാണ്. ഈ പേരുകൾക്ക്

play28:18

ഒരൊറ്റ മൂല്യത്തെയോ മൂല്യങ്ങളുടെ ശേഖരത്തെയോ

play28:19

സൂചിപ്പിക്കാൻ കഴിയും. പ്രത്യേക ഘടനയുള്ള

play28:20

മൂല്യങ്ങളുടെ ശേഖരത്തെയാണ് നമ്മൾ ഡാറ്റാ സ്ട്രക്ചർ(data

play28:21

structure) എന്ന് വിളിക്കുന്നത്. അതിനാൽ, ഇവയെ സാധാരണയായി

play28:22

ഡാറ്റാ സ്ട്രക്ചറുകൾ(data structures) എന്ന് വിളിക്കുന്നു.

play28:23

അതിനാൽ, ഈ സാഹചര്യത്തിൽ നമ്മുടെ ഡാറ്റാ ഘടന

play28:24

ഒരു പട്ടികയാണ്.

play28:25

ഈ പേരുകളും മൂല്യങ്ങളും ഉപയോഗിച്ച് നമുക്ക്

play28:26

എന്തുചെയ്യാൻ കഴിയും, ഒരു പേരിന് ഒരു മൂല്യം

play28:27

നൽകാമെന്നതാണ് ഒരു കാര്യം. അതിനാൽ, ഉദാഹരണത്തിന്,

play28:28

നമ്മൾ fn = ശൂന്യമായ ലിസ്റ്റ്(list) എന്ന്

play28:29

എഴുതുമ്പോൾ, fn ന്റെ മൂല്യം ശൂന്യമായ

play28:30

പട്ടികയായി നമ്മൾ സജ്ജമാക്കുന്നു.

play28:31

ഇത് രണ്ട് കാര്യങ്ങൾ പറയുന്നു, മൂല്യം

play28:32

ശൂന്യമായ പട്ടികയാണെന്ന് ഇത് പറയുന്നു, ഇത്

play28:33

fn ലിസ്റ്റുകളെ(list) സൂചിപ്പിക്കുന്നു

play28:34

എന്ന് പൈത്തണിനോട്(python) പറയുന്നു, ഇത് നമ്മൾ

play28:35

കാണുന്നതുപോലെ ഇവിടെ നടക്കുന്ന രണ്ട്

play28:36

ഘട്ടങ്ങളാണ്. മറ്റൊരു ഭാഗം, നമ്മൾ

play28:37

cf പട്ടികയിലെ ഓരോ f നും വേണ്ടി എന്തെങ്കിലും

play28:38

എഴുതുമ്പോൾ, cf ലെ എല്ലാ മൂല്യങ്ങളും

play28:39

എടുത്ത് f എന്ന പേരിന് f എന്ന മൂല്യങ്ങളിലേക്ക്

play28:40

ഓരോന്നായി നൽകണമെന്ന് ഇത് സൂചിപ്പിക്കുന്നു.

play28:41

അവർക്ക് ഈ സമത്വ ചിഹ്നം സ്പഷ്ടമായി

play28:42

ഇല്ലെങ്കിലും, നമ്മൾ cf പട്ടികയിലേക്ക്

play28:43

ചുവടുവെക്കുമ്പോൾ ഇത് f നായി പുതിയ മൂല്യങ്ങൾ

play28:44

നൽകുന്നു. അതിനാൽ, ഒരു പൈത്തൺ പ്രോഗ്രാമിൽ(python

play28:45

program) നമ്മൾ ചെയ്യുന്ന പ്രധാന കാര്യം പേരുകൾക്ക്

play28:46

മൂല്യങ്ങൾ നൽകുക എന്നതാണ്.

play28:47

ഒരു മൂല്യം നിർണ്ണയിച്ചാൽ നമുക്ക് മൂല്യം പരിഷ്കരിക്കാനാകും.

play28:48

ഉദാഹരണത്തിന്, n ന്റെ ഒരു പുതിയ ഘടകം കണ്ടെത്തുമ്പോഴെല്ലാം,

play28:49

പഴയ ഘടകങ്ങളൊന്നും നമ്മൾ ആഗ്രഹിക്കുന്നില്ല,

play28:50

നിലവിലുള്ള ലിസ്റ്റ്(list) fm എടുക്കാൻ നമ്മൾ

play28:51

ആഗ്രഹിക്കുന്നു, അത് ചേർക്കാൻ നമ്മൾ

play28:52

ആഗ്രഹിക്കുന്നു. അതിനാൽ, അപ്പൻഡ്(append)

play28:53

എന്ന ഈ ഫംഗ്ഷൻ(function), ഉദാഹരണത്തിന്, fn എന്ന

play28:54

പേരിന്റെ മൂല്യം ഒരു പുതിയ പേരിലേക്ക്

play28:55

പരിഷ്കരിക്കുന്നു, അത് പഴയ പേര് എടുക്കുകയും

play28:56

അതിന്റെ അവസാനം ഒരു i ഘടിപ്പിക്കുകയും

play28:57

ചെയ്യുന്നു. സാധാരണയായി, നിങ്ങൾക്ക്

play28:58

ഒരു സംഖ്യ ഉണ്ടായിരിക്കാം, അത് രണ്ട് ഇരട്ടി

play28:59

സംഖ്യ ഉപയോഗിച്ച് മാറ്റിസ്ഥാപിക്കാൻ

play29:00

നമ്മൾ ആഗ്രഹിക്കുന്നു. അതിനാൽ, നമുക്ക്

play29:01

i = 2 * i പോലുള്ള എന്തെങ്കിലും ഉണ്ടായിരിക്കാം.

play29:02

അതിനാൽ, നക്ഷത്രം ഗുണനത്തെ സൂചിപ്പിക്കുന്നു,

play29:03

ഇതിനർത്ഥം ഗണിതപരമായി i = 2 * i എന്നത് അർത്ഥമാക്കുന്നില്ല,

play29:04

കാരണം; വ്യക്തമായും, i 0 അല്ലാത്തിടത്തോളം,

play29:05

i, 2 * i ന് തുല്യമാകരുത്. അതിന്റെ അർത്ഥം i

play29:06

യുടെ നിലവിലെ മൂല്യം എടുത്ത് അതിനെ രണ്ടായി

play29:07

ഗുണിച്ച് i ലേക്ക് നിയോഗിക്കുക എന്നതാണ്.

play29:08

നമ്മൾ മുന്നോട്ട് പോകുന്നതിനനുസരിച്ച്

play29:09

നമുക്ക് അത് കാണാൻ സാധിക്കും, പക്ഷേ

play29:10

അസൈൻമെന്റ്(assignment) ഉപയോഗിച്ച് പൂർണ്ണമായും

play29:11

പുതിയ മൂല്യം നൽകാം അല്ലെങ്കിൽ പഴയ മൂല്യം

play29:12

ഉപയോഗിച്ച് നിങ്ങൾക്ക് മൂല്യം അപ്‌ഡേറ്റ്(update)

play29:13

ചെയ്യാൻ കഴിയും. അതിനാൽ, ഇവിടെ നമ്മൾ

play29:14

fn ലിസ്റ്റിന്റെ(list) ഫംഗ്ഷന്റെ(function) പഴയ

play29:15

മൂല്യം എടുക്കുന്നു, നമ്മൾ ഒരു മൂല്യം

play29:16

കൂട്ടിച്ചേർക്കുന്നു, അതിന് fn ന്റെ ഒരു

play29:17

പുതിയ മൂല്യം ലഭിക്കും.

play29:18

നമ്മൾ ശ്രദ്ധിക്കേണ്ട മറ്റൊരു ഭാഗം നമ്മൾ

play29:19

എങ്ങനെ ഘട്ടങ്ങൾ നിർവ്വഹിക്കുന്നു

play29:20

എന്നതാണ്. അതിനാൽ, ഇന്നത്തെ പ്രഭാഷണത്തിന്റെ

play29:21

തുടക്കത്തിൽ നമ്മൾ പറഞ്ഞു, ഒരു പ്രോഗ്രാം(program)

play29:22

ഘട്ടങ്ങളുടെ ഒരു ശ്രേണിയാണ്. എന്നാൽ

play29:23

നമ്മൾ തുടക്കം മുതൽ അവസാനം വരെയുള്ള

play29:24

ഘട്ടങ്ങളുടെ ക്രമം അന്ധമായി നടപ്പിലാക്കുന്നില്ല.

play29:25

ചിലപ്പോൾ നമ്മൾ വീണ്ടും വീണ്ടും അതേ കാര്യം

play29:26

ചെയ്യേണ്ടിവരും. ഉദാഹരണത്തിന്, 1 മുതൽ

play29:27

m വരെയുള്ള എല്ലാ ഘടകങ്ങളും m നെ ഹരിക്കുന്നുണ്ടോ

play29:28

എന്ന് പരിശോധിക്കുക, അങ്ങനെയാണെങ്കിൽ

play29:29

അവയെ പട്ടികയിൽ ഇടുക. അതിനാൽ, ചില ഘട്ടങ്ങൾ

play29:30

ആവർത്തിക്കുന്നു, ഉദാഹരണങ്ങൾക്കായി,

play29:31

ഒരു ലിസ്റ്റിലെ(list) ഓരോ ഇനത്തിനും ഇവിടെ

play29:32

നമ്മൾ എന്തെങ്കിലും ചെയ്യുന്നു.

play29:33

നമ്മൾ നോക്കുന്ന മൂല്യം പ്രത്യേക

play29:34

നിബന്ധനകൾ പാലിക്കുന്നുണ്ടെങ്കിൽ മാത്രമേ ചില ഘട്ടങ്ങൾ

play29:35

നടപ്പിലാക്കുകയുള്ളൂ. m നെ i കൊണ്ട് ഹരിച്ചാൽ

play29:36

ശിഷ്ടം 0 ആണെങ്കിൽ, m % i എന്നത് 0 പറയാം,

play29:37

ഇതിനെ കൂട്ടി ചേർക്കുക. അതിനാൽ, m ന്റെ ഘടകങ്ങൾ

play29:38

fm ലേക്ക് i കൂട്ടിച്ചേർക്കുക എന്ന ഘട്ടം,ഇത് സംഭവിക്കുന്നത്

play29:39

i എന്നത് m ന്റെ ഘടകമാണെന്ന അവസ്ഥയുമായി പൊരുത്തപ്പെടുന്നെങ്കിൽ

play29:40

മാത്രമായിരിക്കും. ഒരേ കാര്യം വീണ്ടും

play29:41

വീണ്ടും ചെയ്യുന്ന ആവർത്തന ഘട്ടങ്ങൾ

play29:42

ഉണ്ട്. അവർക്ക് കണ്ടീഷണൽ‌(conditional) ഘട്ടങ്ങളുണ്ട്, ഒരു

play29:43

പ്രത്യേക നിബന്ധന ഉണ്ടെങ്കിൽ‌ മാത്രമേ

play29:44

ഇത് ചെയ്യൂ. അതിനാൽ, നമുക്ക്

play29:45

ഇവിടെ നിർത്തും. പ്രോഗ്രാമുകൾ(program)

play29:46

നമുക്ക് അവബോധപരമായി അറിയുന്നതിൽ നിന്ന്

play29:47

വളരെ വ്യത്യസ്തമല്ലെന്ന് ഈ ഉദാഹരണങ്ങൾ നിങ്ങളെ

play29:48

കാണിക്കും, അത് ശരിയായി എഴുതുക, മാത്രമല്ല

play29:49

നമുക്ക് ആവശ്യമുള്ള എല്ലാ ഇന്റർമീഡിയറ്റ്(intermediate)

play29:50

മൂല്യങ്ങളുടെയും ഘട്ടങ്ങളുടെയും

play29:51

വിവരങ്ങൾ സൂക്ഷിക്കുന്നുണ്ടെന്ന് ഉറപ്പുവരുത്തുക,

play29:52

അങ്ങനെ നമുക്ക് കാര്യങ്ങൾ നഷ്ടപ്പെടുന്നില്ല.

play29:53

നമ്മൾ പിന്നീട് ഈ ഉദാഹരണം കൂടുതൽ വിശദമായി

play29:54

നോക്കും, കൂടാതെ ഇത് എഴുതുന്നതിനുള്ള

play29:55

മറ്റ് മാർഗ്ഗങ്ങൾ കണ്ടെത്താനും മറ്റ്

play29:56

സവിശേഷതകൾ പരിശോധിക്കാനും ശ്രമിക്കും, പക്ഷേ

play29:57

ഇത് പ്രോഗ്രാമിംഗ്(programming) ചിത്രീകരിക്കുന്നതിനുള്ള

play29:58

ഒരു നല്ല മാർഗമാണ്.

Rate This

5.0 / 5 (0 votes)

関連タグ
ProgrammingAlgorithmsData StructuresCourse IntroductionEducational ContentComputational ThinkingMathematicsPython ProgrammingCoding ConceptsEducational Resources
英語で要約が必要ですか?