CSC 211 Data Structures Lecture 32

Slides:



Advertisements
Similar presentations
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
Advertisements

Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
Chapter 11: Data Files & File Processing In this chapter, you will learn about Files and streams Creating a sequential access file Reading data from a.
CSCI 171 Presentation 12 Files. Working with files File Streams – sequence of data that is connected with a specific file –Text Stream – Made up of lines.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
 2000 Prentice Hall, Inc. All rights reserved. Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Lec11: File Processing 廖雪花 TEL: 年 5 月.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating.
Structures and Unions Chapter 6. Structure A structure is an aggregate data type  Composed of two or more related variables called member/field/element.
CS1061 C Programming Lecture 18: Sequential File Processing A. O’Riordan, 2004, 2007 updated.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
20/03/01 Sudeshna Sarkar, CSE, IIT Kharagpur1 File Handling in C Lecture 17c 20/3/01.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
22. FILE INPUT/OUTPUT. File Pointers and Streams Declarations of functions that perform file I/O appear in. Each function requires a file pointer as a.
Programming Practice Introduction Tree Operations. Binary Search Tree. File Processing Create, read, write and update files. Sequential.
1 File Processing Dr. Serdar ÇELEBİ. 2 Outline Introduction The Data Hierarchy Files and Streams Creating a Sequential Access File Reading Data from a.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Programming Languages -1 (Introduction to C) files Instructor: M.Fatih AMASYALI
1 Lecture09: File I/O 5/6/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Text and Binary File Processing 程式設計 潘仁義 CCU COMM.
1. Introduction File Declaration and Initialization Creating and Opening File Closing File EOF Reading from and Writing into a File Extra : Random Access.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
1 Lecture09: File I/O 11/19/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Introduce some standard library functions.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 11 – File Processing Outline 11.1Introduction.
Chapter 12 Files (reference: Deitel ’ s chap 11) chap8.
C Program Design C File Processing 主講人:虞台文. Content Introduction Data Hierarchy Files and Streams Creating a Sequential-Access File Reading Data from.
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
CS 261 – Recitation 7 Spring 2015 Oregon State University School of Electrical Engineering and Computer Science.
C File Processing. Objectives To be able to create, write and update files. To become familiar with sequential access file processing. To become familiar.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Chapter 12 Files (reference: Deitel ’ s chap 11) chap8.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 29 Thanks for Lecture Slides:
Files A collection of related data treated as a unit. Two types Text
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
FILES IN C. File Operations  Creation of a new file  Opening an existing file  Reading from a file  Writing to a file  Moving to a specific location.
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
1 Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating a Sequential Access File 11.5Reading.
Connecting to Files In order to read or write to a file, we need to make a connection to it. There are several functions for doing this. fopen() – makes.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
UniMAP SemI-11/12EKT120: Computer Programming1 Files.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Chapter 11 – File Processing
11 C File Processing.
Chapter 4 File Processing
TMF1414 Introduction to Programming
File I/O.
Chapter 11 – File Processing
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Text and Binary File Processing
File Input and Output.
Chapter: 7-12 Final exam review.
Fundamental of Programming (C)
File Handling in C.
EPSII 59:006 Spring 2004.
EPSII 59:006 Spring 2004.
Chapter 11 Files chap8.
Professor Jodi Neely-Ritz University of Florida
Presentation transcript:

CSC 211 Data Structures Lecture 32 Dr. Iftikhar Azim Niaz ianiaz@comsats.edu.pk 1

Last Lecture Summary Hash Function Properties of a Good Hash Function Hash Function Methods File Text and Binary Files Operations on Files File Access Methods Sequential Files Indexed Files Hashed Files 2

Objectives Overview File Implementation in C Language Basic File Operations Opening a file Reading data from a file Writing data to a file Closing a file File operations on Text Files File operations on Sequential Binary Files Revision of the Course Lecture 1 to Lecture 31

Files - Implementation Files are places where data can be stored permanently. Some programs expect the same set of data to be fed as input every time it is run. Cumbersome. Better if the data are kept in a file, and the program reads from the file. Programs generating large volumes of output. Difficult to view on the screen. Better to store them in a file for later viewing/ processing 4

