
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Complete Data Structures Lectures in PPTs, best to read before exam to revise everything
Typology: Lecture notes
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
R d i th fil l b d itt
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
This is how .byte 11 (in MIPS) is stores in memory: 0000 0000 0000 0000 0000 0000 0000 1011
Big Endian: (^) Little Endian:
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
(e.g. Intel)
(e.g. SPARC)
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
g Signed/Unsigned Real
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Data Representation: Unsigned
Unsigned Unsigned integers are positive (or to be more precise, do not have a sign).
Size Limit (low, high) 8 bits 0 255 (255 = 2^8 - 1)
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
8 bits 0, 255 (255 2 1) 16 bits 0, 64k (64k = 2^16 - 1) … … N bits 0, 2N^ – 1
Signed Represented in 2’s complement form
Data Representation: Real Nos.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
Sign 8-bits Exponent
23-bits Mantissa
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
p
•Most CPUs have 6-7 significant figures
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
In two-dimensional parity check, a block of bits is divided into rows and a redundant row of bits is added to the whole block.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Mode Operations Allowed
Action
r Read Return NULL if file doesn’t exist
w Write Create if file doesn’t exist. Destroy file contents if it exists a Write at end Create if file doesn’t exist
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
a Write at end Create if file doesn t exist. Retain old contents r+ Read Write Return NULL if file doesn’t exist w+ Read Write Create if file doesn’t exist. Destroy file contents if it exists a+ Read, Write-at-end
Create if file doesn’t exist. Retain old contents
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
Functions for Reading from a File
int fgetc(FILE *stream)
int fgets(char *s, int n, FILE
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
int fscanf(FILE *stream, const char *format, ...)
int fgets(char s, int n, FILE *stream)
size_t fread(const void *ptr, size_t size, size_t nobj, FILE *stream)
int fputc(int c, FILE *stream)
int fputs(const char *s, FILE *stream)
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
int fprintf(FILE *stream, const char *format, ...)
int fputs(const char s, FILE stream)
size_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *stream)
Repositioning the Read-Write Locator
Repositions the file pointer on a stream: int fseek (FILE fp, long offset, int origin);* offset is the number of bytes to move the position indicator origin says where to move from
Three options/constants are defined for origin
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
move the indicator offset bytes from the beginning SEEK_CUR move the indicator offset bytes from its current position SEEK_END move the indicator offset bytes from the end
long ftell (FILE * fp) ;
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
External Sorting Techniques K-way Merge Sort
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Poly-Phase Merge Sort
Need Entire data to be sorted might not fit in the available internal memory
Considerations When data resides in internal memory
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
When data resides in internal memory Data access time << Computation time Need to reduce the number of CPU operations When data resides on external storage devices Data access time >> Computation time Need to reduce disk accesses
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
g ( ) y storage
There are N records on the disk It is possible to sort M records using internal sort (at a time)
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
Create N/M sorted runs, reading M records at a time Set aside 3 blocks of internal memory each capable of holding M/3 records First two blocks act as input buffers Third acts as output buffer
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Third acts as output buffer Merge runs {R1, R2}; {R3, R4} to get N/2M runs of size 2M each Continue merging till a single run of size N is not obtained
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
2-Way Merge (with Tape Drives)
Available number of tape drives: 4 (2*2) Say the tapes are named U, V, W, X All the data is initially on tape U Internal memory can sort M records at a time T t l b f d i N
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
Total number of records is N Depending upon the pass number the pair (U,V) or (W,X) can act either as a set of input tapes or output tapes
2-Way Merge (with Tape Drives)
Read M records from U Sort them internally and Write them alternately to W/X Do Merge Ith run from W with Ith run on X; Write to U Merge (I+1)th run from W with (I+1)th run on X; Write to V Continue till all runs are not processed
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Result: N/2M runs of length 2M each, placed alternately on tapes W & X W & X become the input tapes U & V become the output tapes Repeat the merge process till you don’t get a single run of length N
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
Motivation Need for better performance
Strategy Increase the number of runs that are merged at a time Say, K runs are merged at a time
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh U4.
Requirement According to the above algorithm we require K input tapes and K output tapes => 2*K number of tape drives
Number of passes Log (^) k (N/M) = P
Illustration: 3-Way Merge using 6 tapes
T1 2 12 3 5 23 6 50 7 31 90 22 11 15 78 45 40 T
T T
© Bharati Vidyapeeth’s Institute of Computer Applications and Management, New Delhi-63, by Shalini Singh (^) U4.
T T