Wednesday 30 December 2015

All about scanf() function in C programming language

Okay, hi every one...
For the next half hour I'm going to write all about the scanf() function in C programming language. Here I'll share few links that will help you to know more about the scanf() function.

First, lets start with
"What does the scanf() function returns ?"
The answer to this is known by many of the people. It returns the number of items successfully read on the console.
You can check it through a simple C program.
#include <stdio.h>
int main()
{
    int i ;
    printf("%d", scanf("%d", &i));
    return 0;
}

Okay, you try to run this program on your compiler and observe few things.
If you input 5, you will get output as 1.
Try to input 123, what do you think the output should be?
Well, you may thing that the output should be 3 as we have entered 3 digit number. But that's not the output. The output will be again 1.

Okay, so the true interpretation of the returning value of scanf() function is that it returns the number of input taken on the console.
Now we can again see a different kind noticeable thing in the returning value by scanf() function.

Again in the above program if you try to input any character instead of the integer then you will found an unexpected output.
Suppose you enter 'a' on the console of the above program, then what do you think the output should be?
Better you try to run the same program on your compiler. You will find that this time it has printed 0.

Now the question is why 0?
Well, to know the reason for printing the 0 we have to again go to the main definition of the returned value by the scanf() function. And now when we look above we find that scanf() returns the number of items successfully read. And now here we have to note the word successfully.

So if we input a character instead of integer then that is termed as a unsuccessful read from the input and thus the scanf() returns 0.

Now few lines that I read on man is -
scanf,  fscanf, sscanf, vscanf, vsscanf, vfscanf
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
Here is the link that will help you to master this topic - Click here
Now I think we have gained appreciable knowledge on returning value of scanf().

Coming to the next big mistake that many people generally do while using the scanf() function.

Okay, Now if I ask you that make a program to accept two characters and display them. Most of the beginner programmer will make a program like -
#include<stdio.h>
int main()
{
    char c1, c2;
    printf("\n Enter characters one : ");
    scanf(" %c", &c1);
    printf("\n Enter character two : ");
    scanf("%c", &c2);
    printf("\n The the characters are %c and %c ", c1, c2);
    return 0;
}
Now I give you a task, stop reading further for few second and try to find the logical problem with this above code.
Have you found some? Anyway, if you haven't found yet then try to run this program in your compiler. Probably you will find some anomaly.

Here is the output of this program.
Enter two characters : a
The the characters are a and
Here you can see that we are only able to input the first character and not the second one.
Now some of you may have found the reason for the anomaly. No worries, if you haven't yet then I'm going to tell you.

When you enter the first character 'a' then if gets stored into the c1, and when you press enter key ('\n') then it gets stored into c2 and becomes the second character. Now there is no input instruction left so the console just prints the output.

Now one general question may arise that why does this anomaly does not occur when I perform the same task using the integer format specifier?
example :-
#include<stdio.h>
int main()
{
    int a, b;
    printf("\n Enter two numbers : ");
    scanf("%d%d", &a, &b);
    printf("\n The two numbers are %d and %d ", a, b);
    return 0;
}
Okay, again by now some of you have known the reason but for those who haven't known why below is the answer.

Now we again move one step back and see that what was happening in case we were dealing with the character format specifier. We can note that the second input given was a character ('\n') which has ASCII value of 13. But in this case when we use the integer format specifier then we see that the '\n' (which is a character ) does not get assigned to the variable b (which is a integer) i.e here we encounter the failure of the read operation (also known as matching failure) on the console and thus the next input buffer is still active and so when we press the next integer then it gets stored into the variable b.

Now here the discussion does not gets over, we have to note that if in the input buffer we have newline ('\n') then what difference it is going to create for :-

  1. scanf("%c", &charVar);
  2. scan("%d",  &intVar);
  • In case of scanf("%c", &charVar);, the newline is considered as the input, so the second scanf skips asking for the input from user.
  • In the case of scanf("%d", &intVar); the leftover newline is skipped and it wait for theinteger input to appear, so it stops and asks the user for the input. However in this case if you input a non-whitespace character and press ENTER, the char input will be considered as an input, causing a matching failure.