Text Data Files When you use a file to store data for use by a program, that file usually consists of text (alphanumeric data) and is therefore called a text file. Can be created, updated, and processed by C programs Are used for permanent storage of large amounts of data Storage of data in variables and arrays is only temporary

Basic Files Operations Opening a file Reading data from a file Writing data to a file Closing a file

Opening a File A file must be “opened” before it can be used. FILE *fp; : fp = fopen (filename, mode); fp is declared as a pointer to the data type FILE. filename is a string - specifies the name of the file. fopen returns a pointer to the file which is used in all subsequent file operations. mode is a string which specifies the purpose of opening the file: “r” :: open the file for reading only “w” :: open the file for writing only “a” :: open the file for appending data to it

File Modes r - open a file in read-mode, set the pointer to the beginning of the file. w - open a file in write-mode, set the pointer to the beginning of the file. a - open a file in write-mode, set the pointer to the end of the file. rb - open a binary-file in read-mode, set the pointer to beginning of file. wb - open a binary-file in write-mode, set the pointer to beginning of file. ab - open a binary-file in write-mode, set the pointer to the end of the file. r+ - open a file in read/write-mode, if file does not exist, it will not be created. w+ - open a file in read/write-mode, set the pointer to the beginning of file. a+ - open a file in read/append mode. r+b - open a binary-file in read/write-mode, if the file does not exist, it will not be created. w+b - open a binary-file in read/write-mode, set pointer to beginning of file. a+b - open a binary-file in read/append mode.

File Modes Points to note: Several files may be opened at the same time. For the “w” and “a” modes, if the named file does not exist, it is automatically created. For the “w” mode, if the named file exists, its contents will be overwritten.

Opening a File in = fopen (“mydata.dat”, “r”) ; FILE *in, *out ; in = fopen (“mydata.dat”, “r”) ; out = fopen (“result.dat”, “w”); FILE *empl ; char filename[25]; scanf (“%s”, filename); empl = fopen (filename, “r”) ;

Closing a File After all operations on a file have been completed, it must be closed. Ensures that all file data stored in memory buffers are properly written to the file. General format: fclose (file_pointer) ; FILE *xyz ; xyz = fopen (“test.txt”, “w”) ; ……. fclose (xyz) ;

Closing a File fclose( FILE pointer ) feof( FILE pointer ) Closes specified file Performed automatically when program ends Good practice to close files explicitly system resources are freed. Also, you might not find that all the information that you've written to the file has actually been written to disk until the file is closed. feof( FILE pointer ) Returns true if end-of-file indicator (no more data to process) is set for the specified file

Read/Write Operations on Text Files The simplest file input-output (I/O) function are getc and putc. getc is used to read a character from a file and return it. char ch; FILE *fp; ch = getc (fp) ; getc will return an end-of-file marker EOF, when the end of the file has been reached. putc is used to write a character to a file. putc (ch, fp) ;

Text File - Example Convert a text file to all UPPERCASE main() { FILE *in, *out ; char c ; in = fopen (“infile.dat”, “r”) ; out = fopen (“outfile.dat”, “w”) ; while ((c = getc (in)) != EOF) putc (toupper (c), out); fclose (in) ; fclose (out) ; }

Read/Write Operations on Text Files We can also use the file versions of scanf and printf, called fscanf and fprintf. General format: fscanf (file_pointer, control_string, list) ; fprintf (file_pointer, control_string, list) ; Examples: fscanf (fp, “%d %s %f”, &roll, dept_code, &cgpa) ; fprintf (out, “\nThe result is: %d”, xyz) ; fprintf Used to print to a file It is like printf, except first argument is a FILE pointer (pointer to the file you want to print in)

Some Points How to check EOF condition when using fscanf? Use the function feof if (feof (fp)) printf (“\n Reached end of file”) ; How to check successful open? For opening in “r” mode, the file must exist. if (fp == NULL) printf (“\n Unable to open file”) ;

