Académique Documents
Professionnel Documents
Culture Documents
Objective:
Outcome:
In this Chapter the student will come to know how Computer Works.
In this Chapter the student will come to know what are the various Hardware and Software
components of computers and there functionality.
In this Chapter the student will learn different types of programming languages like(Machine
level language, High level language, Middle level language).
In this Chapter the student will learn the internal process of the program execution
like(Linker,Loader,Complier)
In this Chapter the student will learn the software development methodology
Syllabus:-
Points:
a) Hardware
b) Software
c) Both Hardware and Software
d) none
1. C is ______Language .
True or False:
5. OS is a programming Language?
Answers:
1) False 2) True 3) False 4)True 5) False 6)True 7) True 8) False 9) True 10) False
4) EPROM d) Bus
Matching answers:
1. Design a Flow chat to find whether a given number is prime or not and also find it is even or
odd?
2 Design and develop the solution for finding the roots of quadratic equation by using algorithm
and flow chart
3. Design and develop the solution for finding the area of circle?
4. Design and develop the solution for determining whether there is profit or loss during the
selling of an item
5. Develop Pseudo code to determine whether the given year is leap year or not
Tutorial Problems
1. What are the some input devices? Briefly explain some popular input devices.
2. What is a flow? Chart? How it is different from algorithm and pseudo code?
6. Design an Algorithm to simulate multiplication by addition. The program should accept as input
two integers (they may be zero, positive, or negative)
3. Write an Algorithm to find out all the factors of given positive integer.
4. What is Flowchart? Draw a flow chart to read ten integers and print the sum of squares of all
ten values.
5. Draw a flowchart to Read ten positive integers and how many are multiples of 7.
UNIT II
Objective:
Concepts of Operators.
Process of statements
Outcome:
The students will get the complete information about operators, expressions,
statements. And control statements
Syllabus:
1. C is a Structured programming language which born at “AT & T’s Bell Laboratories” of
USA in 1972. It was written by Dennis Ritchie.
2. This language was created for a specific purpose: to design the UNIX operating
system (which is used on many computers). From the beginning, C was intended to
be useful--to allow busy programmers to get things done.
3. Because C is such a powerful, dominant and supple language, its use quickly spread
beyond Bell Labs.
4. In the late 70’s C began to replace widespread well-known languages of that time like
PL/I, ALGOL etc.
6. This posed a serious problem for system developers. To solve this problem, the
American National Standards Institute (ANSI) formed a committee in 1983 to
establish a standard definition of C.
7. This committee approved a version of C in 1989 which is known as ANSI C. With few
exceptions, every modern C compiler has the ability to adhere to this standard. ANSI
C was then approved by the International Standards Organization (ISO) in 1990.
8. The C language is named because its predecessor was called BCPL (Basic computer
programming language). The BCPL language was developed by Ken Thompson of Bell
Labs.
9. The basic characteristics of C are:
o small in size
o loose typing (lots of freedom)
o structured (extensive use of functions)
o designed for systems programming (i.e., low level programming of the type
needed to implement an operating system)
o C is higher level than assembler but still close to the hardware and allows
direct manipulation of many system aspects: pointers, memory allocation,
bitwise manipulation ...
Simple C Pragramme:
1. Documentation Section:
The documentation section consists of a set of comment lines giving the name of
the program, the name and other details, which the programmer would like to use later.
2. Preprocessor Statements
The preprocessor statement begin with # symbol and are also called the preprocessor
directive. These statements instruct the compiler to include C preprocessors such as
header files and symbolic constants before compiling the C program. Some of the
preprocessor statements are listed below.
3. Global Declarations
The variables are declared before the main ( ) function as well as user
defined functions is called global variables. These global variables can be accessed by all
the user defined functions including main ( ) function.
4. The main ( ) function
Each and Every C program should contain only one main ( ). The C
program execution starts with main ( ) function. No C program is executed without the main
function. The main ( ) function should be written in small (lowercase) letters and it should not
be terminated by semicolon. Main ( ) executes user defined program statements, library
functions and user defined functions and all these statements should be enclosed within left
andrightbraces.
Braces({})
Every C program should have a pair of curly braces ({, }). The left braces indicates the
beginning of the main ( ) function and the right braces indicates the end of the main ( ) function.
These braces can also be used to indicate the user-defined functions beginning and ending.
These two braces can also be used in compound statements.
LocalDeclarations
The variable declaration is a part of C program and all the variables are used in main ( )
function should be declared in the local declaration section is called local variables. Not only
variables, we can also declare arrays, functions, pointers etc. These variables can also be
initialized with basic data types. For examples.
Code:
Main ( )
{
int sum = 0;
int x;
float y;
}
Here, the variable sum is declared as integer variable and it is initialized to zero. Other variables
declared as int and float and these variables inside any function are called local variables.
Program statements
These statements are building blocks of a program. They represent instructions to the
computer to perform a specific task (operations). An instruction may contain an input-output
statements, arithmetic statements, control statements, simple assignment statements and any
other statements and it also includes comments that are enclosed within /* and */ . The
comment statements are not compiled and executed and each executable statement should be
terminated with semicolon.
# include <stdio.h>
main()
{
printf ("welcome to sbit /n");
}
Identifiers:
Rules:
C 'data types' which are used to define a variable before its use. The definition of a
variable will assign storage for the variable and define the type of data that will be held in the
location.
char characters
short
long
signed
unsigned
The modifiers define the amount of storage allocated to the variable. The amount of
storage allocated is not cast in stone. ANSI has the following rules:
A variable is an identifier which is used to store the data or values in memory location
4. Variable names start with a letter or underscore (_), followed by any number of
letters, digits, or underscores.
5. Uppercase is different from lowercase, so the names sam, Sam, and SAM specify
three different variables.
Constants:
Constants are data values that cannot be changed during the execution of a
program
Numeric constants
o Integer constant
Decimal Constants(0-9)
o Real Constants
Floating point Constants- must contain a decimal point end with f Ex:
1.24f,5.67f,0.3f
Character Constants
Input/output:
A terminal keyboard and monitor can be associated to perform input and output
operations. A keyboard is a source for a text stream to read the dada; a monitor is a destination
for a text stream to print the data.
Output:
Input:
Keywords:
The following are the C language supported key words
Operators:
Expression:
Collection of operators and operands is an expression. Operators are symbols which take
one or more operands or expressions and perform arithmetic or logical computations.
Ex: a+b+c+d,(a+b)*(c/d)
Precedence and Associativity:
Precedence table:
Operator precedence is why the expression 5 + 3 * 2 is calculated as 5 + (3 * 2), giving
11, and not as (5 + 3) * 2, giving 16.
We say that the multiplication operator (*) has higher "precedence" or "priority" than the
addition operator (+), so the multiplication must be performed first.
Associativity table:
Operator Associativity is why the expression 8 - 3 - 2 is calculated as (8 - 3) - 2, giving 3,
and not as 8 - (3 - 2), giving 7.
We say that the subtraction operator (-) is "left associative", so the left subtraction must
be performed first. When we can't decide by operator precedence alone in which order to
calculate an expression, we must use associativity.
Since the operators + and - have the same precedence, and are left-associative, the
following expressions are all equivalent:
x+3-y+5
(x + 3) - y + 5
((x + 3) - y) + 5
((x + 3) - y + 5)
Since the operators =, += and -= have the same precedence, and are right-associative,
the following expressions are all equivalent:
x = y += z -= 4
x = y += (z -= 4)
x = (y += (z -= 4))
(x = y += (z -= 4))
Expression Evaluation:
Expression evaluation is done from left to right or right to left and based on operator
precedence.
Here precedence of ++ is higher than + - / * operators. And, precedence of * / is higher than + -
operators. So, the expression must be computed as:
g = f / 4 + f * 2 / ++f;
g = (f / 4) + ((f * 2) / ++f);
........1....5......2....4...3....
and the result must be:
g = 2.6
Type Conversion:
short int -> int -> unsigned int ->long int -> unsigned long int -> float -> double -> long double
Explicit Casting (given transformation) of data types has higher priority then automatic
transformation. General declaration of explicit (given) cast (cast operator):
Example:
a = (int) c;
b = (double) d + c;
C Statements:
Statement types :
1. Labeled-statement
a. go to statement
2. Expression-statement
3. Selection-statement
a. if statement
i. simple if statement
ii. if else statement
iii. else if ladder statement
b. switch statement
4. Iteration-statement
a. While loop statement
b. do while loop statement
c. for loop statement
5. Jump-statement
a. Break statement
b. Continue statement
6. Selection statements:
If Statement:
Syntax:
7. Switch statement:
Syntax:
switch( expression )
{
case constant-expression1:
statements1;
break;
case constant-expression2:
statements2;
break;
case constant-expression3:
statements3;
break;
default:
statement 4;
}
8. Break statement:
If a condition is matched in switch case then execution continues on into the next case
also if it is not explicitly specified that the execution should exit the switch statement. This is
achieved by using break keyword.
Syntax:
break;
9. Default Statement:
Syntax
default:
statements;
Loops provide a way to repeat statements and control how many times they are
repeated.
while loop
if the test condition is true: the statements get executed., the test condition is checked
again. If it is still true the statements get executed again. This cycle repeats until the test
condition evaluates to false.
syntax:
The do While statement is similar to the while statement except that its termination
condition is at the end. the body of the loop executes at least once, regardless of the condition.
Syntax:
do
{
Statements;
}while(expression);
for loop:
expression2 - Conditional expression, as long as this condition is true, loop will keep
executing.
Syatax
The continue statement provides an immediate jump to the loop control statement.
Syntax:
Continue;
go to statement:
The goto statement is a jump statement which jumps from one point to
another point within a function. The goto statement is marked by label statement. Label
statement can be used anywhere in the function.
Syntax;
A:
statements
if(condition)
goto A;
#include<stdio.h>
void main()
{
char letter =`Z`;
printf("\n%c",letter);
}
1) Z
2) 90
3) Error
4) Garbage Value
3. What is the output of the following code? [ ]
#include<stdio.h>
void main()
{
int s=0;
while(s++<10)
{
if(s<4 && s<9)
continue;
printf("\n%d\t",s);
}
}
1) 1 2 3 4 5 6 7 8 9
2) 1 2 3 10
3) 4 5 6 7 8 9 10
4) 4 5 6 7 8 9
4. Find output [ ]
#include <stdio.h>
void main()
{
int a; printf("%d",a^a);
}
1) 1
2) 0
3) Unexpected
4) Runtime Error
UNIT-III
Objective:
1. The student will be able to learn the importance of functions and structured
programming.
2. The student will be able to understand various types of types of pre-defined and user
defined functions.
3. The student will be able to understand the concept of arrays along with their types.
4. Applications of arrays, various types of storage classes and inter function
communication.
5. The student will be able to get capability of implementing programs in functions and
arrays.
Outcome:
1. After completion of this chapter the student will come to know the concepts of
structured programming.
2. The student will come to know types of functions and recursion concepts along with
programming.
3. The student will come to know the definition and types of arrays along with the
advantages of arrays.
4. The student will come to know the types of arrays and application of arrays.
Points:
1. In software development, functions play an important role since they allow dividing
of the program into subprograms.
2. Functions are vital to C programming; main is a specially recognized function in C.
3. Every program must have a main function to indicate where the program has to
begin its execution.
4. While it is possible to code any program utilizing only main function, it leads to a
number of problems.
5. If a program is divided into functional parts, then each part may be independently
coded and later combined into a single unit.
6. These independently coded programs are called subprograms that are much easier
to understand, debug and test. In C such subprograms are referred to as ‘functions’.
7. A Function is an independent, reusable module of statements, that specified by a
name. This module (sub program) can be called by its name to do a specific task.
8. We can call the function, for any number of times and from anywhere in the
program.
9. The purpose of a function is to receive zero or more pieces of data, operate on them,
and return at most one piece of data.
10. A Called Function receives control from a Calling Function. When the called function
completes its task, it returns control to the calling function. It may or may not return
a value to the caller.
11. The function main () is called by the operating system; main () calls other functions.
When main () is complete, control returns to the operating system.
12. Function prototypes: functions should be declared before they are used. ANSI
provides a new function declaration called the function prototype.
13. A function prototype tells the compiler the number and type of arguments that are
to be passed to function and the type of value that is to be returned by the function.
14.
P
reprocessor Directives
#define - Define a macro substitution
#undef - Undefines a macro
#ifdef - Test for a macro definition
#ifndef - Tests whether a macro is not defined
#include - Specifies the files to be included
#if - Test a compile-time condition
#else - Specifies alternatives when #if test fails
#elif - Provides alternative test facility
#endif - Specifies the end of #if
#pragma - Specifies certain instructions
#error - Stops compilation when an error occurs
# - String zing operator
## - Token-pasting operator
Answers: 1-a, 2-c, 3-d, 4-c, 5-c, 6-d, 7-b, 8-a, 9-a, 10-a, 11-d, 12- a, 13-d, 14- a, 15-c, 16-b, 17b.-
6. scope 7. Recursion 8. Return type 9. Prototype declaration 10. Auto 11. dynamic
True/False:
1. C functions can return only one value under their function name. [true]
2. A function in C should have at least one argument. [false]
3. A function can be defined and placed before the main (). [true]
4. A function can be defined within the main (). [false]
5. A user-defined function must be called once; otherwise a warning message will be
issued. [true]
6. Any name can be used as a function name [true]
7. Only a void type function can have void as its argument [false]
8. A function can call itself. [true]
9. A function without a return statement is illegal. [false]
10. The return type of a function is int by default. [false]
11. The type all elements in an array must be same. [true]
12. When an array is declared C automatically initializes its elements to zero. [false]
13. In C by default the first subscript is zero. [true]
14. An unsigned long int type can be used as a subscript in an array. [false]
15. Accessing an array outside its range is a compile time error. [true]
Assignment questions:
1. Write a function exchange to interchange the values of two variables. Say x and y.
illustrate the use of this function, in a calling function. Assume that x and y are defined
as global variables.
2. Write a function prime that returns 1 if its argument is a prime number and returns zero
otherwise.
3. Write function that will scan a character string passed as an argument and convert all
lowercase letters into their uppercase equivalents.
4. Write a function that will generate and print the first n Fibonacci numbers.
5. Write a function that demonstrates recursion.
UNIT-IV
Syllabus:
Objective:
Outcome:
1. After completion of this chapter the student will come to know the concepts of
pointers and strings.
2. The student will come to know the types of string handling functions along with
programming.
3. The student will come to know the pointers and multidimensional arrays.
4. The student will come to know the concept of dynamic memory allocation and their
types.
Points:
1. Pointers provide a powerful and flexible method of manipulating data in the
programs.
2. The advantages of pointers are
1. Things can be done better with pointers than without.
2. Things that can be done only with pointers.
3. C provides the power and flexibility in dealing with pointers which serve to set apart
from other programming languages.
4. Pointer is a variable which stores the address of another variable.
4901 4902 4903 4904 4905
25
alpha
aptr=α fig: aptr contains the address of variable alpha (aptr is a pointer to
alpha)
6. Pointer is a variable which stores the address of another variable. Pointers are much
used in C.
7. A pointer declaration takes the following form:
1. <data-type> *<pointer-name>;
Where data type is any valid data type and indicates the type of variable that
points to. The * (asterisk) is the indirection operatoe and it indicates that pointer-name is a
pointer variable to type data-type.
20.
UNIT-V
Syllabus:
Objective:
The student will be able to learn basic Derived types and the use of each derived
type and how to create the structures, unions and specify the different formats to
the structures and union.
Students can learn different types of accessing structure variables, they can create
own data types using typedef.
Students can create their own applications using structures and unions
Process of structures
Outcome:
In this unit students will gain the basics of structures and union creations, accessing
the variables and usage of structure using other c concepts like arrays, pointers and
functions.
The students will get the complete information about typedef, bit fields.
Points:
21. STRUCTURE: A structure is a collection of variables under a single name. These variables can be
of different types, and each has a name which is used to select it from the structure.
22. A structure is a convenient way of grouping several pieces of related information together.
struct mystruct
{
int numb;
char ch;
}
23. Structure has name mystruct and it contains two variables: an integer named numb and a
character named ch.
struct mystruct s1;
24. Accessing Member Variables
s1.numb=12;
s1.ch=’b’;
printf(“\ns1.numb=%d”,s1.numb);
printf(“\ns1.ch=%c”,s1.ch);
25. typedef can also be used with structures. The following creates a new type sb which is of type
struct chk and can be initialised as usual:
typedef struct chk
{
char name[50];
int magazinesize;
float calibre;
} sb;
ab arnies={"adam",30,7};
26. Unions:
A union is an object that can hold any one of a set of named members. The members of the
named set can be of any data type. Members are overlaid in storage.
27. The storage allocated for a union is the storage required for the largest member of the union,
plus any padding required for the union to end at a natural boundary of its strictest member.
union {
char n;
int age;
float weight;
} people;
people.n='g';
people.age=26;
people.weight=64;
28. PROCESSING A STRUCTURE:
The members of a structure are usually processed individually, as separate entities.
Therefore, we must be able to access the individual structure members. A structure member
can be accessed by writing variable.member name.This period (.) is an operator, it is a member
of the highest precedencegroup, and its associativity is left-to-right.
29. USER-DEFINED DATA TYPES (Typedef): The typedef feature allows users to define new data
types that are equivalent to existing data types. Once a user-defined data type has been
established, then new variables, arrays, structure and so on, can be declared in terms of this
new data type. In general terms, a new data type is defined as
typedef type new type;
30. STRUCTURES AND POINTERS: The beginning address of a structure can be accessed in the
same manner as any other address, through the use of the address (&) operator. Thus, if
variable represents a structure type variable, then & variable represents the starting address of
that variable. We can declare a pointer variable for a structure by writing
type *ptr;
31. PASSING STRUCTURES TO A FUNCTION: There are several different ways to pass structure–
type information to or from a function. Structure member can be transferred individually, or
entire structure can be transferred.
32. The individual structures members can be passed to a function as arguments in the function
call; and a single structure member can be returned via the return statement. To do so, each
structure member is treated the same way as ordinary, single- valued variables.
33. UNIONS:
Union, like structures, contain members whose individual data types may differ from one
another. However, the members that compose a union all share the same storage area within
the computer’s memory.
Whereas each member within a structure is assigned its own unique storage area. Thus, unions
are used to conserve memory. In general terms, the composition of a union may be defined as
union tag{
member1;
member 2;
---
member m
};
3. #include<stdio.h> [ ]
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}
A. 3, 2, 515 B. 515, 2, 3 C. 3, 2, 5 D. 515, 515, 4
Ans : A
Int a;
Char ch[10];
Float f;
}s;
Ans. C
Ans. D
ans. A
Ans. A
Ans. b
c. a and b
d. none
Ans. B
11. Is it necessary that the size of all elements in a union should be same? (False)
Assignment questions.
1. What is the main reason for using structure?
2. What special keyword is used in defining a structure?
3. Define structure tag and what is its purpose?
4. In what two ways can a structure variable be declared?
5. What rules govern the use of the period (.) operator?
6. What is meant by an array of structure?
7. What characteristic must a structure have in order to be initialized Within its declaration?
8. What is the meaning of the arrow operator?
UNIT-VI
Unit-VI
Objective:
Outcome:
In this unit students will gain good knowledge on file handling techniques on text and
binary files.
Students will learn about all file handling functions with programming examples
Points:
1. File Handling in C: We frequently use files for storing information which can be processed by
our programs. In order to store information permanently and retrieve it we need to use files.
2. Files are not only used for data. Our programs are also stored in files.
3. In order to use files we have to learn about File I/O i.e. how to write information to a file and
how to read information from a file.
4. Specifying the file you wish to use is referred to as opening the file.
5. When you open a file you must also specify what you wish to do with it i.e. Read from the file,
Write to the file, or both.
6. Because you may use a number of different files in your program, you must specify when
reading or writing which file you wish to use. This is accomplished by using a variable called a
file pointer.
7. Every file you open has its own file pointer variable. When you wish to write to a file you
specify the file by using its file pointer variable.
8. You declare these file pointer variables as follows:
9. The variables fp1, fp2, fp3 are file pointers. You may use any name you wish.
10. The file <stdio.h> contains declarations for the Standard I/O library and should always be
included at the very beginning of C programs using files.
11. Constants such as FILE, EOF and NULL are defined in <stdio.h>.
12. You should note that a file pointer is simply a variable like an integer or character.
13. It does not point to a file or the data in a file. It is simply used to indicate which file your I/O
operation refers to.
14. A file number is used in the Basic language and a unit number is used in Fortran for the same
purpose.
15. The function fopen is one of the Standard Library functions and returns a file pointer which you
use to refer to the file you have opened e.g.
16. The above statement opens a file called prog.c for reading and associates the file pointer fp
with the file.
17. When we wish to access this file for I/O, we use the file pointer variable fp to refer to it.
The Standard I/O Library provides similar routines for file I/O to those used for standard I/O.
c = getc(fp);
reads the next character from the file referenced by fp and the statement
putc(c,fp); writes the character c into file referenced by fp.
Objective Questions
Assignment Questions:
True/False Questions:
Objective:
The student will be able to learn the related activities of sorting and searching
which are very important to many computer applications.
The student will be able to understand the concept of searching and their types
along with algorithms.
And also student will be able to know about different types of sorting techniques
along with algorithms.
Outcome:
After completion of this chapter the student will come to know the concept of
searching and types of searching along with the algorithms and programs.
After completion of this chapter the student will come to know the concept of
sorting and different types of sorting techniques along with the algorithms and
programs.
The students will come to know the time complexities of various searching and
sorting techniques.
Syllabus: Searching and sorting-selection sort, bubble sort, insertion sort, merge sort.
Searching-Linear search and binary search methods.
Points:
3. If min!=pass then swap a[min] and a[pass] [end of outer for loop]
4. Exit
15. Insertion sort: insertion sort works very fast on small size arrays. The
insertion sort procedure scans array, a from a[0] to a[n-1], inserting each
element a[j] into its proper position in the previously sorted sub array
a[0],a[1],……….a[n-1].
16. Merge sort: the merge sort technique sorts a given set of values by
combining two sorted arrays into one larger sorted array.
17. The total number of comparisons in the merge sort technique to sort n data-
items of an array is log n.
18. So the complexity of merge sort O(n log n).
19. Quick sort: sorting method that performs very well on larger arrays and lists.
At each step in the method the goal is to place a particular element in its final
position within the array.
20. In so doing the elements which precede the element are smaller while the
elements that follow it are larger. This technique essentially partitions the
array into two sub-arrays.
21. The same process can then be applied to these sub-arrays and repeated until
all the elements are placed in their final positions.
22. The quick sort method of sorting is also called as partition exchange
procedure.
23. A general algorithm based on a recursive method follows:
a. Partition the current array into two sub-arrays.
b. Invoke quick sort to sort the left sub-array
c. Invoke quick sort to sort the right sub-array.
24. Linear Search: the simplest form of a search is the linear (sequential) search.
This technique is meant for searching a particular item in an unsorted data in
a sequential manner until the desired data item is found.
25. Linear search is easy to write and efficient for short lists, but a failure for long
ones.
26. Binary search: binary search is a simple methods of accessing a particular
item with a certain key value resembles the search for a name.
27. The approximate middle item of the data set is located, and its key value is
examined. If its value is too high, then the key of middle element of the first
half of the set is examined and procedure is repeated on the first half until
the required item is found.
28. If the value is too low, then the key of the middle element of the second half
of the dataset is tried and the procedure is repeated on the second half. This
process continuous until the desired key is found or search interval becomes
empty.
Objective questions:
3) If the elements are sorted using linked list, which Sorting is more efficient [ ]
10) For the list of only few elements which search Techniques is efficient [ ]
11) For the list of large number of elements which search technique is efficient [ ]
16) The binary search is effective only when the elements are in [ ]
Answers: 1. B 2. B 3. B 4. c
Answers: 17. Sorting 18. Searching 19. Binary search 20. Merge sort 21. (Left+right)/2
True or false:
Assignment questions:
1. Write a ‘c’ program to sort the given integers using partition Exchange sort?
3. Write a ‘c’ program to search for a given element in the integer array using binary search.
4. Write a ‘c’ program to sort the given integers using Merge sort.
7. Analyze the worst-case performance of Quick sort and compare with Selection sort.
10. Write a recursive binary search function to find the location of the given element in the
array.
11. Formulate non-recursive algorithm for binary search with its timing analysis.
14. Suppose that the list contains the integers 1, 2, 8 in this order. Trace out through steps of
binary search to determine what comparisons of key are done in searching.
15. Compare the different sorting algorithms with respect to the time and space complexities.
19. Explain the algorithm for exchange sort with a suitable example.
20. What are the best and worst case time complexities for quick sort?
22. Write an algorithm for two way merge sort. Analyze the Time complexity.
Tutorial Problems:
1. Write a ‘c’ program to sort the given list of integers in ascending order by using Bubble sort.
2. Write a ‘c’ program to sort the given list of integers in ascending order by using Selection
sort.
3. Write a ‘c’ program to sort the given list of integers in ascending order by using Quick sort.
4. Write a ‘c’ program to sort the given list of integers in ascending order by using Merge sort.
5. Write a ‘c’ program to sort the given list of integers in ascending order by using Insertion
sort.
6. Write a ‘c’ program that use both recursive and non-recursive function to perform the
following searching operations for a key in a given list.
2. Illustrate the results of bubble sort for each pass, for the following initial array of elements.
68 67 99 33 122 200
3. Write a C program or algorithm to sort an array of integers in ascending order using insertion
sort.
4. Illustrate the results of insertion sort for each pass, for the following initial array of elements.
68 57 99 33 122 200
5. Write a C program or algorithm to sort an array of integers in ascending order using selection
sort.
6. Illustrate the results of insertion sort for each pass, for the following initial array of elements.
23 78 45 8 32 56
7. Write an algorithm or program for binary search to find a given integer in an array of integers.
8. Illustrate the results of bubble sort for each pass, for the following initial array of elements
44 36 57 19 25 89 28
9. Write an algorithm or program for linear search to find a given integer in an array of integers.
UNIT - VIII
Objective:
Outcome:
The student can create linear data structures using linear lists and linked lists.
The student can convert infix expression to prefix and postfix expressions.
Syllabus: Data structures – Introduction to DS, Abstract data types, linear list, Singly Linked List
– implementation, insertion, deletion and searching operations on linked list, Stacks –
operations, Array and linked representation of stacks, stack application infix to post fix
conversion, postfix expression evaluation, recursion, implementation, Queues – operations,
array and linked representations.
Points:
Abstract Data Type: The Abstract Data Type is a specification for the type of values that a
data type can store and the operation that can be performed on those values.
Data Structure: A data structure is a group of memory locations used to represent the
information used by the algorithm.
Types of Data Structure: Two types 1. Linear Data Structure and 2. Non-linear Data Structure
Stack: A stack is a linear structure containing homogeneous elements in which all insertions and
deletions are made at one end, called top of the stack. A stack is a Last-in-first-out (LIFO) list.
Operations of Stack:
Applications of Stack: 1. Used in conversion of infix expression into prefix and postfix.
Queue: A queue is an ordered list in which all insertions take place at one end, the rear,
whereas all deletions take place at the other end, the front. A queue is a first-in-first-out(FIFO)
linear data structure.
Operations of Queues:
2. Linked Queues
3. DeQueues
Linked Lists: A linked list is a list or chain of items where each item points to the next one in the
list. Each item in a linked list is called a node.
Assignment:
1. What is a data structure? Explain about various types of data structures with examples.
2. Write and explain stack ADT.
3. Explain various queues operations with suitable examples in detail.