Introduction to Algorithm
Growth of Function
Algorithm –
एक अल्गोरिथ्म step-by-step instructions का sequence है जो finite है और जब भी हम किसी input को उस अल्गोरिथ्म पर लगाएंगे तो हमें output मिल जाएगा। यह सरल (simple) और प्रभावी (Effective) है।
Program –
एक computer program, instructions का एक संग्रह है या कहें collection है जो computer द्वारा execute होने पर एक विशिष्ट कार्य करता है। ये programming languages के syntax में ही होते है।
लेकिन मेरा मुद्दा algorithm या program की definition के बारे में नहीं है। मेरा मुद्दा आपको यह बताना है कि एक अल्गोरिथ्म क्या कर सकता है जो कि एक program नहीं कर सकता, या फिर एक program क्या कर सकता है जो कि एक अल्गोरिथ्म नहीं कर सकता।
Example-किसी समस्या को हल करने के लिए, आपने एक अल्गोरिथ्म design किया, और फिर किसी भी programming language के source code में उस अल्गोरिथ्म लागू किया। कुछ ऐसे example भी है जिसमें एक अल्गोरिथ्म को design करके कुछ समस्याओं को हल किया जा सकता है, लेकिन कोई भी programming language उन्हें हल नहीं कर सकती है। सोचो और बताओ क्या मैं ठीक बोल रहा हूँ?
मैं आपको एक उदाहरण दूंगा। किसी भी संख्या के वर्गमूल (square root) की गणना करने के लिए एक अल्गोरिथ्म लिखें। आप square root का अल्गोरिथ्म बना सकते हैं जो सही होगा लेकिन आप एक ऐसा program नहीं बना सकते हैं जो प्रत्येक input का square root दे । अल्गोरिथ्म में, आपको बस तर्क (Logic) लिखना होगा, यह इतना सरल है, लेकिन एक ऐसा program (जो syntactically और semantically रूप से एकदम सही है), उस program में आप हरेक number का output नहीं ला सकते हैं।
√4 – 2 ठीक है,
√9 – 3 ठीक है,
√16 – 4 ये भी ठीक है
लेकिन √5, √6, √7 और √8 के बारे में क्या? 4, 9, 16, 25,… ये perfect square roots हैं, लेकिन non-perfect numbers (जैसे कि 5, 6, 7, 8… ) का square root आप नहीं दे सकते हैं।
कुछ धारणाएं हैं कि √2 – 1.414 के बराबर है, और हिप्पासस, जो कि एक ग्रीक दार्शनिक थे, ने पाया कि 2 का square root एक अपरिमेय संख्या (irrational number) है, अर्थात, उन्होंने साबित किया कि 2 के square root को दो numbers के ratio के रूप में व्यक्त नहीं किया जा सकता है। आप खुद ही पता लगाइए कि क्या 1.414 का इसका सही उत्तर है, इसके आगे हज़ारों संख्या और जोड़ दीजिये, उत्तर फिर भी perfect नहीं होगा। इसलिए computer program square root की समस्या के साथ न्याय नहीं कर सकता क्योंकि इसे सटीकता की आवश्यकता होती है लेकिन अल्गोरिथ्म तर्क (logic) दे सकता है। तो जो websites आपको square root का program लिख कर देती हैं, वह बस approximate answer ही देती हैं।
एक दूसरा example उनके लिए जिनको मित्रता में बहुत विश्वास हैं –
जब आपको कोई पसंद आता है और आप उससे मित्रता करना चाहते हो, लेकिन अभी आपको सफलता नहीं मिली है तो बहुत सारे लोग अपने सबसे करीबी मित्र से पूछते है कि जो आपका target है उससे बात कैसे कि जाए । फिर आपका सबसे करीबी मित्र आपको कुछ Tips देता है, तो वह जो कहता है उसे आप समझो कि ये एक अल्गोरिथ्म है, जो आपको सिर्फ logic ही देगी, पर उसका program बनाना ये कठिन कार्य है। program तभी बनेगा जब अपने अल्गोरिथ्म का उपयोग करके जो आपका target है उससे मित्रता कर ली, पर 50% संयोग ऐसा होगा कि वह मना कर दे । तब आपका program नहीं बन पाएगा ।
Test Yourself
Q1- Define Computer Program?
A computer program is a collection of instructions that performs a specific task when executed by a computer. It follows the syntax of the programming language.
Q2- Can cube root program gives accurate output on every input?
Perfect cube root numbers can give accurate output but every input can’t give accurate results.
Q3- Can cube root algorithm give accurate logic on every input?
There is a domain of input which will pass in the algorithm and algorithm instruction will give accurate logic.
Q4- An algorithm becomes a ________ when it is written in the form of a programming language.
Program
Q5- Is it possible for a program to evolve into an algorithm?
Expert programmers can do that. There is a certain way you have to follow to make an algorithm from a program.
1. Write input domain
2. Write all the test cases
3. Note every output.
4. Break the code into modules.
5. Write algorithms for the modules.
6. Find integration of the module’s algorithm.
7. Dry run the program’s algorithm.
Q6- The method that uses a list of well-defined instructions to complete a task starting from a given initial state to an end state is known as
Algorithm
Q7- Algorithms are used to
1. better planning.
2. Better programming
3. Easier testing and debugging
All of the above
Q8- What is the pictorial representation of algorithm?
Flowchart
Q9- Pseudocode chooses to focus on
1. Development
2. Design
3. Coding
Design
Q10- The pseudocode instructions are written in which order in which they will be executed is _________.
Sequence