For more information on scanf input conversions for reading string and character values: ‘%s’, ‘%S’, ‘%[’, ‘%c’, and ‘%C’ you cal follow :-
Link 1

To have a look on online version of C11 Standard you can visit here.
Now we will see how to correctly input characters consecutively from the user. 

#include<stdio.h>
int main()
{
    char c1, c2;
    printf("\n Enter characters one : ");
    scanf(" %c", &c1);
    printf("\n Enter character two : ");
    scanf("%c", &c2);
    printf("\n The the characters are %c and %c ", c1, c2);
    return 0;
}


To make this program logically correct (so that we can take two inputs and their values can be inserted into c1 and c2 respectively) we can perform many tasks. Below I have listed some ways that you can follow.
First approach :-
  • We can put the space between the first %c and the second %c. Now you change the above code little bit and you will find your program working successfully.
Now many of you will ask that "what change the space is going to do in scanf() function?"
Okay, now lets us study about "Meaning of space in scanf() function"
  • Space in scanf format means "to skip all whitespace (such as blanks, tabs, or newlines)" from the current position on. However, when you are using a format specifier that does not ignore whitespace, including space into the format when necessary (to force the skip) will work perfectly.
  • The specifiers that do not ignore whitespace are `c` `[` and `n`. So, specifying a space in front of one of those specifiers makes a difference. Otherwise, it doesn't make any difference.

Monday 7 December 2015

Pointer to Pinter in C++ (IN HINDI)

नीचे एक pointer to pointer पर उदाहरण है :-

नीचे स्पष्ट रूप से नीचे के कोड की व्याख्या करने के लिए एक तस्वीर है। आशा है कि यह आपकी निशित रूप से मदद करेगा।
इस प्रोग्राम के पास एक पॉइंटर वेरिएबल p  है जो कि (a) की एड्रेस पर पॉइंट करता है। और एक और पॉइंटर वेरिएबल है जो की p की एड्रेस को पॉइंट करता है जिसका नाम क्यू (q) है। इसे ही हम pointer to pointer का नाम देते है। इसके साथ एक और pointer to pointer to pointer वेरिएबल है जो की r है यह वेरिएबल क्यू(q) की एड्रेस पर  पॉइंट करता है।

// उदाहरण :- pointer to pointer पर
#include<iostream>
using namespace std;
int main()
{
    int a = 6;
    int *p;
    p = &a;
    int **q;
    q = &p;
    int ***r;
    r = &q;
    cout<<" Value of &p : "<<&p<<endl;// address of p
    cout<<" Value of p : "<<p<<endl;// address of a
    cout<<" Value of *p : "<<*p<<endl;// 6
    cout<<" Value of q : "<<q<<endl;// address of p
    cout<<" Value of *q : "<<*q<<endl;// address of a (value stored in p)
    cout<<" Value of **q : "<<**q<<endl;// 6
    cout<<" Value of r : "<<r<<endl;//  address of q
    cout<<" Value of *r "<<*r<<endl;// address of p
    cout<<" Value of **r : "<<**r<<endl;// address of a
    cout<<" Value of ***r : "<<***r<<endl;// 6
    return 0;
}


Saturday 5 December 2015

Difference between pointer variable and Reference variable in C++ (IN HINDI)

एक रिफरेन्स वेरिएबल एक प्रकार का उपनाम है। एक वेरिएबल जो पहले  से प्रोग्राम में मौजूद है उसी के उपनाम को हम रिफरेन्स वेरिएबल कहते हैं। एक बार जब हम रिफरेन्स का आरंभीकरण कर देते हैं, तब हम वेरिएबल अथवा रिफरेन्स का उपयोग उस वेरिएबल को अपने प्रोग्राम में उपयोग करने के लिए इस्सतमल कर सकते हैं।

C++ References एवं  Pointers के ३ बड़े अंतर :

रिफरेन्स को काफी समय पॉइंटर्स समझ लिया जाता है। परन्तु यह गलत है, निचे कुछ अंतर दिए गए हैं।
  • हम रिफरेन्स को नुल्ल् वैल्यू के साथ सहयोगी नहीं बना सकते , परन्तु हम पॉइंटर्स को नुल्ल् वैल्यू के साथ सहियोग कर सकते है।
  • अगर एक बार रिफरेन्स किसी वेरिएबल / ऑब्जेक्ट(object) के साथ सहियोग में हो गया तो हम उस रिफरेन्स की वैल्यू चेंज नहीं कर सकते (मतलब अब हम उस रिफरेन्स को किसी और वेरिएबल के साथ साहियोह नहीं कर सकते )। पॉइंटर्स के साथ ऐसा नहीं है। हम पॉइंटर्स की वैल्यू de-referencing से बदल सकते हैं। 
  • // example
    int x = 5;
    int y = 6;
    int *p;
    p =  &x;
    p = &y;
    *p = 10;
रिफरेन्स उदाहरण
  • int x = 5;
    int y = 6;
    int &r = x;
  • एक रिफरेन्स वेरिएबल को उसके निर्माण के समय ही किसी दूसरे वेरिएबल के साथ सहियोग करना जरुरी है। परन्तु हम पॉइंटर्स को कभी भी किसी वेरिएबल के साथ सहियोग कर सकते है। 

Creating References in C++ :-

हम अपने प्रोग्राम में एक वेरिएबल घोषित कर देते है। 
`int var = 5 ;`
अब हम रिफरेन्स वेरिएबल कुछ इस प्रकार घोषित कर सकते है। 
`int& ref = var ;`
हम लोग इस घोषणा को इस प्रकार पढ़ते है (`ref` is an integer reference initialized to `var`)

उदाहरण
#include<iostream>
using namespace std;
int main()
{
    cout<<"program to illustrate use of reference variable : \n";
    int var ;
    int & ref = var ;

    var = 5;
    cout<<"The value of var is : " << var << endl ;
    cout<<"The value of reference variable ref is : " << ref << endl ;
    return 0;
}

Output :-
program to illustrate use of reference variable : 
The value of var is : 5
The value of reference variable ref is : 5

Saturday 28 November 2015

Traversing the Linked List (In Hindi) | लिंक सूची Traversing

लिंक सूची Traversing

हम ये मान लेते हैं की head पॉइंटर फर्स्ट नोड को पॉइंट कर रहा है। हमे traverse करने के लिए निम्नलिखित कदम लेने होंगे :-

  1. Follow the pointers.
  2. Display the contents of the nodes (or count) as they are traversed.
  3. Stop when the next pointer points to NULL.


listLength() फंक्शन लिंक्ड लिस्ट में कितने नोड्स हैं उन्हें बताता है।
यही फंक्शन लिंक्ड लिस्ट प्रिंट करने के लिए  भी  इस्सतमल में आ सकता है।

def listLength(self):
   current = self.head
   count = 0
   while current != None:
      count = count + 1
      current = current.getNext()
   return count

Time Complexity: O(n)
Space Complexity: O(1)

Comparison of Linked Lists with Arrays and Dynamic Arrays (In HINDI)

ऐरे और डायनामिक ऐरे के साथ लिंक सूचियों की तुलना



लिंक सूचियों के साथ मुद्दे (नुकसान)
लिंक सूचियों में मुद्दों का एक नंबर रहे हैं। लिंक सूचियों के मुख्य नुकसान व्यक्ति तक पहुँच समय है तत्वों। ऐरे यह सरणी में किसी भी तत्व का उपयोग करने के लिए ओ (1) लेता है, जिसका मतलब है यादृच्छिक अभिगम है। लिंक सूचियों सबसे खराब स्थिति में सूची में एक तत्व के लिए उपयोग करने के लिए O (एन) लेता है। उपयोग समय में सरणियों का एक और लाभ यह है स्मृति में spacial इलाके। सारणियों स्मृति से सटे ब्लॉक के रूप में परिभाषित कर रहे हैं, और इसलिए किसी भी सरणी तत्व हो जाएगा शारीरिक रूप से अपने पड़ोसियों के पास। यह बहुत आधुनिक सीपीयू कैशिंग तरीकों से फायदा होता है।

लिंक सूचियों के लाभ
लिंक सूचियों के फायदे और नुकसान दोनों है। लिंक सूचियों का लाभ का विस्तार किया जा सकता है लगातार समय में। एक सरणी (Array) बनाने के लिए हम तत्वों की एक निश्चित संख्या के लिए स्मृति आवंटन करना चाहिए। अधिक 
तत्वों (element) जोड़ने के लिए हमे एक नई सरणी (Array) बनाना होगा और नई सरणी में पुराने सरणी (array) नकल करना चाहिए। यह ले जा सकते हैं काफी सारा समय। हम शुरू में अंतरिक्ष के बहुत सारे आवंटन से रोक सकते हैं, लेकिन फिर आप की जरूरत से ज्यादा का आवंटन हो सकता है और स्मृति बर्बाद कर रहे। एक लिंक सूची के साथ हम आवंटित सिर्फ एक तत्व के लिए अंतरिक्ष के साथ शुरू कर सकते हैं।


धन्यवाद

Friday 27 November 2015

Python Program with time complexity of log (n) | पाइथन प्रोग्राम जिनकी टाइम कोम्प्लेक्सिटी log n है।

नमस्कार आपका यहाँ स्वागत है।
आज हम कुछ ऐसे पाइथन प्रोग्राम देखेंगे जिनकी टाइम कोम्प्लेक्सिटी ( time complexity ) लोग न ( log n ) है।
और साथ ही में हम यह भी बतायेँगे की इन पाइथन प्रोग्राम्स की time complexity (समय जटिलता ) log n क्यों है।

पहला प्रोग्राम :-
def Logarithms(n):
    i = n
    while i >= 1: 
        i = i // 2
        print i 

Logarithms(100)
# time complexity is log2(n)

कृपया ध्यान दें की logarithm (लघुगणक) का बेस २ है .

अब हम इसकी टाइम कोम्प्लेक्सिटी निकलते हैं।

आप // ऑपरेटर के कुछ उदाहरण पर विचार कर सकते हैं
5//2 = 2
6//2 = 3
11//2 = 5

यह बहुत जटिल (कठिन) नहीं है, हालांकि, यह देखने का एक और अधिक गणितीय तरीका है।
सवाल यह है की  आप कितनी बार आप 2 से एन (n) को विभाजित कर सकते हैं ताकि आपको १ मिल जाये , है ना?
ऊपर दिए गए बयान अनिवार्य रूप से आपको यह बता रहे हैं की  आप (2 से विभाजित)  करते रहें जब तक आपका अंक १ से बड़ा है।

1 = N / 2^x
2^x से गुणा:
2^x = N
log2(2^x) = log2 N
x * log2(2) = log2 N
x * 1 = log2 N
x = log2 N



ग्राफ : y = log2(n)


दूसरा प्रोग्राम :-

def Logarithms2(n):
    i = 1
    while i <= n: 
        i = i * 2
        print i 

Logarithms(100)

इस प्रोग्राम का काम ऊपर वाले प्रोग्राम के विपरीत है।

यहां हालत गलत होंगे जब 2^x > N हो जायेगा।
अर्थात्
2^x = N
log2(2^x) = log2 N
x * log2(2) = log2 N
x * 1 = log2 N
x = log2 N

हम स्पष्ट रूप से समय जटिलता (time complexity) फिर से वही है। 


Wednesday 25 November 2015

Interactive mode in python program (in HINDI) | पाइथन प्रोग्राम में इंटरैक्टिव मोड।

हम जानते हैं की पाइथन एक प्रोग्रामिंग भाषा है, लेकिन यह नहीं जानता कि प्रोग्राम क्या है? इसलिए, प्रोग्राम को समझने के लिए हम पाइथन का इस्सतमल करेंगे।
पाइथन शैल ( python shell )दो तरीकों से किया जा सकता है, अर्थात।, इंटरैक्टिव मोड (interactive mode) और स्क्रिप्ट मोड( script mode )। जहाँ नाम का सुझाव के रूप में इंटरएक्टिव मोड, हमें ओएस (OS) के साथ बातचीत करने के लिए अनुमति देता है;
स्क्रिप्ट मोड (script mode) हमें पाइथन सोर्स फाइल बनाने में मदत करता है। अब, हम पहली इंटरैक्टिव मोड के साथ शुरू होगा।

इंटरैक्टिव मोड


>>>print “How are you?”
How are you?

पाइथन की प्रतिक्रिया जान लेते है। हम निम्नलिखित स्टेटमेंट लिख कर प्रतिक्रिया की जाँच कर सकते हैं।
i)print 5+7
ii) 5+7
iii) 6*250/9
iv) print 5-7


कुछ उदाहरण दिए गए हैं नीचे


अब हम एक छोटे से कोड लिखने के लिए अच्छा कर रहे हैं
^ D (Ctrl + D) या quit() दुभाषिया (interpreter) छोड़ने के लिए प्रयोग किया जाता है।
^ F6 खोल ( shell ) पुनः आरंभ करेगा।


अगर हमे बड़े कोड लिखने हैं तो हमे shell मोड का इस्सतमल करना पड़े गा। 

धन्यवाद

Tuesday 24 November 2015

Radix Sort in Python (in HINDI) | पाइथन में रेडिक्स सॉर्ट।

कथन:
प्राकृतिक क्रम में उन्हें पुनर्व्यवस्थित, पूर्णांकों की एक अव्यवस्थित सूची को देखते हुए।

नमूना इनपुट: [534, 246, 933, 127, 277, 321, 454, 565, 220]
नमूना आउटपुट: [127, 220, 246, 277, 321, 454, 534, 565, 933]

:समाधान की समय जटिलता (Time Complexity)
सबसे अच्छा मामले ओ (के एन) O(kn); औसत के मामले ओ (के एन)
O(kn); सबसे खराब स्थिति हे (के .एन.)O(kn),
जहाँ पर के (k) सबसे लम्बे नंबर की लम्बाई है।

k lon(n) "क लॉग (एन)" से अधिक है तो एक nlog (एन) एल्गोरिथ्म एक बेहतर फिट होगा। हकीकत में हम हमेशा मूलांक बदल सकते हैं

दृष्टिकोण:
मूलांक तरह, प्रकार और बाल्टी प्रकार की गिनती की तरह, आधारित एक पूर्णांक है
इनपुट सरणी के मूल्यों यानी # एल्गोरिथ्म (माना जाता है पूर्णांकों)। इसलिए मूलांक तरह सबसे तेजी से छँटाई एल्गोरिदम के बीच है चारों ओर, सिद्धांत में। मूलांक तरह के लिए विशेष भेद है
यह प्रत्येक सिफर (यानी अंकों) के लिए एक बाल्टी बनाता है कि #; जैसे की, प्रकार बाल्टी के लिए भी इसी तरह, मूलांक तरह प्रत्येक बाल्टी होना चाहिए अलग चाबियाँ स्वीकार कर सकते हैं कि # उगने वाली दाढ़ी सूची।
दशमलव मूल्यों के लिए , बकेट की संख्या दशमलव के रूप में 10 है, प्रणाली 10 अंकों के / Cyphers (यानी 0,1,2,3,4,5,6,7,8,9) है। फिर चाबियाँ लगातार महत्वपूर्ण अंक के अनुसार क्रमबद्ध हैं।

