Need of an Algorithm

Distribute Education like Computer Geek

मान लीजिए आपके पास एक problem है जिसे आप या कोई machine (computer) solve कर सकता है, और इसे solve करने के लिए आपको एक specific procedure को follow करना होगा। इस procedure को simple language में लिखे गए instruction या command को algorithm कहा जाता है।

Need of an algorithm (Hindi)
Complex Algorithm
.
हर Task में Algorithms की जरूरत क्यों होती है?

जब भी हम कोई activity करते हैं, तो कुछ specific procedures को follow करना जरूरी होता है ताकि काम सही तरीके से पूरा हो।

चाहे काम आसान हो या कठिन, हर काम के लिए एक method या plan होता है, जिसे follow करना जरूरी है ताकि desired output मिले। यही काम algorithms करते हैं।

यह हमें task को efficiently और सही तरीके से करने का clear means provide करता है।

जैसे cooking, math problem solve करना, या एक जगह से दूसरी जगह जाना। इन tasks के लिए हमारे पास specific steps होते हैं, जो या तो लिखे हुए होते हैं या हमारे दिमाग में होते हैं। अगर हम इन steps को follow न करें, तो सही result मिलना मुश्किल हो सकता है।
Computer science और अन्य fields में भी algorithms इसी तरह महत्वपूर्ण होते हैं। यह tasks को organized तरीके से करने, performance को improve करने, और consistent results ensure करने में मदद करते हैं।
इसीलिए algorithms की जरूरत होती है, ताकि हर काम को simplify, standardize, और guide किया जा सके, जिससे accuracy और efficiency सुनिश्चित हो सके।

.

एक algorithm का example: Tea Recipe

  1. Start
  2. Gas पर tea pan रखो
  3. Water, milk, और tea leaves डालो
  4. Mixture को boil करो
  5. Sugar डालो
  6. Mixture को boil करो
  7. Tea तैयार है
  8. Stop

Inputs: Water, sugar, tea leaves, tea pan, और gas
Output: Tea

Algorithm “Definite”, clear और unambiguous होता है, और ये Effective या possible result देने वाले होते है। यह finite steps में terminate होता है। अगर इन qualities में से कोई भी पूरी नहीं होती, तो वह algorithm नहीं कहलाता, और हम वह task नहीं कर सकते। मतलब Donald Ervin Knuth ने सही कहा था।

.

Algorithm और Pseudocode

Algorithms को अक्सर pseudocode में लिखा जाता है, जो आपकी native language और किसी programming language का combination होता है। ऊपर दी गई tea recipe भी एक pseudocode है क्योंकि यह English language में लिखी गई है। अगर इसमें किसी programming language का syntax जोड़ दें, तो भी यह algorithm कहलाएगा।

.
अगर आप किसी language (C, C++, Java, Python) में program लिखना चाहते हैं, तो पहले आपको algorithm या pseudocode लिखना होगा। यह numbered bullet form में होना चाहिए ताकि program बनाते समय आपको logic साफ समझ में आए।

.

Note: Algorithm को बहुत simple होना चाहिए। लेकिन जो लोग Coreman की book पढ़ते हैं, उनके लिए algorithms की logic को समझना आसान नहीं होता। फिर भी दुनिया के अधिकतर professors और researchers Coreman की book पढ़ते और पढ़ाते हैं और algorithms की complexities से deal करते हैं।

.

Algorithms क्यों जरूरी हैं?
  1. Problem Solving – Complex problems को systematic तरीके से solve करने के लिए algorithms मदद करते हैं। यह problem को छोटे, manageable steps में divide करके solution आसान बनाते हैं, जैसे Divide & Conquer
  2. Efficiency – Algorithms problem को solve करने का सबसे efficient तरीका खोजने की कोशिश करते हैं। यह resources का optimal usage करते हैं, time complexity को कम करते हैं और memory requirements को minimize करते हैं।
  3. Reproducibility – Algorithms well-defined और unambiguous होते हैं, जिससे कोई भी steps को follow करके वही result प्राप्त कर सकता है।
  4. Scalability – Algorithms बड़े datasets या problems को handle कर सकते हैं, जिससे यह big data processing और large-scale computations के लिए उपयोगी बनते हैं।
  5. Reusability – एक बार algorithm develop और test हो जाए, तो उसे similar problems में दोबारा use किया जा सकता है, जिससे time और effort बचता है।
  6. Automation – Algorithms tasks को automate करते हैं, जिससे human errors कम होते हैं और accuracy बढ़ती है, जैसे machine learning और artificial intelligence में।
  7. Standardization – Algorithms common problems को solve करने के standard methods provide करते हैं, जिससे अलग-अलग systems और platforms में consistency और compatibility बनी रहती है।
  8. Decision Making – Algorithms decision-making processes में use होते हैं, जैसे navigation systems में route optimization या financial modeling में investment decisions।
  9. Predictive Analysis – Algorithms predictive analysis में महत्वपूर्ण भूमिका निभाते हैं, जो historical data के आधार पर trends, patterns या future events का अनुमान लगाते हैं।
  10. Scientific and Engineering Applications – Algorithms scientific simulations, engineering designs, और computational tasks के लिए fundamental होते हैं।

Test Yourself

Q1- What is the difference between Algorithm & Pseudocode?

Algorithms are typically written in pseudocode, or a combination of your native language and one or more programming languages, before being implemented in a program.
Pseudocode is written in natural language and it will have some mathematical notation which is easy to understand. It is an informal text with a simpler version of the solution. Algorithm is a formal text which is unambiguous, effective, finite and definite. 

Q2- What comes first – Algorithm, pseudocode or program?

First you draw pseudocode, which is informal and written in native languages, and mathematical notation (if any).
Second, you draw an algorithm by taking pseudocode into a formal language, and the instruction should be clear, unambiguous, finite, effective, and definite.
Then, in the 3rd part, you will generate a program by taking clear and unambiguous instructions from the algorithm.

Q3- Is the algorithm for each programming language different?

No, algorithm is same for each programming language. Algorithms just give us logic and logic is the same for every programming language.

Q4- Should an algorithm be rewritten if code is written in one language and then rewritten in another language? 

Yes, the algorithm will have to be rewritten if the algorithm of the previous code is not written. Because a programmer can understand that logic only if he has an algorithm. Break the previous code into smaller form and rewrite the algorithm. 

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha