Complexity of an algorithm or function - time complexity and space complexity

Complexity (कॉम्पलेक्सिटी ):- 

Complexity of an algorithm or function is based on memory space taken by the algorithm or function and CPU's time given to the algorithm or function for the execution.
किसी अल्गोरिथम या फंक्शन की कॉम्पलेक्सिटी उस अल्गोरिथम या फंक्शन द्वारा ली गयी मेमोरी स्पेस एवं CPU द्वारा उस अल्गोरिथम या फंक्शन को प्रदान किये गए समय पर निर्भर करती है।   

Complexity depends on following three major components-
कॉम्पलेक्सिटी निम्न तीन मुख्य अवयवों पर निर्भर करती है :-
1. Input data (इनपुट डेटा):- 
Data which is accepted by an algorithm from input device or memory.
इनपुट डिवाइस या मेमोरी द्वारा अल्गोरिथम को प्रदान किया गया डाटा।  

2. Size of input data (इनपुट डाटा का आकार) :-
Number of memory bytes present in input data.
इनपुट डाटा में उपस्थित मेमोरी बाइट्स की संख्या।  

3. Key operation of an algorithm or function (अल्गोरिथम या फंक्शन  ):- 
The main operations of an algorithm or function which will execute by the CPU in a specific time interval.
अल्गोरिथम या फंक्शन की  मुख्य संक्रियाएँ, जो CPU द्वारा दिए गए समय अंतराल में रन की जानी है।   

Complexity are mainly of two types- 
कॉम्पलेक्सिटी निम्न दो प्रकार की होती हैं :-
1. Time complexity (टाइम कॉम्पलेक्सिटी)
2. Space complexity (स्पेस कॉम्पलेक्सिटी)

1. Time complexity (टाइम कॉम्पलेक्सिटी):-  the time taken by CPU to execute an algorithm or function is called time complexity.
CPU द्वारा किसी अल्गोरिथम या फंक्शन को रन करने में लिया गया समय, टाइम कॉम्पलेक्सिटी कहलाती है।    

2. Space complexity (स्पेस कॉम्पलेक्सिटी):-  the memory space (number of bytes) taken by an algorithm or function in primary memory of computer is called space complexity.
मुख्या मेमोरी में किसी अल्गोरिथम या फंक्शन को प्रदान की गयी मेमोरी बाइट्स की संख्या, स्पेस  कॉम्पलेक्सिटी कहलाती है।   

Note:- "An algorithm which takes less time of CPU and memory space is assumed as an excellent algorithm."
नोट:- "एक अल्गोरिथम जो रन होने के लिए CPU का कम समय एवं कम मेमोरी स्पेस ग्रहण करती है अच्छी अल्गोरिथम मानी जाती है।"

We can find complexity in following three states:- 
कम्प्लेक्सिटी निम्न तीन स्थितियों में ज्ञात की जाती है:- 

1. Best case (बेस्ट केस):- 
When an algorithm or function will be executed in its ideal state, then algorithm is called as in best case. For example:-
जब अल्गोरिथम या फंक्शन को उसकी आदर्श स्थिति में रन किया जाता है तब अल्गोरिथम को बेस्ट केस में कहा जाता है। उदहारण के लिए:-
1. In linear search item is found at first position in list.
लीनियर सर्च में, आइटम का लिस्ट में प्रथम स्थान पर प्राप्त हो जाना।  
2. Applying bubble sort on previously sorted list.
आरोही क्रम में व्यवस्थित लिस्ट पर बबल सॉर्ट लागु करना।   

2. Average case (एवरेज केस):-
When algorithm or function will be executed in its probable state then algorithm is called as in average case. For example:-
जब अल्गोरिथम या फंक्शन को उसकी सामान्य स्थिति में रन किया जाता है तब अल्गोरिथम को एवरेज केस में कहा जाता है। उदहारण के लिए:-
1. In linear search an item is found between 2 to n-1 position in list.
लीनियर सर्च में, आइटम का लिस्ट में द्वितीय स्थान से n-1 स्थान पर प्राप्त हो जाना।
2. Applying bubble sort randomly on list or data structure.
सामान्य लिस्ट पर बबल सॉर्ट लागु करना।   

3. Worst case (वर्स्ट केस):- 
When an algorithm or function execute in its unfavorable condition, then algorithm is assumed as worst case.For example:- 
जब अल्गोरिथम या फंक्शन को उसकी विपरीत स्थिति में रन किया जाता है तब अल्गोरिथम को वर्स्ट केस में कहा जाता है। उदहारण के लिए:-
1. In linear search an item is either found on n th position or not in list.
लीनियर सर्च में, आइटम का लिस्ट में n वें स्थान पर या प्राप्त न होना।
2. Applying bubble sort on previously sorted list in descending order.
अवरोही क्रम में व्यवस्थित लिस्ट पर बबल सॉर्ट लागु करना।   

No comments:

Post a Comment

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...