प्रोग्राम के नीचे लिखा है :-

def RadixSort(A):
    RADIX = 10
    maxLength = False
    tmp , placement = -1, 1

    while not maxLength:
        maxLength = True
        buckets = [list() for _ in range(RADIX)]
        for  i in A:
            tmp = i / placement
            buckets[tmp % RADIX].append(i)
            if maxLength and tmp > 0:
                maxLength = False

        a = 0
        for b in range(RADIX):
            buck = buckets[b]
            for i in buck:
                A[a] = i
                a += 1
    # move to next digit
    placement *= RADIX
    return A
A = [534, 246, 933, 127, 277, 321, 454, 565, 220]
print(RadixSort(A))



यही प्रोग्राम अगर आप सभी प्रकार के इनपुट के लिए लिखना चाहते हैं तो वह भी निचे लिखा गया है।
def RadixSort(A):
    RADIX = 10
    maxLength = False
    tmp , placement = -1, 1

    while not maxLength:
        maxLength = True
        buckets = [list() for _ in range(RADIX)]
        for  i in A:
            tmp = i / placement
            buckets[tmp % RADIX].append(i)
            if maxLength and tmp > 0:
                maxLength = False

        a = 0
        for b in range(RADIX):
            buck = buckets[b]
            for i in buck:
                A[a] = i
                a += 1
    # move to next digit
    placement *= RADIX
    return A
