Lesson 1 Programming Methodologies: 1.1. An Introduction To Data Structure
Lesson 1 Programming Methodologies: 1.1. An Introduction To Data Structure
Programming methodologies deal with different methods of designing programs. This will teach you how to program efficiently. This book restricts itself to the basics of programming in C and C++, by assuming that you are familiar with the syntax of C and C++ and can write, debug and run programs in C and C++. Discussions in this chapter outline the importance of structuring the programs, not only the data pertaining to the solution of a problem but also the programs that operates on the data. Data is the basic entity or fact that is used in calculation or manipulation process. There are two types of data such as numerical and alphanumerical data. Integer and floating-point numbers are of numerical data type and strings are of alphanumeric data type. Data may be single or a set of values, and it is to be organized in a particular fashion. This organization or structuring of data will have profound impact on the efficiency of the program.
statements) Multiple entry points to a function/procedure/subroutine/method In this style of programming there is a great risk that implementation details of many data structures have to be shared between functions, and thus globally exposed. This in turn tempts other functions to use these implementation details; thereby creating unwanted dependencies between different parts of the program. The main disadvantage is that all decisions made from the start of the project depends directly or indirectly on the high-level specification of the application. It is a wellknown fact that this specification tends to change over a time. When that happens, there is a great risk that large parts of the application need to be rewritten.
1.13. ARRAYS
Arrays are most frequently used in programming. Mathematical problems like matrix, algebra and etc can be easily handled by arrays. An array is a collection of homogeneous data elements described by a single name. Each element of an array is referenced by a subscripted variable or value, called subscript or index enclosed in parenthesis. If an element of an array is referenced by single subscript, then the array is known as one
dimensional array or linear array and if two subscripts are required to reference an element, the array is known as two dimensional array and so on. Analogously the arrays whose elements are referenced by two or more subscripts are called multi dimensional arrays. 1.13.1. ONE DIMENSIONAL ARRAY One-dimensional array (or linear array) is a set of n finite numbers of homogenous data elements such as : 1. The elements of the array are referenced respectively by an index set consisting of n consecutive numbers. 2. The elements of the array are stored respectively in successive memory locations. n number of elements is called the length or size of an array. The elements of an array A may be denoted in C as A[0], A[1], A[2], ...... A[n 1]. The number n in A[n] is called a subscript or an index and A[n] is called a subscripted variable. If n is 10, then the array elements A[0], A[1]......A[9] are stored in sequential memory locations as follows : A[0] A[1] A[2] ...... A[9] In C, array can always be read or written through loop. To read a one-dimensional array, it requires one loop for reading and writing the array, for example: For reading an array of n elements for (i = 0; i < n; i ++) scanf (%d,&a[i]); For writing an array for (i = 0; i < n; i ++) printf (%d, &a[i]);
1.14. VECTORS
A vector is a one-dimensional ordered collection of numbers. Normally, a number of contiguous memory locations are sequentially allocated to the vector. A vector size is fixed and, therefore, requires a fixed number of memory locations. A vector can be a column vector which represents a n by 1 ordered collections, or a row vector which represents a 1 by n ordered collections.
1.15. LISTS
As we have discussed, an array is an ordered set, which consist of a fixed number of elements. No deletion or insertion operations are performed on arrays. Another main disadvantage is its fixed length; we cannot add elements to the array. Lists overcome all the above limitations. A list is an ordered set consisting of a varying number of elements to which insertion and deletion can be made. A list represented by displaying the relationship between the adjacent elements is said to be a linear list. Any other list is said to be non linear. List can be implemented by using pointers.