Page 10 - DCAP407_DATA_STRUCTURE
P. 10

Unit 1:  Introduction to Data Structures




                                  Instructions for assembling a puzzle can be an example of an algorithm. If you
                                  are given a preliminary set of marked pieces, you can follow the instructions
                                  given to complete the puzzle.
               According to Levitin, algorithms can be defined as,  “A  sequence of unambiguous instructions for
               solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of
               time.”
               Most computer programs involve an algorithm and one or more data structures. An appropriate data
               structure needs to be selected for an algorithm as the efficiency of the algorithm depends on the data
               structure chosen. By increasing the data storage space, you may not be able to reduce the time needed
               for processing the data and vice versa.


                                  When we want to print a mailing list  alphabetically we  need to use a data
                                  structure and an algorithm. We first arrange all the names in a data structure
                                  (array) and then sort the names alphabetically using an algorithm (sorting).
               1.1.2   The Concept of Data Type
               A data type comprises a set of data with values and consists of predefined set of characteristics. To be
               specific, data is usually stored in a variable, where the value of the variable changes according to the
               program being executed. The four commonly used data types in C language include int (integer), float
               (real  number), char (character) and pointer. The keywords int, float, char  and so on  always take
               lowercase letters. Generally, a data type includes constants and variables. A constant is considered as an
               entity that does not change in any given program. A variable is an entity that may change from one
               program to another. It is necessary to specify the variables that will be used in a program. Therefore,
               type declaration is made by giving the data type and then the variable names. The syntax for declaring
               the data type and the variable name is as given below:
               Syntax:

               <(data type)><variable names>;

                              int x;
                              Where, int is a data type and x is a variable
               Integer Data Type
               An integer data type includes only whole numbers. It does not contain any fractional data. It is denoted
               by the keyword  int. It occupies 2 bytes of memory space. Integer data type can either be signed or
               unsigned. The  signed type integer takes both positive and negative values. The range of integer
               constant is from -32768 to +32767 (-2^15 to +2^15 - 1) for a 16-bit compiler and -128 to 127 (-2^7 to +2^7
               - 1) for an 8-bit complier. A 16-bit compiler uses one bit for storing sign and the remaining 15-bits for
               storing numbers. An 8-bit complier uses one bit for storing sign and the remaining 7-bits for storing
               numbers. The unsigned integer ranges from 0 to 65535. The signed and unsigned integers are specified
               as follows:
               Syntax:
               Unsigned int value;
               Signed int value;
               The integer data type is denoted by placeholder format string % d, which indicates that the data being
               used is of integer values.

                               int x;
                               scanf (“%d”, &x);







                                        LOVELY PROFESSIONAL UNIVERSITY                           3
   5   6   7   8   9   10   11   12   13   14   15