A = []
n = input("Enter the numebr of elements you want to sort : ")
print("Enter the numbers : \n")
for i in range(0, n):
    num = int(input())
    A.append(num)
print(RadixSort(A))



धन्यवाद

Time Complexity involving if, elif and else condition in Python Program (in HINDI)

पाइथन प्रोग्राम की समय जटिलता ( टाइम कोम्प्लेक्सिटी ) जिनमे if, elif, अथवा else कंडीशंस इस्सतमल किया गया है।


निचे कुछ उदाहरण मैंने लिख रखे है। 

पहला उद्धरण

def SimpleIfCondition(n):
    i = n
    if i == 0: 
        i = i + 1
    print i

इस प्रोग्राम की समय जटिलता ( टाइम कोम्प्लेक्सिटी ) ओ(1) यानी  "O(1)" है।

विवरण / व्याख्या
हम मान लेते हैं की असाइनमेंट (assignment) ऑपरेटर केवल एक यूनिट समय लेता है। 
साथ ही में अगर कोई कंडीशनल if , elif अथवा else कंडीशन है तो वह भी एक यूनिट समय लेता है। 

अब हम साफ देख सकते हैं की ४ (4) स्टेटमेंट निष्पादित (execute) होंगे अथार्त हम इस फंक्शन की समय जटिलता (time complexity) को O(4) बोल सकते है जो की O(1) के बराबर है।
यह प्रोग्राम कांस्टेंट समय लेता है। 

दूसरा उद्धरण 
def IfElseCondition(n):
    i = n
    if i == 0: 
        i = i + 1
    elif i == 1:
        i += 2    
    print i  
    
# O(1)

यह उदाहरण भी पिछले उदाहरण की तरह है।
इस की टाइम कोम्प्लेक्सिटी भी O(1) ही है।
इस प्रोग्राम के लिए स्पष्टीकरण की कोई जरूरत नहीं है।

कुछ ऐसे प्रोग्राम जिनकी टाइम कोम्प्लेक्सिटी O(n) है। 

तीसरा उद्धरण 
# O(n)    
def testFunction(n):
    for j in range(1,n):
            print j           

