Latest News
|
|
UNIT 5
TOPICS TO BE COVERED IN THIS UNIT:
- Input and output - concept of a file
- Text files and binary files
- Streams
- Standard I/O
- Formatted I/O
- File I/O operations
- Error handling
TEACHING MATERIAL
Unit 5 Teaching Aids - Click Here
TUTORIAL MATERIAL
Tutorial 1
- What are the different modes in which a file can be opened.
- What is a binary file and explain its different modes.
- Explain the syntax of the following i/o operations.
- fopen
- fprintf
- ftell
- rewind
- Explain the differences between the following codes relating to their outputs.
main main
{ {
FILE fp; FILE fp;
char c; char c;
printf("enter a string:"); printf("enter the string");
scanf("%c",&c); scanf("%c",&c);
fp=fopen("abc","w"); fp=fopen("abc","a");
fprintf(fp,"%c",c); fprintf(fp,"%c",c);
fclose(fp); fclose(fp);
} }
- The return type of the function fopen is?______
- In the following code,what is the work of argc and argv
main(int argc,char *argv[])
{
------
------
}
Tutorial 2
- Describe the error handling techniques used in i/o operations
- Write a program to write your details into file and print them
- Observe the following code
main()
{
int i;
for(i=1;i=10;i++)
printf("%d",i);
}
after execution of the above program print.c we get print.exe
if we perform the command "c:\>print.exe>abc.txt"
- what does '>' operator do.
- what is the data present in abc.txt
- if a file contains the following text{ABCDEFGHIJKLMNOPQRSTUVWXYZ^Z}then what is the output for
fseek(fp,5l,0);
printf("The position of %c is %d",getc(fp),ftell(fp));
- If the same file is taken as input,then what is the output for
fseek(fp,10,SEEK_SET);
if(feof(fp2)!=0)
printf("File is run out of data");
else
printf("%c",fgetc(fp));
PRACTICE PROBLEMS
Beginner Problems
- What do you mean by sorting? Mention the different types of sorting.
- Explain linear search with a good example.
- What is the time complexity of binary search?
- Trace out all passes and steps by hand to sort the following list in bubble sort
5 2 1 8 7
- Write algorithm for performing selection sort.
- Write a program to sort elements of an array using Insertion sort.
Intermediate Problems
- Formulate recursive algorithm for binary search with its timing analysis.
- Write a program to explain selection sort. Which type of technique does it belong?
- Compare the advantage and disadvantage of bubble, insertion and selection sort.
- Sort the following numbers using selection sort and give the required steps.
96,31,27,42,34,76,61,10,4
- Distinguish between linear and binary search methods.
- Write an algorithm for non-recursive binary search method.
- Write an algorithm for two-way merge sort. Analyze its time complexity.
- Derive the time complexity of merge sort.
- Explain Quick sort with algorithm.
- Analyze the worst case performance of Quick sort and compare with Selection sort.
Advanced Problems
- Write a program to sort the elements whose worst case is O (n2) and average case is
O (n log n).
- Write an algorithm for routine merge(x, lb1, ub1, ub2) that assumes that
x [lb1] through
x [ub1] and x[ub1 + 1] through x[ub2] are sorted and merges the two into x[lb1]
through x[ub2].
- Trace through the steps by hand to sort the following list in Quick sort.
28 7 39 3 63 13 61 17 50 21
- Write in detail about the following:
- Selection sort
- Merge Sort.
- Suppose that the list contains the integers 3 7 13 17 28 50 21 39 61 63 in this order.
Trace through the steps of binary search to determine what comparisons of keys are done
in searching. - To locate 17
- To locate 16
- Write an algorithm for performing selection sort when the input elements are represented as a linked list.
- Write about Sorting Efficiency, and explain O - notation Analysis.
This Page Is Designed By R.Harish
|