What is an Algorithm? -एक एल्गोरिदम क्या है?
- _Romeyo Boy_
- 23 दिस॰ 2021
- 3 मिनट पठन
इस ट्यूटोरियल में, हम उदाहरणों की सहायता से सीखेंगे कि एल्गोरिदम क्या हैं।
कंप्यूटर प्रोग्रामिंग के संदर्भ में, एक एल्गोरिथ्म किसी विशेष समस्या को हल करने के लिए अच्छी तरह से परिभाषित निर्देशों का एक सेट है। यह इनपुट का एक सेट लेता है और वांछित आउटपुट ( Desired Output ) उत्पन्न करता है। उदाहरण के लिए,
दो संख्याओं को जोड़ने के लिए एक एल्गोरिथ्म:
दो नंबर इनपुट लें।
+ ऑपरेटर का उपयोग करके नंबर जोड़ें।
परिणाम प्रदर्शित करें।
एक एल्गोरिथ्म एक प्रक्रिया या नियमों का एक सेट है, जो विशेष रूप से कंप्यूटर द्वारा गणना या कुछ अन्य समस्या-समाधान संचालन करने के लिए आवश्यक है। एक एल्गोरिथ्म की औपचारिक परिभाषा यह है कि इसमें निर्देशों का परिमित सेट होता है जो विशिष्ट कार्य को करने के लिए एक विशिष्ट क्रम में किया जा रहा है।
यह पूरा प्रोग्राम या कोड नहीं है; यह सिर्फ एक समस्या का समाधान ( तर्क या लॉजिक ) है, जिसे फ़्लोचार्ट या स्यूडोकोड का उपयोग करके अनौपचारिक विवरण के रूप में दर्शाया जा सकता है।
Qualities of Good Algorithms ( अच्छे एल्गोरिदम के गुण )
इनपुट और आउटपुट को सटीक रूप से परिभाषित किया जाना चाहिए।
एल्गोरिथम का प्रत्येक चरण स्पष्ट और साफ़ रूप से होना चाहिए।
किसी समस्या को हल करने के कई अलग-अलग तरीकों में से एल्गोरिदम सबसे प्रभावी होना चाहिए।
एक एल्गोरिथ्म में कंप्यूटर कोड शामिल नहीं होना चाहिए। इसके बजाय, एल्गोरिथ्म को इस तरह से लिखा जाना चाहिए कि इसे विभिन्न प्रोग्रामिंग भाषाओं में उपयोग किया जा सके।
For Examples; एल्गोरिथम उदाहरण
दो संख्याओं को जोड़ने के लिए एल्गोरिथम
एल्गोरिथम तीन संख्याओं में सबसे बड़ा खोजने के लिए
द्विघात समीकरण की सभी जड़ों को खोजने के लिए एल्गोरिदम
फैक्टोरियल खोजने के लिए एल्गोरिदम
अभाज्य संख्या की जाँच करने के लिए एल्गोरिथ्म
फाइबोनैचि श्रृंखला का एल्गोरिथ्म
Algorithm 1: Add two numbers entered by the user
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Algorithm 2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Algorithm 3: Find Root of the quadratic equatin ax2 + bx + c = 0
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
D ← b2-4ac
Step 4: If D ≥ 0
r1 ← (-b+√D)/2a
r2 ← (-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp ← -b/2a
ip ← √(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
Algorithm 4: Find the factorial of a number
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial ← 1
i ← 1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
5.1: factorial ← factorial*i
5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop
Algorithm 5: Check whether a number is prime or not
Step 1: Start
Step 2: Declare variables n, i, flag.
Step 3: Initialize variables
flag ← 1
i ← 2
Step 4: Read n from the user.
Step 5: Repeat the steps until i=(n/2)
5.1 If remainder of n÷i equals 0
flag ← 0
Go to step 6
5.2 i ← i+1
Step 6: If flag = 0
Display n is not prime
else
Display n is prime
Step 7: Stop
Algorithm 6: Find the Fibonacci series till the term less than 1000
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term ← 0 second_term ← 1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term ≤ 1000
5.1: temp ← second_term
5.2: second_term ← second_term + first_term
5.3: first_term ← temp
5.4: Display second_term
Step 6: Stop
Comments