इस फंक्शन में फॉर लूप ऍन(n) बार चल रहा है और हर बार j की वैल्यू प्रिंट कर रहा है। अर्थार्त इस फंक्शन की टाइम कोम्प्लेक्सिटी O(n) है। 

चौथा उद्धरण  
# O(n)
def IfElseCondition2(n):
    i = n
    if i > 0: 
        for j in range(1,n):
            print j
    elif i < 0:
        i += 2    
    print i   

अगर हम इस फंक्शन में ऍन (n) की वैल्यू 0 से बड़ी डालते है तो इस प्रोग्राम की टाइम कोम्प्लेक्सिटी भी हो O(n) जाएगी। 
जैसा की हम जानते हैं  प्रोग्राम की सबसे खराब मामले की प्रतिनिधिनित्वा करता है। इसीलिए इस का टाइम कोम्प्लेक्सिटी O(n) है। 

पांचवा उद्धरण 
# O(n^2): Note that if testFunction is executed always
def IfElseCondition3(n):
    i = n
    if testFunction(n) > 0: 
        for j in range(1,n):
            print j
    elif i < 0:
        i += 2    
    print i   


नोट है कि अगर हमेशा चलता है तो इस्सकी टाइम कोम्प्लेक्सिटी ओ(n^2) हो जाएगी। 

आप को किसी भी प्रकार का संदेह है तो इस पोस्ट की टिप्पणी अनुभाग में पूछ सकते है। 

धन्यवाद 

Monday 23 November 2015

Time Complexity of Python Programs With Break Statement

हिंदी में प्रोग्राम को समझाया गया है 

यह पोस्ट में python कार्यक्रम से जुड़े बयानों (functions) अथवा प्रोग्राम की समय जटिलता ( Time Complexity ) खोजने के बारे में है।
ये break स्टेटमेंट इस्सतमल किये हुए प्रोग्राम की समय जटिलता बताता है।

def Function(n):
   count = 0
   for i in range(n / 2, n):  # बाहरी पाश एन / 2 बार निष्पादित होता है।(Outer loop execute n/2 times)
      j = 1
      while j + n / 2 <= n:  # मध्य पाश के पास ब्रेक स्टेटमेंट है (Middle loop has break)
         break
         j = j * 2

      print (count)

Function(20)


इस प्रोगाम में आप ऍन की कोई भी वैल्यू लें सकते है परन्तु जो परिस्थिति दी हुई है ( j + n/2 <= n ) वो हमेशा ही सही रहेगी। इसके परिणाम के रूप में while लूप ख़त्म ( terminate ) हो जाता है। यह प्रोग्राम का while ब्लॉक केवल एक ही बार चलेगा क्योकि ब्रेक स्टेटमेंट प्रोग्राम को while लूप से बहार ले जायेगा और लूप ख़त्म हो जायेगा।
परन्तु फॉर लूप वाला ब्लॉक ऍन बार चलेगा। 

प्रणाम स्वरूप इस पाइथन प्रोग्राम इस समय जटिलता ( Time Complexity ) ओ(n) अथवा  O(n) हो जाएगी। 


Python program explained in English

Here we are going to learn how to find the time complexity of a python program which involves the a break statement.
The program is written in the above segment of this post.

In the program if we put any value of n ( in this case I have taken 20 as the value of n), then the condition inside the while loop ( j + n/2 <= n) remains true and then the execution of break statement takes place which brings us out of the while loop and then clearly we can see that the for loop is running n times. So the overall time complexity of the above program is O(n).

Thursday 12 November 2015

Don’t let mental blocks control you. Set yourself free. Confront your fear and turn the mental blocks into buildinblocksg

Saturday 3 October 2015

Learn C# for Beginners : switch statement | C Sharp Tutorials


This Video will guide you through the basics of switch statement and at the end of this video you will be able to create a basic calculator application in C# using Microsoft's Visual Studo development software.

Here you can find the source code for the calculator program in C# (c sharp)

But I strongly recommend to minimize your browser and try this yourself first.