 Good morning and welcome back for the continuation of the session and the third lecture. What we have seen so far is a one dimensional array a 0, a 1, a 2, a 3, a 4 and so on. For example, we can declare an array to contain 100 roll numbers. We can have another array which can contain marks for those 100 roll number students. We could easily combine these into a multi dimensional array that is the motivation for multi dimensional array. Similarly, a statement such as float a 5 defines a one dimensional array of floating point numbers. The way we should introduce a two dimensional array is that if this defines five elements or five floating point values, then a declaration of the type int a 10, 10 will declare a two dimensional array or a 100 element array. The point is although this array stores 100 values, these are not accessed from a 0 to a 100 ordinarily, but they will be accessed as a two index mechanism for accessing an element. So, an element in this array for example, is a 4 3. So, a 4 3 will be the element which will be fourth not fourth row, but fifth row and fourth column element. Remember that every dimension of a multi dimensional C array begins the index from 2 from 0 and continues up to size minus 1. We illustrate this using the example of matrix multiplication. So, we start by saying that assume that there is a matrix a which is m by n and another matrix b which is n by p, then as per the matrix multiplication rules, the resultant multiplication matrix a b will be m into p matrix. We may state the actual formula which is used to compute a matrix multiplication. For example, the i comma jth element of the multiplication array C will be computed from various elements of a and b using this summation a i k into b k j for all values of k. It is useful to remind our students that in matrix multiplication, the matrix are supposed to be compatible to be multiplied, which means that the second dimension of the first matrix and the first dimension of the second matrix should be same. That is why m into n matrix can be multiplied with n into p matrix and the resultant matrix will be m by p and that is why this summation sigma where we have simply stated that summation is over k, k actually is a variable which varies from 1 to the specification n here. So, for every element i and j where i changes from 0 to m minus 1 and j changes from 0 to p minus 1, I will do this summation for all values of k varying k from 0 to n minus 1 which is the compatible dimension of the two matrices. A simple program can be written to demonstrate matrix multiplication. We illustrate the algorithm first where we say that we first read the two matrices a and b into the memory by after defining the two arrays appropriately two dimensional arrays. Then C is computed as per above formula and C i j in our program will be output as soon as it is ready means as soon as it is computed will output it. Of course it will also be stored because we will be assigning the final value to C i j consequently it is possible to complete all the computations and output the resultant matrix C completely. We should tell our students to watch for the indices because indices vary differently in C programming language. So, here is a matrix multiplication program there would of course be the usual definitions and so on. There would be reading of input so matrix a and matrix b is supposed to have been read here. Notice the iteration that is being set up for matrix multiplication is a nested iteration. The first index i varies from 0 to m 0 to m minus 1 actually. The second index j within the iteration set up for i varies from 0 to p minus 1. This is exactly as per the definition of matrix multiplication where to calculate C i j where i ranges between 0 to m minus 1 and j ranges between 0 to p minus 1. Consequently when C i j computation happens inside this nested iteration each element of C for all values of i and all values of j will be computed once this nested iteration is completed. Inside this nested iteration we first begin by saying C i j is equal to 0. Let us go back to the slides two previous slides here. Notice that the computation of C i j itself is a summation which will require a separate iteration varying k from 0 to n minus 1. So, let us go to the slide showing the program. Here you will notice that since it is a summation I have to first start with a 0 value for the final result and keep adding the appropriate product components to this 0 value one by one over a separate iteration. The third iteration is set up here using a variable k for k equal to 0 to n minus 1 this is the iteration and what this iteration does is that for every value of k it calculates a i k into b k j which is an element of the sigma summation and adds it to the element C i j. So, we can tell our students that look C i j is almost like a fixed variable as far as this iteration is concerned that fixed variable is like sum or something. So, the sum is initialized to 0 then sum is incremented sum is equal to sum plus a i k plus b k j. Observe that inside this iteration for k i and j both are fixed that is why C i j becomes a fixed variable and a i k and b k j assume or range over different elements of the two arrays calculating that sigma. It is easy for people to see once they understand these things that when I execute this complete nested iteration for every value of i and j I would have calculated the appropriate sigma summation and therefore calculated the value of C i j. Now, as I said earlier it is possible for me to complete the entire computation and at the end here where I have shown three dots to create an output instruction which will output all the elements of C alternately as in when the element of C is computed I can output the element of C here by saying output C i j. This will output the i th row j th column element. Observe that i and j both are defined by the outer loops before this point j and i. So, matrix multiplication actually is a fairly simple operation. I also have a program ready which shows you how to solve a system of linear equations the Gauss Jordan elimination method. That is a fairly complex algorithm. Those of you are familiar with Gauss Jordan elimination or a method to finding out solution of linear algebraic equations. We will appreciate that. I will be posting that program in C tomorrow on to the Moodle site as well as I will mail it to the coordinators that is for reference and all participants may like to read that program and comment on it later. The other example that I wish to discuss today is that of magic squares. So, what is a magic square and n into n square matrix where the sum of elements of every row and every column is same. Additionally, sum of elements of each of the main diagonals is also same. So, this is a very interesting mathematical entity a magic square to repeat magic squares is an n by n square matrix where the sum of every row every column and the major diagonals is same. Here is an example 8 1 6 3 5 7 4 9 2. This n by n this 3 by 3 magic square is also referred to by the constant sum which is 15. So, notice that whether you sum any row here first second or third whether you sum a column here first second or third or whether you sum a diagonal here or the major diagonal here you will still get the sum as 15. This was known to Chinese there is a reference because Chinese history is well documented it is called low shoe square and this was known some 650 years before Christ. Incidentally 3 by 3 magic squares were also known to Indian since Vedic times. So, this mathematical entity is of a old vintage but it is an interesting entity and typically a problem that can be posed to our students is that if I give you a 3 by 3 matrix of integer numbers determine whether that matrix is a magic square or not. So, determine if a matrix is a magic square is a problem. The program that I have written for this magic square I have written a partial program as you will soon see I first define the square matrix of an arbitrary size 20 by 20. Of course the actual matrix that will be inputted for the examination whether it is a magic square or not will be much smaller and that will typically be of size n by n. Therefore, I define n as an integer variable I define a 2 dimensional array square 20 as a 2 dimensional array which you store my given matrix I define i and j as index variables and I define sum as an additional variable which I may use in my computation. This sum is actually the sum of the magic square. So, for example for the 3 by 3 matrix that we saw in the previous slide the value of sum would be 15. Of course when some people give us an n by n matrix and ask us to determine whether it is a magic square or not we would not know the sum in advance. So, what we could do is we could find out the sum by a formulation and curiously for any n by n magic square if it is indeed a magic square namely all its rows columns and major diagonals add up to the same value that sum value is actually given by this formula n into n square plus 1 by 2 this again is well known. So, the program does the following it also defines by the way variables to accumulate individual sums of rows and diagonals. So, I have defined here int r sum int c sum int d 1 sum and int d 2 sum I have defined all of these sums to 0, 0, 0, 0, 0 to begin with. Now, I read n the value of n itself. So, somebody may give me a 3 by 3 matrix somebody may give me a 4 by 4 matrix somebody may give me a 5 by 5 matrix and ask me to check whether that is a magic square. So, I read the value of n and then I will read n into n elements of the array these elements will be read in the matrix in the array called square 20 comma 20. Here again if you are giving this example it is useful to tell students that if it is an n by n matrix then the indices will vary from 0 to n minus 1 and 0 to n minus 1 respectively for rows and columns. The actual verification is in fact a simple process we say calculate all the sums. So, what we are doing for i equal to 0 i less than n i plus plus for j equal to 0 j less than n j plus plus I calculate r sum equal to r sum plus square i j then I calculate c sum equal to c sum plus square i j i. Notice that for a variation of i and j I can calculate r sum and c sum using this formula and then I calculate d 1 sum plus equal to square i i d 2 sum plus equal to what that is the question. Square i i let us we will go over to the next slide to demonstrate this. Incidentally this program is not correct. So, before you find the flaw I am telling you that this program is not correct I would request you to find out what is the error in this program. This program is also not complete because here I have said d 1 sum plus equal to square i j but I have not said d 2 sum plus equal to what remember that we would have introduced the expressions earlier to our students. So, they would know plus equal to as an increment operation this means d 1 sum is equal to d 1 sum plus such and such thing d 2 sum we are not very sure what should be the formula for calculating d 2 sum. So, we look at this program and then we can illustrate some of the computations and then ask some questions. First to show how the terms of a row are added we have said in our formula in the program an instruction r sum equal to r sum plus square i j for i equal to 1 j equal to 0 1 and 2 let us see what will happen square i comma 1 comma 0 ok. So, what I am trying to show I think you should ignore the the arrows but I think somewhat they are indicative. So, when I am looking at i equal to 1 I am actually looking at the second row the first element of the second row is p which is square 1 0 which is shown here the second element which is element for j equal to 1 in the first row in the second row that is row i equal to 1 is 5 and this is 7. So, this arrow should actually be pointing up here. So, these three are being added as 50. So, this is how the row sum is being computed for a specific value of i but for different values of j. In exactly the same fashion the diagonal sum will calculate it. So, let us see how diagonal sum is being calculated d sum we said plus equal to square i i this will add the following this is my matrix for example. So, for a given value of i since I will range from 0 1 and 2 square 0 0 will be value 8 square 1 1 will be value 5 and square 2 2 will be value 2 these three will be added these also turn out to be 15. So, this 15 can be compared with the sum that we have calculated to check whether it is indeed a magic square or not. Now, this is about calculation of d 1 sum the issue is what should be the way in which d 2 sum will be represented. So, once again we read here d 1 sum plus equal to square i i will add these terms square 0 0 square 1 1 and square 2 2 there is another mistake here it should not be square 3 3 it should be square 2 2 the question now is while summing the main diagonal element square i i sum of the other diagonal d 2 sum can be incremented by what term. So, should I add to d 2 sum square n minus i plus 1 i square n minus i i square i n minus i minus 1 or none of these this must be done inside the earlier loop for j this is the quiz I will repeat again I am dealing with an n by n matrix it was an explicit 3 by 3 matrix or 4 by 4 matrix it would be easier for me to write the index exactly but it is an n by n matrix. So, I have to define the indices for increment in terms of n only the question is one diagonal can be summed up by incrementing the element by square i i how do I add the increment to d 2 sum Perrier says choice to Simba says Pune says choice C any other answer B and C so far Amruta says C PHG says C NIT says B Seagal technology says B C OEP Pune says C Nirma says C Rehanayati Nagpur says C's if we could go by majority opinion C would be the answer ok. So, I think this was good enough but when we raise this question to our students students will definitely take some time to appreciate what is happening after raising such a question what I have found is that it is useful to analyze the possible answers in some details so that any student who has any doubt the doubt gets clarified here is the analysis when we add a i i the i will take values 0 0 1 1 2 2 3 3 this is what the main diagonal will be the analysis is being done assuming that n is equal to 4 so for that situation I will take values 0 0 1 1 2 2 3 3 with respect to n we can quickly calculate what will be the indices for the choices A B C and D for example for the first choice where the first element is indexed by n minus i plus 1 and second element is indexed by i we get the values 5 0 4 1 3 2 2 3 obviously these do not represent the element of the second diagonal look at B it says square n minus i and i this will have actually index values 4 0 3 1 2 2 and 1 3 again this is not correct the value of the second index is varying from 0 1 2 3 but the value of first index is varying from 4 to 1 which is incorrect in C C indices must vary between 0 to n minus 1 look at the option C which incidentally is the correct answer square i n minus i minus 1 this one will vary over 0 3 1 2 2 1 and 3 0 this is indeed the correct answer incidentally if I wrote the increment as n minus i minus 1 and then i I would still get the same sum but I would be summing in a different order it will be 3 0 2 1 1 2 and 0 3 observe that when the main diagonal is 0 0 1 1 2 2 3 3 one of the main diagonals then the other main diagonal will be 0 3 1 2 2 1 sorry 0 3 1 2 2 1 3 0 or 3 0 2 1 1 2 0 3 and that is why C is the correct answer or its mirror image could have been the correct answer the choice D is none of these this must be done inside the earlier loop for J is meaningless because it is a square matrix and wherever I know the value of i I implicitly know the value of the other index because that is related to i n n only and therefore none of these is incorrect answer incidentally I mentioned earlier that such quiz questions are extremely useful in judging whether our students have understood whatever is being discussed or not ordinarily to conduct a quiz formally you require to distribute answer sheets collect their answers and then examine them in a classroom typically we would ask questions and some students will answer a better method even in a classroom is to ask people to raise their hands and based on the number of people who raise their hands for the right question right answer we can judge as teachers whether the concept has been understood or not however when the class size becomes large there are two problems counting of hands becomes very difficult second there is no record of hand raising that is ever kept consequently conduct of such quizzes cannot be used to avoid marks to students and as teachers you will all agree with me that if there are any marks associated with a quiz then the enthusiasm shown by the students the attention paid by the students and the mind application that happens is much greater that is the reason why I decided to introduce those clicker devices unfortunately not all centers have yet received all the clickers but from Monday onwards whatever be the number of clickers that have been received by different centers I will actually be using those clickers to conduct quizzes and we can see the total assembled data that we can instantly get which can be counter displayed from here to the benefit of all participants so here is the right expression d 2 sum is equal to d 2 sum plus square i n minus i minus 1 and as I mentioned earlier one can also use the symmetric equivalent which is d 2 sum equal to d 2 sum plus square n minus i minus 1 i for n equal to 4 this will add terms in a different sequence with index values 3 0 2 1 1 2 and 0 3 but it will still meet the requirements so these were some examples that I wanted to discuss I will take one more not example but one more domain which is rich with real life problems that one would like to solve using computers these real life problems relate to simulation of different activities in particular board game simulation or simulation of any game where there is an element of chance is a very interesting activity this is done by generating random numbers and using random numbers to simulate real life situation I would like to add that random numbers are useful not only in simulating games but in actual real life situation as well for example when there is a lottery for allocation of houses which let us say are created by the government under some scheme assume that there are 20 houses and there are 200 applicants to purchase those houses often governments resolved to a lottery system now in any lottery there is an element of chance and one must ensure that a computerized lottery actually depicts the correct element of chance as would happen in a real lottery that is where the use of random numbers becomes very prominent so here is a slide to illustrate to our students the notion of random numbers and how and where they could be used so a popular example snakes and ladders is a board game which most of our students will know just as we all know it most of us have played it in our childhood there could be various card games which can again use the random numbers for simulating those games in snakes and ladders and such board games and some of the card games a dice is thrown to get a number between 1 to 6 or in a card game cards are dealt randomly again you need random number generator this is perhaps not the place to teach our students the entire random number theory but they would have studied a little bit of probability and a very little bit of statistics in their school maths which is adequate to explain both the concept of computerized random number generation and the use of such random numbers in simulating certain activities such as a board game later I will be posting a program which simulates a game of snakes and ladders in fact this was given as a problem in the final examination here a problem very similar to this I will post that problem and also post that solution for your benefit so to continue this discussion to explain the notion of random numbers which are generated by computers to our students we may talk about uniform random numbers a uniform random number is when a number is randomly chosen from the same set and each number has the same probability of occurrence incidentally when we throw a dice the number that appears will be from the set 1 to 6 depending upon which phase shows up and a ideal dice actually has equi probability for each of these numbers that means any one of these numbers will throw up with equal probability and we would like to simulate such a situation using computers so when we use a computer to simulate any game of chance we need to generate random numbers here we can introduce the notion of pseudo random numbers we say that computer can generate a sequence of numbers only by using a specified algorithm and that algorithm will be used by the program that we write to simulate the game so this algorithm could be a function for example typically given a starting number as seed the same sequence will always be generated so for example to such an algorithm if I give a seed 4, 5, 6 then it will generate a certain sequence if I again use the same function same algorithm giving the same seed it will again generate the same sequence so the question that our students may ask is where is the randomness such sequences are called pseudo random numbers because they are not really random however since the next number is such a sequence cannot be guessed without knowing the algorithm for the user of the algorithm the sequence is random in order to ensure that every time I run the random number generating algorithm and it should give me a different sequence then I have to use a different initial seed value by using different initial seed values different sequences can be generated last but not the least we can give some examples of random numbers for example representing toss of a coin a uniform random number has to be generated with value either 0 or 1 for representing throw of a dice as I explained earlier we need to generate a uniformly distributed random number in the range 1 to 6 now we state to our students that the standard library in seed programming language namely the stdlib contains a function called ran which does not have a parameter so whenever we say ran a random number is generated and is given back to us it generates a uniform random number however it is a large integer value in fact the sequence of random numbers that is generated by successive cost to ran will be all large random numbers large integer numbers so if we want the large integer numbers to be limited to a certain range such as 1 to 6, 1 to 10 or whatever then we will have to do some arithmetic operations upon it further if we want to generate different sequences every time we run this program there is a facility to provide a seed this is done by another function called s ran which is used to provide a seed to the random number generating algorithm if in my program I take one seed value as input then that seed value will be fed once and for all to the internal random number generator and the generator will generate an appropriate random sequence using that seed if next time I run the program I give it a different seed it will run a different sequence now this is the description of what random numbers are what pseudo random numbers are how pseudo random numbers are useful and what are the facilities provided by seed programming language environment I call it an environment because seed programming language itself does not have such built-in functions they have been built as a part of the standard library subsequently we can show them examples of how such pseudo random numbers can be used to write programs to simulate real life activity as I mentioned I will later on show you a program which simulates a board game with this let us now go over to different centers and if you have any query either regarding this session or the previous morning lectures or for that matter anything about workshop please feel free to raise your query I am George from Anna University there is a function called random mice in seed would you please tell me what is it for I am not aware of the function random mice I will study that in the STD lip and then come back to you maybe tomorrow morning however I would like you and all our colleagues to remember that we should not use terms such as a function random mice in seed please remember that in seed there is no such no function at all the functions are available as part of libraries which have been built by others so I think it is useful to tell our students to distinguish between the features of a programming language and features that have been added to that programming language through the use of libraries of course intrinsically we assume that all library functions are part of seed but there is a subtle distinction particularly when we first time talk about library it is useful to say is this function available in the seed library or standard library by the way if something is not available in standard library I could always write such functions myself put them into my own library the seed compiler whether it is GCC or any other seed compiler in any other environment will permit you to link together functions from multiple libraries to your compiled program to create a meaningful executable let's go over to the COEP Pune okay thank you I notice that you always ask two questions whenever you ask questions but that's okay the first question that you ask related to the algorithm which I represented notice that I had mentioned that this program is wrong you have spotted out the error correctly having a single variable for row sum and column sum is not correct because there are three rows and three columns in a three by three matrix or four rows and four columns in a four by four matrix incidentally your observation that the summation will merely give you the sum of last row and last column is also unfortunately not correct because the same variable keeps adding values for all values of the indices i and j so actually you will get a massive sum which will neither be the sum of a row nor will be sum of a column but that's an error which can be easily corrected perhaps you may consider having two one-dimensional arrays for row sum and column sum so since there are n rows and n columns n varying between 0 to 19 because the original matrix is 20 by 20 at max you may actually define a row sum array of 20 elements and a column sum array of 20 elements indices varying between 1 to 19 and within the nested iterations calculate individual elements of these because indeed there will be so many rows and columns so thank you for pointing that out gave me an opportunity to clarify as far as second question is concerned there are large number of graphics packages in unix environment the fact of life is that most of the colleges do not believe in experimenting with unix environment and therefore they miss out on the rich graphics that is available just to give you an example xlib or xlibrary is a fundamental underlying graphic system which is put on practically every unix machine on top of it you have multiple graphic packages the simplest is a turtle graphics which is actually a toy graphics which is in fact used to teach school children all across the world in the developed countries the fundamental concepts of not only graphics but of programming curious so complete programming concepts can be taught using turtle graphics so turtle or k turtle can be downloaded from net if you search on the net you will find a large number of graphic packages which are available I do not know did we include any graphics package in our pack which we have sent I will check up in the package that has been sent as a distribution to all coordinating centers probably there is some graphic package but I am not sure because in this subject coverage we had not considered including graphics but in so far as unix environment is concerned some of the best graphics packages are actually available high end packages are actually available only on unix and unix derivative workstation so if you take for example the high end graphics work which is done either in geographical information system or in remote sensing or in image processing most of the workstations are based on the unix operating system or its derivative so to conclude to answer your question there are indeed a large number of packages yes its a question of searching them if you just go to internet and say graphics in unix or graphics under unix you will get a number of downloads there are commercial products but there are also free open source graphics packages which are entirely usable lets go over to the next ASC Amrutapuri has a query I have a doubt regarding why you have introduced the algorithmic complexity for the first semester students it may not be very difficult for them to understand that the program complexity is of polynomial time or of order n square or something like that so even in your quiz which you have conducted you told that your students gave the option it is very difficult to guess so in that case what is the thing behind saying that we should teach algorithmic complexity to say about the execution of the program and in that for the first semester students I think is it you are getting the question that the need for the algorithmic complexity to be taught at this point of time yes very good point that you are making I will tell you two things by the way the comment about my students was limited to their ability to answer that particular quiz question it did not mean that they did not easily understand the algorithmic complexity in fact there were several other questions asked subsequently after the concept was clarified which they could answer very easily second point I will make is that we all believe that first year is not the place to teach algorithmic complexity is because we never studied ourselves algorithmic complexity in first year as a matter of fact after studying several subjects in computer science only then we studied the notion of algorithmic complexity and therefore implicitly we believe that this is a very complex concept and cannot be introduced at the entry level I beg to differ I have found out not only in the last semester when I taught but even earlier whenever I talked about this notion people understood it very easily the issue is what terminology you use to explain this notion please remember that I did not talk about algorithmic complexity till I had explained through examples the notion of efficiency of a program you will all agree that our students must learn to write efficient program efficiency tied to the time of execution now this notion every student as a matter of fact every human being understands to do an activity faster is the objective of most people doing any meaningful activity and therefore to tell our students that right programs which you run faster is natural the point is when I ask them to write efficient programs we all think it is alright but when I connect it up with the notion of time complexity of algorithm we believe that is suddenly an advanced concept I submit that that is not so firstly we are not teaching them about algorithmic complexity in the context of order n square, order n, order n log n in as many theoretical details as algorithmic complexities discussed in advanced courses but let me tell you that people find it extremely easy to understand order n, order n square, order n cube and order log n complexity particularly when they look at problems involving a single iteration a nested iteration of n into n or a triple nested iteration as we saw in the matrix multiplication algorithm similarly when we discuss binary search they easily appreciate the successive reduction of search space by half and therefore they can understand and appreciate that things can be done in log n time so people do not find it difficult even at first year level to understand and appreciate it so final answer to your question is to introduce elementary concepts of efficiency of your program is absolutely essential in my opinion we may or may not connect it up with the word like algorithmic complexity that is a matter of choice which you as an individual teacher can make depending upon what kind of students response that you find however I believe it is mandatory to explain to students that their programs must run efficiently and for that the tool that is available in most operating system environment is so simple whether it is Microsoft or Unix I discussed the Unix tool which says time followed by a command now by asking students to execute the same program for different values of n you can actually hint at how the execution behavior or time required to execute is changing notice that by simple example we could show that the time required to execute the program appears to be proportional to n square consequently to introduce the notion of an order n square complexity is not very difficult so to conclude first it is not at all unnatural and advanced to introduce the basic concept of efficiency second whether this concept of computer program run time efficiency should be necessarily tied up with algorithmic complexity is an issue that is left to the choice of individual teachers I submit that some notion should be introduced I submit that it can be introduced and I submit that almost all students understand the basic notion of algorithmic complexity it is useful for example later on when we tell them to use binary search instead of sequential search if they do not understand the advantage they will perhaps not feel encouraged to write more efficient algorithms so I hope this answers your question let's go over to government engineering college trissure I would like to ask two questions one is in the magic square all the elements should be distinct second thing is it is a general question that is Pascal is I think it is normal because of the influence of C nobody is I think using Pascal to answer first question yes your observation is correct the numbers are required to be distinct the answer to second question is Pascal is not dead as a matter of fact a programming language once born never dies as long as its definition and at least one compiler exists somewhere and at least one user is using Pascal for your information there are colleagues of mine who even today prefer to write programs in Pascal just as there are several colleagues who prefer to write their numerical computational algorithms in FORTRAN but the fact of life is that as computer science has advanced as newer programming languages have come up the facilities and features that they provide and the power of expression that they have and more importantly the huge number of very useful libraries that have got created around modern programming languages generally forces people to shift over to these languages so there is nothing wrong with Pascal in so far as fundamental programming is concerned in fact there are many teachers who were of the view at the time when Pascal was at its top that for teaching programming only Pascal should be used and not any other programming language this was the time when Pascal had probably the best control structures and best program structures as compared to the then prevailing languages however today not only Pascal is not in use but even the use of C programming for doing serious programming is actually going out you will find many C programmers actually using their skills for embedded systems where C is still popular primarily because of its nearness to the machine almost all major applications are being written in object oriented paradigms so while people like you and me may feel sad about Pascal not being used but that is the way life is let's go over to KJ Somya Mumbai hello sir I want to ask two questions first is why we don't consider compile time to calculate time complexity and second is is it possible to return multiple values to function both are good questions the first question why don't we consider compile time while calculating the efficiency of a program the simple answer is a program may be written once but can be used hundreds of times typically unless the program functionality changes the program is not kept only in the source form it is compiled and kept and therefore even if the compilation is going to take a long time it is a one time activity you observe that in today's example also we wrote that program once we compiled it once but we ran it four times with four different values of n once with 10,000, second time with 20,000, third time with 50,000 once with 1000 etc. none of these executions required a recompilation that is the reason why compiled time is not considered generally as a part of efficiency of your program it is an external process which merely converts our instructions into machine language what we are concerned with while describing the efficiency of a program is the run time efficiency the time taken to execute that program and your second question the second question is whether it is possible for a function to return multiple values well explicitly a function can return at most one value that is mandatory however indirectly a function may return multiple values the mechanism to do so is to pass either a parameter or an array to a parameter by address or by reference to a function so if I pass a parameter by reference a variable by reference or if I pass an array an array is always passed as a reference mechanism so not by value generally parameters are passed to the function by value and therefore any modification done on those parameters by the function is never reflected back on to the original parameters indeed that is the clean way of calling a function the function therefore ordinarily returns only a single value so your question can be answered in two ways one strict way answer is no function will return at most one value by the way not one value but at most one value because I can define a function as white which means it does not return a value it is usually written is used to do a certain functionality not concerned with numerical computation and returning value the second way of answering it is that while the function cannot directly return multiple values it can change multiple parameters if the parameters are passed by reference I hope that answers your question we have time for two quick questions the question is whether the constant should be defined by a macro or the constant should be defined by a const keyword it is a completely a matter of choice I do not think there is a particular direction by any programming practice to prefer one over the other it is entirely situation dependent both are right ways of doing it and therefore you can choose anyone I think with this we must stop the last one Periyar Maniyama University has one question if so for what kind of application we can use main function as a recursive function I have never seen the main function itself being a recursive function and therefore I cannot imagine any practical application of it usually the recursive function is always invoked from within the main program please remember that the main function is not something that you invoke it is the operating system which invokes a main function and therefore if operating system gets into a recursive spin there could be serious trouble so I do not see any reason why the main function itself could be a recursive function however I am not aware of any application as I said about the other question I will try to find this out and get back to you thank you so much we must really stop now