Example : Merge Two Text Files #include <stdio.h> int main() { FILE *fileA, /* first input file */ *fileB, /* second input file */ *fileC; /* output file to be created */ int num1, /* number to be read from first file */ num2; /* number to be read from second file*/ int f1, f2; /* Open files for processing */ fileA = fopen("class1.txt","r"); fileB = fopen("class2.txt","r"); fileC = fopen("class.txt","w");

Example : Merge Two Files /* As long as there are numbers in both files, read and compare numbersone by one. Write the smaller number to the output file and read the next number in the file from which the smaller number is read. */ f1 = fscanf(fileA, "%d", &num1); f2 = fscanf(fileB, "%d", &num2); while ((f1!=EOF) && (f2!=EOF)){ if (num1 < num2){ fprintf(fileC,"%d\n", num1); f1 = fscanf(fileA, "%d", &num1); } else if (num2 < num1) { fprintf(fileC,"%d\n", num2); f2 = fscanf(fileB, "%d", &num2); } else { /* numbs are equal:read from both files */ fprintf(fileC,"%d\n", num1); f1 = fscanf(fileA, "%d", &num1); f2 = fscanf(fileB, "%d", &num2); } }

Example : Merge Two Files /* if reached end of second file, read the remaining numbers from first file and write to output file */ while (f1!=EOF){ fprintf(fileC,"%d\n", num1); f1 = fscanf(fileA, "%d", &num1); } /* if reached the end of first file, read the remaining numbers from second file and write to output file */ while (f2!=EOF){ fprintf(fileC,"%d\n", num2); f2 = fscanf(fileB, "%d", &num2); } /* close files */ fclose(fileA); fclose(fileB); fclose(fileC); return 0; } /* end of main */

Files and Streams FILE structure C views each file as a sequence of bytes File ends with the end-of-file marker Stream created when a file is opened Provide communication channel between files and programs Opening a file returns a pointer to a FILE structure Example file pointers: stdin - standard input (keyboard) stdout - standard output (screen) stderr - standard error (screen) FILE structure File descriptor Index into operating system array called the open file table File Control Block (FCB) Found in every array element, system uses it to administer the file

Files and Streams Read/Write functions in standard library fgetc Reads one character from a file Takes a FILE pointer as an argument fgetc( stdin ) equivalent to getchar() fputc Writes one character to a file Takes a FILE pointer and a character to write as an argument fputc( 'a', stdout ) equivalent to putchar( 'a' ) fgets reads a line (string) from a file fputs writes a line (string) to a file fscanf / fprintf File processing equivalents of scanf and printf

Creating a Sequential Access File C imposes no file structure No notion of records in a file Programmer must provide file structure Creating a File FILE *myPtr; Creates a FILE pointer called myPtr myPtr = fopen("myFile.dat", openmode); Function fopen returns a FILE pointer to file specified Takes two arguments – file to open and file open mode If open fails, NULL returned fprintf Used to print to a file Like printf, except first argument is a FILE pointer (pointer to the file you want to print in)

Creating a Sequential Access File feof( FILE pointer ) Returns true if end-of-file indicator (no more data to process) is set for the specified file fclose( FILE pointer ) Closes specified file Performed automatically when program ends Good practice to close files explicitly Details Programs may process no files, one file, or many files Each file must have a unique name and should have its own pointer

1. Initialize variables and FILE pointer 1 /* Fig. 11.3: fig11_03.c 2 Create a sequential file */ 3 #include <stdio.h> 4 5 int main() 6 { 7 int account; 8 char name[ 30 ]; 9 double balance; 10 FILE *cfPtr; /* cfPtr = clients.dat file pointer */ 11 12 if ( ( cfPtr = fopen( "clients.dat", "w" ) ) == NULL ) 13 printf( "File could not be opened\n" ); 14 else { 15 printf( "Enter the account, name, and balance.\n" ); 16 printf( "Enter EOF to end input.\n" ); 17 printf( "? " ); 18 scanf( "%d%s%lf", &account, name, &balance ); 19 20 while ( !feof( stdin ) ) { 21 fprintf( cfPtr, "%d %s %.2f\n", 22 account, name, balance ); 23 printf( "? " ); 24 scanf( "%d%s%lf", &account, name, &balance ); 25 } 26 27 fclose( cfPtr ); 28 } 29 30 return 0; 31 } 1. Initialize variables and FILE pointer 1.1 Link the pointer to a file 2. Input data 2.1 Write to file (fprintf) 3. Close file

Program Output Enter the account, name, and balance. Enter EOF to end input. ? 100 Jones 24.98 ? 200 Doe 345.67 ? 300 White 0.00 ? 400 Stone -42.16 ? 500 Rich 224.62 ? Program Output

Reading Data from a Sequential Access File Reading a sequential access file Create a FILE pointer, link it to the file to read myPtr = fopen( "myFile.dat", "r" ); Use fscanf to read from the file Like scanf, except first argument is a FILE pointer fscanf( myPtr, "%d%s%f", &myInt, &myString, &myFloat ); Data read from beginning to end File position pointer Indicates number of next byte to be read / written Not really a pointer, but an integer value (specifies byte location) Also called byte offset rewind( myPtr ) Repositions file position pointer to beginning of file (byte 0)

1. Initialize variables 1.1 Link pointer to file 2. Read data (fscanf) 1 /* Fig. 11.7: fig11_07.c 2 Reading and printing a sequential file */ 3 #include <stdio.h> 4 5 int main() 6 { 7 int account; 8 char name[ 30 ]; 9 double balance; 10 FILE *cfPtr; /* cfPtr = clients.dat file pointer */ 11 12 if ( ( cfPtr = fopen( "clients.dat", "r" ) ) == NULL ) 13 printf( "File could not be opened\n" ); 14 else { 15 printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" ); 16 fscanf( cfPtr, "%d%s%lf", &account, name, &balance ); 17 18 while ( !feof( cfPtr ) ) { 19 printf( "%-10d%-13s%7.2f\n", account, name, balance ); 20 fscanf( cfPtr, "%d%s%lf", &account, name, &balance ); 21 } 22 23 fclose( cfPtr ); 24 } 25 26 return 0; 27 } 1. Initialize variables 1.1 Link pointer to file 2. Read data (fscanf) 2.1 Print 3. Close file Program Output Account Name Balance 100 Jones 24.98 200 Doe 345.67 300 White 0.00 400 Stone -42.16 500 Rich 224.62

1. Initialize variables 2. Open file 2.1 Input choice 2.2 Scan files 1 /* Fig. 11.8: fig11_08.c 2 Credit inquiry program */ 3 #include <stdio.h> 4 5 int main() 6 { 7 int request, account; 8 double balance; 9 char name[ 30 ]; 10 FILE *cfPtr; 11 12 if ( ( cfPtr = fopen( "clients.dat", "r" ) ) == NULL ) 13 printf( "File could not be opened\n" ); 14 else { 15 printf( "Enter request\n" 16 " 1 - List accounts with zero balances\n" 17 " 2 - List accounts with credit balances\n" 18 " 3 - List accounts with debit balances\n" 19 " 4 - End of run\n? " ); 20 scanf( "%d", &request ); 21 22 while ( request != 4 ) { 23 fscanf( cfPtr, "%d%s%lf", &account, name, 24 &balance ); 25 26 switch ( request ) { 27 case 1: 28 printf( "\nAccounts with zero " 29 "balances:\n" ); 30 31 while ( !feof( cfPtr ) ) { 32 1. Initialize variables 2. Open file 2.1 Input choice 2.2 Scan files 3. Print

2.2 Scan files 3. Print 33 if ( balance == 0 ) 34 printf( "%-10d%-13s%7.2f\n", 35 account, name, balance ); 36 37 fscanf( cfPtr, "%d%s%lf", 38 &account, name, &balance ); 39 } 40 41 break; 42 case 2: 43 printf( "\nAccounts with credit " 44 "balances:\n" ); 45 46 while ( !feof( cfPtr ) ) { 47 48 if ( balance < 0 ) 49 printf( "%-10d%-13s%7.2f\n", 50 account, name, balance ); 51 52 fscanf( cfPtr, "%d%s%lf", 53 &account, name, &balance ); 54 } 55 56 break; 57 case 3: 58 printf( "\nAccounts with debit " 59 "balances:\n" ); 60 61 while ( !feof( cfPtr ) ) { 62 63 if ( balance > 0 ) 64 printf( "%-10d%-13s%7.2f\n", 2.2 Scan files 3. Print

3.1 Close file 65 account, name, balance ); 66 67 fscanf( cfPtr, "%d%s%lf", 68 &account, name, &balance ); 69 } 70 71 break; 72 } 73 74 rewind( cfPtr ); 75 printf( "\n? " ); 76 scanf( "%d", &request ); 77 } 78 79 printf( "End of run.\n" ); 80 fclose( cfPtr ); 81 } 82 83 return 0; 84 } 3.1 Close file

