 Good morning everybody and sorry for the small delay. Today I will first answer some queries which were raised earlier and in the process we will have a couple of quizzes. So I hope you are ready with your clickers and I hope to get larger number of responses reaching us through the XML files which are FTP here. It was suggested yesterday that I should discuss image processing or fingerprint processing a bit more detail. So what I have done is an earlier C++ program which was used to convert grayscale fingerprints into monotone images. Me and my colleagues have sort of rewritten that in C last night and since that program is fairly long and it incorporates features many of which are important and relevant such as dynamic memory allocation, handling pointers, input output. So I thought I will discuss that particular program at length as a composite example of several features of C programming language. But first some queries from participants will briefly look at dynamic memory allocation and recursion and then as I said we will look at the image processing problem in some greater details. After the tea break we may continue part of this discussion if it is not complete otherwise we will discuss the workshop projects and the activities to be completed. The query is rather simple. I have received an email. I do not know whether the figure that I mentioned here is exact or not but effectively the question was when people say 2.3 gigahertz clock speed or some such thing what exactly does it mean. It is an important question and I am glad someone raised it although it is not concerned directly with programming. It is concerned with execution speed of our programs and therefore we shall have to look at what implication does a clock rate have. To understand this better we will have to go through some details of computer organization the internal actions that take place inside the digital computer. So first we look at the processor technology. The traditional view of a computer organization and this is by the way still taught even in CS programs at many places where we say that we have a central processing unit comprising of a control unit and arithmetic and logic unit. Control unit has the responsibility of understanding our instructions and use electronic circuits to execute those instructions. Arithmetic and logic unit has the capability to carry out numerical manipulations or compare values and so on. These two together intensically work in order to execute our programs. If you look at an instruction and as I had commented earlier typically machine language instructions which are coded in binary form will permit various actions such as add, subtract, multiply, load from memory into registers, load from registers into memory and so on. These instructions themselves are stored in the memory as we all know because computer is a stored program machine. So these instructions if they are to be executed take any instruction which needs to be executed it needs to be fetched from memory and then it needs to be understood by the control unit for example whether the instruction means add instruction means subtract since control unit is not a human being this understanding or what we call decoding is also done using electronic circuits and once the instruction is decoded it is then executed. If addition is to be performed some data will have to be fetched from memory brought on to the register values to be added and the result has to be pushed back on to memory. Each of these actions though they happen at electronic speeds they happen at discrete non-zero intervals and somebody needs to synchronize all these activities of fetching, decoding and execution of the instructions. Now this responsibility of synchronizing these actions things have to run like a clock work and in fact precisely for that reason a clock is provided within a computer as we know the processor as registers which are like fast memory locations data is read from memory process and written back as per the instructions. So as I said a clock synchronizes actions such as fetch, decode, execute what have. Now the speed of the clock how many cycles per second the clock runs because for every cycle of the clock some action will happen some bits will move from one point to another at the next cycle some other decoding circuitry will work etc. Consequently the execution of instruction inside a digital computer is intrinsically linked to the clock and obviously the faster the clock the faster will be the execution of instructions. Now these clock speeds these are by the way crystal driven clocks these clock speeds typically range from 300 megahertz to several gigahertz 2.3 or 2.1 or 3.2 gigahertz. These are typical clock frequencies available in modern computers that we see including high end PCs and digital purpose servers that you see. This speed by the way has improved from kilohertz upwards a kilohertz means 1000 cycles per second. So consequently in one second the clock is capable of driving 1000 times different circuits. Execution of a single instruction ordinarily does not happen within one cycle it may take several cycles in fact different instructions will require different clock cycles. But what is definitely true is that since the actions need one or more clock cycles in general faster the clock faster will be the execution of instructions. The overall speed will also depend upon the architecture of the processor. While that is not the subject of study here but for the purpose of better understanding of happenings let me mention a specific architecture called risk architecture which stands for reduced instruction set computer. Typically instructions are very complex in modern machines but risk processors were introduced so that the instructions individually were extremely simple and therefore they could be executed very rapidly. In fact typically the risk instructions require far fewer clock cycles to execute than their corresponding instructions in other machines. In addition modern computers have an architecture called pipeline architecture. Let me explain to you what the meaning of pipeline is. Imagine let me I think use this small paper to make my point. Suppose there is a lake here and there is a water tank and one person is capable of taking water out of this lake and putting one bucket full of water in let us say two minutes time. Imagine that there is a certain cart or a truck or something like that which can take this water and take it further to a depot let us say this is the depot or water reservoir and it takes three minutes. And imagine now that to supply water from this reservoir to let us say our home one of our family members will go here with a bucket and will take this bucket from this reservoir to home and that may take let us say another three minutes. If you consider one minute to be one clock cycle then typically a bucket is filled in two minutes that is two clock cycles. The truck is loaded and truck brings the water to this particular point in three minutes that is three clock cycles and I go and fetch a bucket of water from here another three minutes three clock cycles. So therefore the instruction to get one bucket of water from here to here will take two minutes plus three minutes plus three minutes a total of eight minutes roughly eight cycles to execute this instruction. However suppose I create a pipeline architecture that means imagine that this fellow is constantly filling up buckets one after another the truck is perpetually moving to and fro and it travels backwards in zero time and there is not just me but my wife my children my neighbours everybody is lined up here to keep carrying buckets. Now if you look at the water flow that will happen at the end of this pipeline so you can imagine that there is a pipe between here and here there is a pipe between here and here and there is a pipe between this point and this point as well. In short we are talking about a pipeline. The characteristic of any such pipeline is that if everybody is continuously working then while the first bucket that is poured inside may take two plus three plus three minutes to come out but while the water is moving in this part this person is adding more buckets. While the water is being taken out from this part the truck is moving more water. Consequently once the pipeline fills up the water will continue to come out of this pipe every two minutes because two minutes is the time when this fellow takes to fill up one bucket of the water. In exactly the same fashion in a pipeline architecture when one instruction is fetched by the computer and it is sent to decoding in the decode circuit the fetching circuit fetches the next instruction. When the first instruction goes for execution the second instruction which has been decoded which has been fetched goes to the decoding and the fetching circuit goes to get another instruction and this is very very crudely and simplistically is the pipeline architecture. Suffice it to say in the context of our discussion of the speed is that a pipeline processor will be capable of executing one instruction per cycle. That means if the speed of the clock is two gigahertz and it is a risk pipeline architecture it is capable of executing two billion instructions per second. Of course these are simplistic instructions it does not mean that even modern computer can add two floating point numbers of high precision of a billion times in a second. But effectively these speeds have improved significantly. So in a nutshell then the notion of a clock is clock synchronizes fetching decoding and execution of machine instructions faster the clock faster will be the speed or performance of the computer roughly it will mean that our programs will run faster and that these speeds have improved from kilohertz first to megahertz and now to gigahertz. It is in this context that I thought I will run a quiz on historical development of computers. So sharpen your clickers this quiz number is one three for all our remote center coordinators please remember to insert one three in the quiz number let people look at this quiz I will read it out it says when where did the first stored program execute on a digital computer you have four choices the first choice says 1950 United States of America the second choice says 1948 England the third choice says 1949 Germany and the fourth choice is none of the above of course those of you who know the answer the question is very simple those who don't know will have to guess and you will have to think about the development that was happening around that time and estimate roughly where the first stored program would have executed please remember we are not talking about the first computers there were mechanical computers and there were even electronic computers but those computers were programmed or instructions were given using something like punch cards or paper tapes the instructions could not be stored till the first stored program computer actually was made and a program was run on that computer so you have to guess where the first program executed first let me freeze now this particular quiz please collect the responses Manjul can you collect the responses here okay so I presume that you would have collected responses so let us see what do our colleagues feel about these historical events yeah responses are still being collected some responses have come up Nathpur, Nirmah, NIT, Surat Kal, Vijay Tiai, Amrita Institute, Annay University, Chennai and Salem can you refresh this list there is not much change I guess so people might have resisted from answering queries because they are not sure of this however I would have expected ticks on more centers because this means that some centers are unable to send the XML file uploading the file quiz number again please the quiz number is one three or thirteen quiz number is one three okay we will wait we will continue our discussion and we will collect these responses once again but the next slide is again a quiz so while we wait for the responses to be collected let me answer some other queries that were raised just now one query was related to what you call bisection method root finding by bisection method unfortunately I don't have the slides easily available here after the tree back I will try to see if I can get the slides and if I can I will try to briefly go over that process once again meanwhile we have tried to refresh the list for quiz number thirteen one three the last refresh we do okay so let us see can you view the responses please there are large number of timeouts I still don't understand the purpose of meaning of this timeout but nevertheless yeah please so a b c and d and there are large number of c's some a's some b's and no d let us look at the right answer the current answer actually is b the first stored program machine called Manchester Mark one executed program on 21st June nineteen forty eight in Manchester England most people credit the invention of stored program computers to United States as a physical geography but it is useful to note that the research in computing was happening in England elsewhere in Europe as in Germany and of course in United States and the British group actually won the race by executing the first stored program this is the second quiz in those days on that this is quiz number fourteen by the way quiz number one four so I request you to remember quiz number one four coordinators please note and let us have maximum number of responses so please don't press your buttons in a hurry till the procedure is followed there and after that you press it even if you press it once you can press it again there is no problem there we would like to see maximum number of responses coming up okay the request was please give the start signal clearly since it is not a timed quiz please do not worry but I am formally announcing start of the quiz but we will wait as long as it takes once you start it will wait for two minutes I think within two minutes you have to respond so what they are saying is when the coordinator collects the responses that will be the stop time but we are starting the quiz let's go back to this slide please so please understand this query with this quiz correctly quiz number fourteen or one four it has the memory used to store bits in the first computer was made using those who are familiar with engineering may find this question simple the memory used a transistors be integrated circuits see cathode rate you and the triode and pen tall walls so you have to choose one of these four because there is no none of the above option here so obviously the correct answer is within these four so I presume that I will wait for exactly 30 more seconds after which at each remote center the remote center coordinator should just look around and if everybody has pushed the buttons should collect the responses so we will go over I request the coordinators to collect the responses can you collect the responses now okay we got many more responses now from multiple centers surprisingly we don't have response from Coimbatore well old and even Tanjavur what has happened I thought Tanjavur clickers were working perhaps some problem in sending FTP file I do not know anyway as I mentioned if the coordinators have collected responses we have a mechanism for you to send these responses by email separately and we could incorporate but let us look at the responses please I still don't understand the notion of time out why should there be so many time out we will have to debug this anyway we will do it next time can we have the bar chart now this bar chart says large number of answers are D about 32 people feel that it is D half of them about 16 feel that it is C and 8 people feel it is A and about 6 people feel that it is B it is interesting that we do not have responses from about 171 people because of the time out but you can perhaps discuss amongst yourselves to find out what your impressions are but let me go ahead and tell you the fact the fact is actually more interesting than what we might imagine the first computer use neither transistors because they did not exist nor integrated circuits because they most certainly did not exist then try and print all walls which has been the guess of largest number of people did exist in fact some memories were made using pen plots and triads and some circuits were made however the memory used in the first computer comprised of a cathode ray tube you will be surprised that cathode ray tube can be used to store bits in fact use of cathode ray tubes for storing bits was already happening there and that particular technique was developed further by Sir Williams at Manchester University and the tubes were known they were patented by Sir Williams this is a brief about the first program as I said it executed on 21st June 1948 and it found the prime factors of a large number Sir Frederick Williams and Tom Kilburn had invented and perfected a memory to store bits efficiently and they proceeded to build the store program computer build around this memory the memory had 32 words its arithmetic and logic unit could only subtract numbers it could not add it certainly could not multiply or divide so how would it find the factors of a number where factorization involves division and what this computer did very simply is that instructions were given to repeatedly subtract a number which amounts to division so that is how division was carried out it could execute one instruction every 1.2 milliseconds considering that there are about 1000 milliseconds in a second and even if you assume it executed one instruction in 1 millisecond it could execute a huge number of 1000 instructions in a second these speeds appear laughable now but those were the times when mechanical calculators and mechanical computers or computers using electron electrical relays and so on where available in large numbers and with respect to those with respect to human intervention required to give one instruction at a time to those calculators this speed was considered very very fast so this is some interesting history let us continue this discussion and look at how the memory was constructed using cathode a tube it was patented by William and it was therefore called Williams tube what they did is on the cathode ray they could display as you know lines could be displayed on a CRT terminal today you see high end graphics and whatever we are talking old days when cathode ray would usually be used cathode ray tube would usually be used to display signals in wave forms from circuits however they use a dot to represent a 0 and a dash or a larger line to represent one human beings can see these dots and dashes clearly but how does a computer sense whether something is not or something is dash well this was done through special metal plates kept on the surface of the CRT which could detect the charge and therefore determine that at the particular location the metal plate whether the contents were 0 or they were 1 namely whether there was a dot or there was a dash walls could also be deployed by the way to build memory later on these were but they were too costly much later magnetic cores were used by pushing small wires through the magnetic cores the direction of magnetization would decide whether a 0 was reprinted or 1 was reprinted in my own institute in the early years when we had a Russian computer which was roughly built around the IBM 360 kind of system it had magnetic core memory the advantage of magnetic cores was that once you magnetize a core it remains magnetized so consequently once you store a number in magnetic memory it does not get lost unlike the electronic memory which is volatile incidentally I have included here a website http inventors.about.com again if you just say Manchester mark 1 or mark 1 first computer or first program you will automatically get a whole lot of answers which will include these details although not covered in the core syllabus I would submit to my colleague teachers that it would be useful to once in a while share the developmental history of such exciting technology our students will definitely find it interesting and some of them who are actually interested in details and integrities would actually go around and determine in far greater details what was happening around the time when this exciting technology was evolving that would definitely lead to a very useful thinking you know contemplation on part of our students this is a photograph of the memory which was used called the Williams tube you can see that these long lines you see here are dashes and the dots that you see in between so these lines represent a word and there were 32 bits in one word and there were 32 words like this and multiple tubes could be cascaded to provide for additional memory of course the whole exercise was very costly as compared to what we see today so much for the historical significance in today's world there are multiple chips 256 kilo bit chips 1 MB chip 2 MB chip 4 MB chip 8 MB chip notice that I write small b small b stands for bit and capital B stands for byte you might wonder that when the memory is byte addressable why am I speaking of bits the actual fact is that the memory packaging in chips occurs in number of bits multiple chips are put together either in the same integrated circuit or next to each other and that is how bytes are formed traditionally computers were organized around words and you had a 4 byte word a 8 byte word sometimes even 2 byte words or smaller machines nowadays as I mentioned all machines are byte addressable and the address can be 8 bits 16 bit 32 bit or 64 bit defining the capability of the machine to address memory typical memory speeds today are 30 to 50 nanoseconds what it means is that if a processor demands some value to be loaded from memory into its register it can be done in 30 to 50 nanoseconds the registers themselves which are like fast locations and an intermediate storage very fast storage which is provided on every processor these days called the cash store can operate at about 10 nanoseconds sorry for the interruption S.V. N. I. T. Suraj says that we are able to collect responses from participants but are not able to send the file to your side it doesn't matter you can try to send it by an attachment as an attachment to email and we will collect it and incorporate it here so please do not worry too much on that however later during the lunch break and during the lunch break please call up our support people and try to figure out why exactly while the file is getting created there why is it not coming perhaps some proxy setting or something will have to be checked anyway the memory the digital computer memory these days is volatile there also exists other type of memory such as read only memory which is a small component where something like a boot record of an operating system could be loaded so that even if rest of the memory loses its contents when you switch on the computer the basic program is available basic input output program is available which can then read from desk and so on and execute it you can also have programmable read only memories or erasable programmable read only memories these are often used in embedded systems as I have mentioned once we turn our attention once again to programming in C programming language we first discuss a very useful concept of type casting in C as you know all variables have specific types integer float double care whatever you have there are occasions however when we wish to force conversion of one data type into another to get correct results imagine this is a program code which is compiled and executed what does this code say int m equal to 6 int implied n equal to 8 and float r so there are two integer variables m and n having values 6 and 8 respectively and what computation we are doing is r is equal to m by n all of you recall the rules of executing sort of arithmetic operations or the expression evaluation this is the expression on the right hand side both m and n are integers since m is 6 and n is 8 the resulting integer will be simply 0 consequently you get a wrong answer this would not have happened had one of them been a floating point number observe that left hand side r is declared as floating point number but what left hand size type is does not dictate how the expression on the right hand side will be evaluated this expression is evaluated as per its own rules consequently if we wanted the correct result we obtained we must force at least one of these operas to a floating point type because we know that if one floating point operand operates with another fixed point or integer operand the integer one is converted into floating point and then the calculations are carried up but if both are integer we can do nothing that is the reason why c permits us to write something like this in parenthesis just before m we write float what this float means is that I am forcing that type of m to be temporarily cast as float we know m is integer but for participation in this expression m's value will be internally converted to floating point and the floating point value will participate in expression evaluation since the expression now is divided by n one of them is floating point one of them is fixed point n will automatically be converted by the compiler into floating point and a proper floating point operation will take place giving you a value let us say 0.75 the values are as indicated now this operation is called type casting there is one example which illustrates how type casting could be useful in ensuring correct numerical results however the greater use of type casting is in terms of describing pointers as you know pointers are merely addresses which point to some locations the first of a set of locations for you say pointer could point to an array pointer could point to a structure it could point to a float floating point value it could also point to an integer value since pointers are fixed length it is possible to recast the pointers so pointer may point to a particular data value but if we recast the pointer then the pointer behaves as if it is not let us say an integer pointer but it is a character pointer a floating point pointer and so on it is important to understand that this memory allocation we call it dynamic because it is not done at the time the compiler compiles your program ordinarily all memory allocation in your program is done by the compiler so when you get an executable file and execute that program well memory is already allocated every variable know where to set how it is addressed and so on now there are occasions when we may not know in advance the exact storage requirement of the algorithm so consider an array whose size must be declared with fixed value in our program suppose I am storing information about employees say if I have 1000 employees I will declare an array of 1000 1200 or 1500 elements to accommodate them but if we actually have less employees than that some of the storage will go west on the other hand if we get even one extra employee then the maximum size of the array that we have declared in our programs well the information about that employee cannot be manipulated at all it is in such situations you might want to think about using what we call dynamic memory allocation here is a small example first we note that the C programming language permits us to allocate memory to specified blocks of data so these block could be as small as 1 byte it could be 10 kilobytes 100 kilobytes 2 megabytes well the programmer this memory can decide how much memory he needs and that much memory will be allocated by the operating system while your program is running so this extra memory or a block of memory to be associated with your structures can be dynamically made available generally the call used to allocate memory to your array or structure or whatever is through a statement called malloc or malloc or memory allocate so it is it is proposed malloc but memory allocate means please allocate so much memory to me now when we ask the computer to allocate memory to us either we should tell it whether we are going to put an array of let's say 500 elements in that block or 500 different variables of type integer what we want to do we have to somehow communicate it to the C compiler so that subsequent operations happen correctly the mechanism to communicate that is again type casting so memory function the malloc function merely returns a pointer and that pointer is pointing to the memory block which is given by the operating system and you can actually cast that pointer in any of the types that you want so that when you access the particular chunk of memory locations that have been given to you you can make best use of them in terms of whatever you require here is another example I have a digital image it has certain height let us say h and width w it could be measured in terms of pixels inches what are we traditionally measure it in terms of pixels so let's say I have a 300 height picture and a 200 wide picture so 300 into 200 is the total size of the image tomorrow I may want to run the same program which looks at this image and say that look I want to handle much larger images or somebody else might want to handle simply small photographs and therefore the size is small but whether small or big such a variable size cannot be provided for in our program or program variables are initialized either by us is writing program or we need values from so consequently the if I have to allocate memory to large image I do not know exactly what is the size of the image in such a situation what I could do is something shown here image is a pointer because MLR gives you a pointer it says image is equal to unsigned care star malloc size of care h into w looks complicated but simple to understand h is the height w is the width so height into width is the total number of pixels in the image if we imagine that each pixel represents 0 to 255 or that is the normal single byte value then h into w also denotes the total number of bytes of storage that you will require to store this image this particular value h into w which would be an integer number ordinarily is type cast using care because care is almost intrinsically same as integer which is what an individual character byte would be you do not know how many bytes in size this would be that would depend upon how float is to how numbers are stored and so on but when you say malloc size of this compute is capable of determining the size and based on whether it is 500 by 500 that is 25000 elements or 10,000 elements or merely 20 elements a memory location block will be given to you and you can manipulate contents of that block almost imagining as if you are handling a predetermined size of the array so for example once I read my picture element values into such a one dimensional array equivalent I can access the array and process the data by saying let us say image boss greater than threshold if so then image boss is set to 255 as we shall see in the later example this is roughly equivalent of saying that I am stretching my histogram and if I am converting a grayscale image into a binary image 0 1 image then obviously I define a threshold picture values or pixel values or what we call color tone values greater than that particular average they will simply be set to 255 other pixels will be set to 0 this is one operation that we do in converting grayscale images into monotone images as I mentioned we shall be looking at a program shortly in a nutshell then dynamic allocation of memory is often resulted to when we are not completely sure of the exact storage requirement and more particularly when such storage requirement is very large please remember that dynamic allocation of memory is rarely done for allocating 1 byte, 2 byte or variables or so on those better be declared properly and fully only for unknown entities you would like to do that and maximum number of times the dynamic allocation will be to sort of read large amount of data and put it in proper storage and that is what is permitted here by this dynamic allocation before taking the break I will also try to briefly discuss recursion, a function which can call itself again all of you know recursion but how do you tell our students about the nature of recursion and recursive call perhaps the best example is the Fibonacci series we have already seen in this workshop an implementation to solve Fibonacci series that is to get its nth term or something through an iterative program we have written that small iterative program here is an example of using recursion so this is the function that I have written integer Fibonacci integer n it tests if n is 0 it returns 0 if n is 1 it returns 1 but if it n is 2, 3, 4, 5, 6 whatever it calls itself to determine that value and how do you call it if n is neither 0 or 1 it will put the actual whatever parameter to this call and now the computer will take the value of n which is neither 0 nor 1 and called Fibonacci itself to generate a return value so for example if n is equal to 2 this return statement will be executed with n equal to 2 which means Fibonacci n minus 1 will be 1 and Fibonacci n minus 2 will be 0 and this function will be invoked again what will it return well now it has actually started executing sort of two streams parallel one which is executed with value n minus 1 and the other which is executed with value n minus 2 if n is large then you can immediately see that in the first cycle of recursion the Fibonacci n minus 1 and n minus 2 are being sent again for revaluation but in the second cycle Fibonacci n minus 1 will be evaluated as Fibonacci n minus 2 plus n minus 3 Fibonacci n minus 2 will be evaluated as Fibonacci 3 plus Fibonacci n plus 4 and this could go on in terms of elegance you have an extremely elegant solution because your main program can be simply written like this so I define integer number floating point f and I say print f sorry integer number and f and I print give a number you have read that number and I simply assign to f the value of that number sent as a parameter to Fibonacci so depending upon the value of num appropriate Fibonacci value will be calculated which will be returned to this variable f I would also like to caution all of you recursion is very pretty and in fact it is considered an intellectual maturity to understand and use recursion however I would like to warn you that except for very small and almost trivial cases recursion could trigger huge amount of execution time and more complexity seemingly you are only adding numbers and addition of numbers if you are adding n numbers it should take order and time but in recursion or in such kind of cases the numbers when they become large they cannot be represented individually on the machine using native capabilities I had mentioned multi pristine arithmetic because the positive of time will not be discussing that but I will try and send a sample program by uploading it on the model so that you can just look at what exactly is involved when I have to add or multiply 200 digit numbers something which we ordinarily do not do there is a query from Anna University whether it is for Fibonacci series is it better to use iteration or recursion function it is a good question and there is no unique answer sadly very as a thumb rule you can imagine the following if the number of recursive levels required are not very many then recursion does present an elegant solution however if value if the number of times that you have to do recurrence that means repeatedly call the same function is more then the complexity of that recursion increases exponentially consider this for a given number just to find the recursive solution you get two numbers or two branches each of which has to find Fibonacci using the same rule so each one becomes two more consequently you grow exponentially in terms of branches so you are trying to find out let us say recursively the value of thousand element of Fibonacci series well that may not exactly be a good idea recursion is often used to implement some esoteric data structures in applications and certainly many things in system software but to conclusively answer your question normally it is a matter of style when n is small using recursion has no problems the use of recursion should be done when it is important that people who read your program understand what you are doing and therefore are able to appreciate recursion in terms of plane efficiency iteration of course in the long run is far more efficient than recursion so you have elegance on one hand you have efficiency on the other hand and one is not at the cost of the other ordinarily we would like to have both so frankly it remains your choice as to what you wish to do we will reassemble at 837 sorry 1037 here