Program Output Enter request 1 - List accounts with zero balances   Enter request 1 - List accounts with zero balances 2 - List accounts with credit balances 3 - List accounts with debit balances 4 - End of run ? 1 Accounts with zero balances: 300 White 0.00 ? 2 Accounts with credit balances: 400 Stone -42.16 ? 3 Accounts with debit balances: 100 Jones 24.98 200 Doe 345.67 500 Rich 224.62 ? 4 End of run. Program Output

Reading Data from a Sequential Access File Cannot be modified without the risk of destroying other data Fields can vary in size Different representation in files and screen than internal representation 1, 34, -890 are all ints, but have different sizes on disk 300 White 0.00 400 Jones 32.87 (old data in file) If we want to change White's name to Worthington, 300 White 0.00 400 Jones 32.87 300 Worthington 0.00ones 32.87 300 Worthington 0.00 Data gets overwritten

Read and Write for Binary Files size_t fread(void *buffer, size_t numbytes, size_t count, FILE *a_file); size_t fwrite(void *buffer, size_t numbytes, size_t count, FILE *a_file); Buffer in fread is a pointer to a region of memory that will receive the data from the file. Buffer in fwrite() is a pointer to the information that will be written to the file. The second argument is the size of the element; it is in bytes. Size_t is an unsigned integer. For example, if you have an array of characters, you would want to read it in one byte chunks, so numbytes is one. You can use the sizeof operator to get the size of the various datatypes; for example, if you have a variable, int x; you can get the size of x with sizeof(x);

Read and Write for Binary Files The third argument count is simply how many elements you want to read or write; for example, if you pass a 100 element array The final argument is simply the file pointer fread() returns number of items read and fwrite() returns number of items written To check to ensure the end of file was reached, use the feof function, which accepts a FILE pointer and returns true if the end of the file has been reached.

Sample Program - 1 /* a simple example of using fread and fwrite to read and write an array of structures */ #include <stdio.h> #include <conio.h> int main() { FILE *fp; // File pointer struct prod { // declaring record int cat_num; float cost; }; typedef struct prod product; // type definition product a[3] = {{2,20.1},{4,40.1},{6,60.1}};// array of records product k, *p = &k;

Sample Program - 2 // opening the text file in read/write mode fp = fopen("c:\fread1.dat","w+b"); // write the entire array into the file pointed to by fp fwrite(a, sizeof(product), 3, fp); // prepare for reading from the beginning of the file rewind(fp); // read from the file one product at a time for (i=0; i<3; i++) { fread(p, sizeof(product), 1, fp); printf(" product %d, cat_num=%d, cost=%f\n", i, p->cat_num, p->cost); } // end of for loop getch(); } // end of main program

Revision – Lectures 1 – 4 1 2 3 4 Lecture Topics Course Outline, Programming and problem solving, Software development method, Program control structures, Algorithm, Pseudocode and Flow chart 2 System Development Life cycle and its phases, Program Development Life cycle and its phases 3 Generation of programming languages, Compiler Interpreter, Procedural and modular programming Structure of a C Program, Data and data structure, Abstract Data Type (ADT) 4 Data types in C Language, Arrays, Declaration, operations, Array and functions, Pointers, Arrays and pointers

Revision – Lectures 5 – 8 5 6 7 8 Lecture Topics Concept of Pointer, Pointer operators, Address and Indirection, Pointer Arithmetic, Pointer and functions Pass by Value, Pass by Reference 6 Dynamic Memory Management with Pointers, Structures, Unions, Strings, Multidimensional Arrays 7 Need for Data Structures, Selecting a data structure Data structure philosophy, Classification, Common Operations, Arrays and Lists, List Operations 8 Algorithm Analysis, Time and Space Complexity, Complexity of Algorithms, Measuring Efficiency Big O Notation, Standard Analysis Techniques

Revision – Lecture 9 – 12 9 10 11 12 Lecture Topics Algorithms and Complexity, Criteria for Algorithm Analysis, Complexity Analysis, Various Complexity Functions, Properties of Big O Notation 10 Data structure Operations, Array-based and Pointer based List ADT, Linked List, Linked List Operations 11 Dynamic Representation, Allocation from Dynamic Storage, Returning unused storage back to dynamic storage, Linked List insert and delete Operations 12 Cursor-based Implementation of List, Search Operation, Sequential Search, Concept, Algorithm and Implementation, Complexity of Sequential Search

Revision – Lectures 13 – 16 13 14 15 16 Lecture Topics Binary Search, Concept, Algorithm and implementation, Binary search complexity, Searching Unordered and Ordered Linked Lists 14 Sorting, Concept, Terminology, Classification, Stability of Key, Bubble Sort, Concept, Algorithm and implementation 15 Bubble Sort Complexity, Selection Sort, Concept, Algorithm, Implementation, Complexity, Insertion Sort, Concept, Algorithm, Implementation, Complexity 16 Comparison of Bubble, Selection and Insertion Sort, Recursion, Concept, Example and Implementation

Revision – Lectures 17 – 20 17 18 19 20 Lecture Topics Recursive Search Algorithms, Recursion with Linked Lists, Recursion and Iteration, Analysis of Recursion 18 Merge Sort, Concept, Algorithm and Implementation Complexity of Merge Sort 19 Quick Sort, Concept, Algorithm and Implementation Complexity of Quick Sort 20 Comparison of Merge and Quick Sort, Shell Sort, Radix sort, Bucket Sort, Sorting techniques comparison

Revision – Lectures 21 – 24 21 22 23 24 Lecture Topics Doubly Linked List, Operations, Algorithm and Implementation Code, Doubly Linked List with Two Pointers 22 Queues, Operations, Algorithm and Implementation, Circular Queue and Deque operations 23 Stacks, Operations, Algorithm and Implementation, Stack Applications 24 Trees, Concept, Examples and Applications, Tree Terminology, Types of Trees, General Trees, Representation and Traversal, Binary Tree

Revision – Lectures 25 – 28 25 26 27 28 Lecture Topics Binary Tree Operations and Traversal, Binary Search tree and its Operations 26 Complete Binary Tree, Heaps, Heap Operations Applications of Heaps, Priority Queue, Heap Sort Concept , Algorithm and Implementation, Complexity, Comparison with Quick and Merge Sort 27 Types of Binary trees, Expression Tree, Threaded Binary Tree, AVL Tree, Red-Black, Splay, Insertion and Deletion Operations, Time Complexity, B–trees 28 Graphs, Terminology and Representation of Graphs Operations on Graphs, Graph Traversals, Breadth First Search (BFS), Depth First Search (DFS)

Revision – Lectures 29 – 32 29 30 31 32 Lecture Topics Shortest Path Problem, Dijkstra’s Algorithm, Bellman Ford Algorithm, Spanning Tree, Minimum Spanning Tree, Kruskal and Prim Algorithm 30 Dictionaries, Table, Concept, Operations and Implementation, Hash Table, Hashing and Hash Function, Hash Tables Implementation, Applications 31 Hash Function, Properties of a Good Hash Function Hash Function Methods, File, Text and Binary Files Operations on Files, File Access Methods, Sequential Files, Indexed Files, Hashed Files 32 File operations implementation in C, File operations on Text and Sequential Binary Files, Revision

Summary File Implementation in C Language Basic File Operations Opening a file Reading data from a file Writing data to a file Closing a file File operations on Text Files File operations on Sequential Binary Files Revision of the Course Lecture 1 to Lecture 31