Introduction
Title page
CS11001/CS11002 Programming and Data Structures
Autumn/Spring Semesters
Introduction
Department of Computer Science & Engineering
Indian Institute of Technology, Kharagpur
Last modified: July 8, 2010
Introduction
Syllabus
Syllabus
Introduction
Syllabus
Syllabus
Introduction to digital computers
Introduction
Syllabus
Syllabus
Introduction to digital computers
Basic programming constructs
Variables and simple data types
Assignments
Input/output
Conditions and branching
Loops and iteration
Iterative searching and sorting algorithms
Introduction
Syllabus
Syllabus
Introduction to digital computers
Basic programming constructs
Variables and simple data types
Assignments
Input/output
Conditions and branching
Loops and iteration
Iterative searching and sorting algorithms
Advanced programming constructs
Functions and recursion
Recursive sorting algorithms
Arrays and strings
Structures
Pointers and dynamic memory allocation
Introduction
Syllabus
Syllabus (contd.)
Introduction
Syllabus
Syllabus (contd.)
Performance analysis of programs
Introduction
Syllabus
Syllabus (contd.)
Performance analysis of programs
Data structures
Abstract data types
Ordered lists
Stacks and queues
Introduction
Syllabus
Syllabus (contd.)
Performance analysis of programs
Data structures
Abstract data types
Ordered lists
Stacks and queues
Programming language: C
Introduction
References
On C
Textbooks and references
Introduction
References
On C
Textbooks and references
Use any standard textbook on ANSI C
Introduction
References
On C
Textbooks and references
Use any standard textbook on ANSI C
Do not use books written on specific C compilers (Turbo C, gcc)
Introduction
References
On C
Textbooks and references
Use any standard textbook on ANSI C
Do not use books written on specific C compilers (Turbo C, gcc)
1 Brian W. Kernighan and Dennis M. Ritchie, The C
Programming Language, Prentice Hall of India.
2 E. Balaguruswamy, Programming in ANSI C, Tata
McGraw-Hill.
3 Byron Gottfried, Schaum’s Outline of Programming with C,
McGraw-Hill.
4 P. Dey and M. Ghosh, Programming in C, Oxford University
Press.
Introduction
References
On data structures
Textbooks and references
Introduction
References
On data structures
Textbooks and references
5 Seymour Lipschutz, Data Structures, Schaum’s Outlines
Series, Tata McGraw-Hill.
6 Ellis Horowitz, Satraj Sahni and Susan Anderson-Freed,
Fundamentals of Data Structures in C, W. H. Freeman and
Company.
7 R. G. Dromey, How to Solve it by Computer, Prentice-Hall
of India.
Introduction
References
On data structures
Textbooks and references
5 Seymour Lipschutz, Data Structures, Schaum’s Outlines
Series, Tata McGraw-Hill.
6 Ellis Horowitz, Satraj Sahni and Susan Anderson-Freed,
Fundamentals of Data Structures in C, W. H. Freeman and
Company.
7 R. G. Dromey, How to Solve it by Computer, Prentice-Hall
of India.
8 http://cse.iitkgp.ac.in/∼pds/notes/
9 http://cse.iitkgp.ac.in/∼pds/notes/swf/
Introduction
Marks distribution
Marks distribution
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Mid-semester test: 30
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Mid-semester test: 30
End-semester test: 50
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Mid-semester test: 30
End-semester test: 50
Final marks of a student: M = m × α, where
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Mid-semester test: 30
End-semester test: 50
Final marks of a student: M = m × α, where
m = Total marks obtained in 100, and
Introduction
Marks distribution
Marks distribution
Two class tests: 10 × 2 = 20
Mid-semester test: 30
End-semester test: 50
Final marks of a student: M = m × α, where
m = Total marks obtained in 100, and
α = Classes attended / Total number of classes.
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Class Test 1: First week of September/February
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Class Test 1: First week of September/February
Mid-semester Test: As per institute schedule
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Class Test 1: First week of September/February
Mid-semester Test: As per institute schedule
Class Test 2: First week of November/April
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Class Test 1: First week of September/February
Mid-semester Test: As per institute schedule
Class Test 2: First week of November/April
End-Semester Test: As per institute schedule
Introduction
Test schedule (tentative)
Tentative schedule of theory tests
Class Test 1: First week of September/February
Mid-semester Test: As per institute schedule
Class Test 2: First week of November/April
End-Semester Test: As per institute schedule
Two or three lab tests are conducted by respective lab instructors
Introduction
Coverage schedule
Tentative schedule for coverage
Introduction
Coverage schedule
Tentative schedule for coverage
Before Class Test 1: Until “iterations” (all loop constructs)
Introduction
Coverage schedule
Tentative schedule for coverage
Before Class Test 1: Until “iterations” (all loop constructs)
Before MidSem Test: Until “introduction to pointers”
Introduction
Coverage schedule
Tentative schedule for coverage
Before Class Test 1: Until “iterations” (all loop constructs)
Before MidSem Test: Until “introduction to pointers”
Before Class Test 2: Until “linked structures”
Introduction
Coverage schedule
Tentative schedule for coverage
Before Class Test 1: Until “iterations” (all loop constructs)
Before MidSem Test: Until “introduction to pointers”
Before Class Test 2: Until “linked structures”
Before EndSem Test: Everything
Introduction
Structure of a C program
How to write C programs
Skeleton of a C program
Introduction
Structure of a C program
How to write C programs
Skeleton of a C program
Include header files
Introduction
Structure of a C program
How to write C programs
Skeleton of a C program
Include header files
Declare global variables, constants and function prototypes
Introduction
Structure of a C program
How to write C programs
Skeleton of a C program
Include header files
Declare global variables, constants and function prototypes
Function bodies
Introduction
Structure of a C program
How to write C programs
Skeleton of a C program
Include header files
Declare global variables, constants and function prototypes
Function bodies
There must be a main function in any C program.
Introduction
Structure of a C program
An example
A complete example
#include <stdio.h>
#define PI_4_BY_3 4.1887902048
double radius = 10;
double sphereVol ( double r )
{
return PI_4_BY_3 * r * r * r;
}
main ()
{
double area;
area = sphereVol(radius);
printf("Radius = %lf, volume = %lf.n", radius, area);
}
Introduction
Some simple C programs
The traditional starter
The traditional starter
#include <stdio.h>
main ()
{
printf("Hello, world!n");
}
Introduction
Some simple C programs
The traditional starter
The traditional starter
#include <stdio.h>
main ()
{
printf("Hello, world!n");
}
This program takes no input, but outputs the string
“Hello, world!”
in a line.
Introduction
Some simple C programs
The short-circuit program
The short-circuit program
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",n);
}
Introduction
Some simple C programs
The short-circuit program
The short-circuit program
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",n);
}
This program accepts an integer as input and outputs the same
integer.
Introduction
Some simple C programs
The square finder
The square finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",n*n);
}
Introduction
Some simple C programs
The square finder
The square finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",n*n);
}
This program takes an integer n as input and outputs the
square n2 of n.
Introduction
Some simple C programs
A faulty reciprocal finder
A faulty reciprocal finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",1/n);
}
Introduction
Some simple C programs
A faulty reciprocal finder
A faulty reciprocal finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",1/n);
}
The division 1/n is of integers (quotient).
Introduction
Some simple C programs
A faulty reciprocal finder
A faulty reciprocal finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%dn",1/n);
}
The division 1/n is of integers (quotient).
The format %d is for printing integers.
Introduction
Some simple C programs
The correct reciprocal finder
The correct reciprocal finder
#include <stdio.h>
main ()
{
int n;
scanf("%d",&n);
printf("%fn",1.0/n);
}
Introduction
PDS laboratory
PDS Laboratory
Introduction
PDS laboratory
Log in
Getting started
Introduction
PDS laboratory
Log in
Getting started
Switch on your monitor.
Introduction
PDS laboratory
Log in
Getting started
Switch on your monitor.
Switch on your PC.
Introduction
PDS laboratory
Log in
Getting started
Switch on your monitor.
Switch on your PC.
Allow the machine to boot. Wait until the log in prompt
comes.
Introduction
PDS laboratory
Log in
Getting started
Switch on your monitor.
Switch on your PC.
Allow the machine to boot. Wait until the log in prompt
comes.
Supply your log-in and password:
Login: s<nn>
Password: s<nn>
Here s is your section (a for 1, b for 2, and so on)
<nn> is the number of your PC.
This opens your window manager (usually KDE) with
icons, the bottom panel, and so on. You are now ready to
start your work.
Introduction
PDS laboratory
Edit, compile and run
Getting started
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Edit your program (new or already existing) by an editor.
emacs myprog.c &
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Edit your program (new or already existing) by an editor.
emacs myprog.c &
Write your program in the editor and save it.
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Edit your program (new or already existing) by an editor.
emacs myprog.c &
Write your program in the editor and save it.
Go to the shell and compile your program:
cc myprog.c
If compilation is successful, an executable called a.out
will be created.
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Edit your program (new or already existing) by an editor.
emacs myprog.c &
Write your program in the editor and save it.
Go to the shell and compile your program:
cc myprog.c
If compilation is successful, an executable called a.out
will be created.
Run your program:
./a.out
Introduction
PDS laboratory
Edit, compile and run
Getting started
Click on the terminal icon to open a shell (command
prompt).
Edit your program (new or already existing) by an editor.
emacs myprog.c &
Write your program in the editor and save it.
Go to the shell and compile your program:
cc myprog.c
If compilation is successful, an executable called a.out
will be created.
Run your program:
./a.out
Continue your edit-compile-debug-run-debug cycle.
Introduction
PDS laboratory
Shut down
Getting started
Introduction
PDS laboratory
Shut down
Getting started
Close all the windows you opened.
Introduction
PDS laboratory
Shut down
Getting started
Close all the windows you opened.
Log out from your window manager. This leaves you again
in the log-in console.
Introduction
PDS laboratory
Shut down
Getting started
Close all the windows you opened.
Log out from your window manager. This leaves you again
in the log-in console.
Select the item to shut down the machine. Wait until the
machine completely shuts down.
Introduction
PDS laboratory
Shut down
Getting started
Close all the windows you opened.
Log out from your window manager. This leaves you again
in the log-in console.
Select the item to shut down the machine. Wait until the
machine completely shuts down.
Switch off your monitor.
Introduction
PDS laboratory
Using emacs
Using emacs
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Save your file before closing emacs.
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Save your file before closing emacs.
“File -> Save (Current buffer)”
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Save your file before closing emacs.
“File -> Save (Current buffer)”
Click the save button (disk)
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Save your file before closing emacs.
“File -> Save (Current buffer)”
Click the save button (disk)
“File -> Save buffer as” (to another file)
Introduction
PDS laboratory
Using emacs
Using emacs
emacs is a powerful text editor.
Run emacs as: emacs myprog.c &
Type in your program in the text area
Navigate with mouse and cursor keys
Save your file before closing emacs.
“File -> Save (Current buffer)”
Click the save button (disk)
“File -> Save buffer as” (to another file)
Save your file once in every 15 minutes.
Introduction
PDS laboratory
Using gvim
Using gvim
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Hit Esc to exit insert mode
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Hit Esc to exit insert mode
When in doubt, it is safe to hit Esc several times to come
back to view mode
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Hit Esc to exit insert mode
When in doubt, it is safe to hit Esc several times to come
back to view mode
Navigate with mouse and cursor keys
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Hit Esc to exit insert mode
When in doubt, it is safe to hit Esc several times to come
back to view mode
Navigate with mouse and cursor keys
You need to save the file by clicking on the appropriate
icon (disk).
Introduction
PDS laboratory
Using gvim
Using gvim
gvim is another powerful text editor.
Run gvim as: gvim myprog.c
Hit Insert before you start typing matter
You will exit the insert mode if you hit Insert when you are
already in the insert mode
Hit Esc to exit insert mode
When in doubt, it is safe to hit Esc several times to come
back to view mode
Navigate with mouse and cursor keys
You need to save the file by clicking on the appropriate
icon (disk).
Save your file once in every 15 minutes.
Introduction
PDS laboratory
A practice program
A practice program
#include <stdio.h>
char name[100];
int i;
main ()
{
printf("Hello, may I know your full name? ");
scanf("%s",name);
printf("Welcome %s.n",name);
printf("Your name printed backward is : ");
for (i=strlen(name)-1; i>=0; --i)
printf("%c",name[i]);
printf("n");
}
Introduction
PDS laboratory
A corrected version
A practice program (corrected)
#include <stdio.h>
char name[100];
int i;
main ()
{
printf("Hello, may I know your full name? ");
fgets(name,100,stdin);
name[strlen(name)-1] = ’0’;
printf("Welcome %s.n",name);
printf("Your name printed backward is : ");
for (i=strlen(name)-1; i>=0; --i)
printf("%c",name[i]);
printf("n");
}
Introduction
PDS laboratory
Using a web browser
Using a web browser
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Bypass proxy for local machines.
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Bypass proxy for local machines.
Type in a URL (web address) in the location field
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Bypass proxy for local machines.
Type in a URL (web address) in the location field
http://cse.iitkgp.ac.in/∼pds/
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Bypass proxy for local machines.
Type in a URL (web address) in the location field
http://cse.iitkgp.ac.in/∼pds/
http://cse.iitkgp.ac.in/∼pds/semester/2010a/
Introduction
PDS laboratory
Using a web browser
Using a web browser
Open a web browser: mozilla or konqueror.
Set a proxy:
10.3.100.211:8080
10.3.100.212:8080
144.16.192.218:8080
144.16.192.245:8080
144.16.192.247:8080
Bypass proxy for local machines.
Type in a URL (web address) in the location field
http://cse.iitkgp.ac.in/∼pds/
http://cse.iitkgp.ac.in/∼pds/semester/2010a/
http://cse.iitkgp.ac.in/∼pds/notes/
Introduction
PDS laboratory
Assignments and submissions
Assignments and submissions
Introduction
PDS laboratory
Assignments and submissions
Assignments and submissions
Click the link on the day’s assignment.
Introduction
PDS laboratory
Assignments and submissions
Assignments and submissions
Click the link on the day’s assignment.
If your assignment is a PDF file, save it to your machine.
Introduction
PDS laboratory
Assignments and submissions
Assignments and submissions
Click the link on the day’s assignment.
If your assignment is a PDF file, save it to your machine.
Use xpdf in order to view PDF files.
xpdf newassgn.pdf
Introduction
PDS laboratory
Assignments and submissions
Assignments and submissions
Click the link on the day’s assignment.
If your assignment is a PDF file, save it to your machine.
Use xpdf in order to view PDF files.
xpdf newassgn.pdf
Consult your lab instructor to know how to submit your
programs.
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Copy a file to another: cp file1.c file2.c
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Copy a file to another: cp file1.c file2.c
Copy a file to a directory: cp file1.c progs/file3.c
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Copy a file to another: cp file1.c file2.c
Copy a file to a directory: cp file1.c progs/file3.c
Move a file to another: mv file1.c file2.c
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Copy a file to another: cp file1.c file2.c
Copy a file to a directory: cp file1.c progs/file3.c
Move a file to another: mv file1.c file2.c
Move a file to a directory: mv file1.c progs/file3.c
Introduction
PDS laboratory
Some useful Unix commands
Some useful Unix commands
Create a directory: mkdir progs
Go to a new directory: cd progs/
Go to the parent directory: cd ../
List all files in a directory: ls -lF
View a file: cat filename
Copy a file to another: cp file1.c file2.c
Copy a file to a directory: cp file1.c progs/file3.c
Move a file to another: mv file1.c file2.c
Move a file to a directory: mv file1.c progs/file3.c
Delete a file: rm filename

intro-slides.pdf very important for computer science students

  • 1.
    Introduction Title page CS11001/CS11002 Programmingand Data Structures Autumn/Spring Semesters Introduction Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Last modified: July 8, 2010
  • 2.
  • 3.
  • 4.
    Introduction Syllabus Syllabus Introduction to digitalcomputers Basic programming constructs Variables and simple data types Assignments Input/output Conditions and branching Loops and iteration Iterative searching and sorting algorithms
  • 5.
    Introduction Syllabus Syllabus Introduction to digitalcomputers Basic programming constructs Variables and simple data types Assignments Input/output Conditions and branching Loops and iteration Iterative searching and sorting algorithms Advanced programming constructs Functions and recursion Recursive sorting algorithms Arrays and strings Structures Pointers and dynamic memory allocation
  • 6.
  • 7.
  • 8.
    Introduction Syllabus Syllabus (contd.) Performance analysisof programs Data structures Abstract data types Ordered lists Stacks and queues
  • 9.
    Introduction Syllabus Syllabus (contd.) Performance analysisof programs Data structures Abstract data types Ordered lists Stacks and queues Programming language: C
  • 10.
  • 11.
    Introduction References On C Textbooks andreferences Use any standard textbook on ANSI C
  • 12.
    Introduction References On C Textbooks andreferences Use any standard textbook on ANSI C Do not use books written on specific C compilers (Turbo C, gcc)
  • 13.
    Introduction References On C Textbooks andreferences Use any standard textbook on ANSI C Do not use books written on specific C compilers (Turbo C, gcc) 1 Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, Prentice Hall of India. 2 E. Balaguruswamy, Programming in ANSI C, Tata McGraw-Hill. 3 Byron Gottfried, Schaum’s Outline of Programming with C, McGraw-Hill. 4 P. Dey and M. Ghosh, Programming in C, Oxford University Press.
  • 14.
  • 15.
    Introduction References On data structures Textbooksand references 5 Seymour Lipschutz, Data Structures, Schaum’s Outlines Series, Tata McGraw-Hill. 6 Ellis Horowitz, Satraj Sahni and Susan Anderson-Freed, Fundamentals of Data Structures in C, W. H. Freeman and Company. 7 R. G. Dromey, How to Solve it by Computer, Prentice-Hall of India.
  • 16.
    Introduction References On data structures Textbooksand references 5 Seymour Lipschutz, Data Structures, Schaum’s Outlines Series, Tata McGraw-Hill. 6 Ellis Horowitz, Satraj Sahni and Susan Anderson-Freed, Fundamentals of Data Structures in C, W. H. Freeman and Company. 7 R. G. Dromey, How to Solve it by Computer, Prentice-Hall of India. 8 http://cse.iitkgp.ac.in/∼pds/notes/ 9 http://cse.iitkgp.ac.in/∼pds/notes/swf/
  • 17.
  • 18.
  • 19.
    Introduction Marks distribution Marks distribution Twoclass tests: 10 × 2 = 20 Mid-semester test: 30
  • 20.
    Introduction Marks distribution Marks distribution Twoclass tests: 10 × 2 = 20 Mid-semester test: 30 End-semester test: 50
  • 21.
    Introduction Marks distribution Marks distribution Twoclass tests: 10 × 2 = 20 Mid-semester test: 30 End-semester test: 50 Final marks of a student: M = m × α, where
  • 22.
    Introduction Marks distribution Marks distribution Twoclass tests: 10 × 2 = 20 Mid-semester test: 30 End-semester test: 50 Final marks of a student: M = m × α, where m = Total marks obtained in 100, and
  • 23.
    Introduction Marks distribution Marks distribution Twoclass tests: 10 × 2 = 20 Mid-semester test: 30 End-semester test: 50 Final marks of a student: M = m × α, where m = Total marks obtained in 100, and α = Classes attended / Total number of classes.
  • 24.
  • 25.
    Introduction Test schedule (tentative) Tentativeschedule of theory tests Class Test 1: First week of September/February
  • 26.
    Introduction Test schedule (tentative) Tentativeschedule of theory tests Class Test 1: First week of September/February Mid-semester Test: As per institute schedule
  • 27.
    Introduction Test schedule (tentative) Tentativeschedule of theory tests Class Test 1: First week of September/February Mid-semester Test: As per institute schedule Class Test 2: First week of November/April
  • 28.
    Introduction Test schedule (tentative) Tentativeschedule of theory tests Class Test 1: First week of September/February Mid-semester Test: As per institute schedule Class Test 2: First week of November/April End-Semester Test: As per institute schedule
  • 29.
    Introduction Test schedule (tentative) Tentativeschedule of theory tests Class Test 1: First week of September/February Mid-semester Test: As per institute schedule Class Test 2: First week of November/April End-Semester Test: As per institute schedule Two or three lab tests are conducted by respective lab instructors
  • 30.
  • 31.
    Introduction Coverage schedule Tentative schedulefor coverage Before Class Test 1: Until “iterations” (all loop constructs)
  • 32.
    Introduction Coverage schedule Tentative schedulefor coverage Before Class Test 1: Until “iterations” (all loop constructs) Before MidSem Test: Until “introduction to pointers”
  • 33.
    Introduction Coverage schedule Tentative schedulefor coverage Before Class Test 1: Until “iterations” (all loop constructs) Before MidSem Test: Until “introduction to pointers” Before Class Test 2: Until “linked structures”
  • 34.
    Introduction Coverage schedule Tentative schedulefor coverage Before Class Test 1: Until “iterations” (all loop constructs) Before MidSem Test: Until “introduction to pointers” Before Class Test 2: Until “linked structures” Before EndSem Test: Everything
  • 35.
    Introduction Structure of aC program How to write C programs Skeleton of a C program
  • 36.
    Introduction Structure of aC program How to write C programs Skeleton of a C program Include header files
  • 37.
    Introduction Structure of aC program How to write C programs Skeleton of a C program Include header files Declare global variables, constants and function prototypes
  • 38.
    Introduction Structure of aC program How to write C programs Skeleton of a C program Include header files Declare global variables, constants and function prototypes Function bodies
  • 39.
    Introduction Structure of aC program How to write C programs Skeleton of a C program Include header files Declare global variables, constants and function prototypes Function bodies There must be a main function in any C program.
  • 40.
    Introduction Structure of aC program An example A complete example #include <stdio.h> #define PI_4_BY_3 4.1887902048 double radius = 10; double sphereVol ( double r ) { return PI_4_BY_3 * r * r * r; } main () { double area; area = sphereVol(radius); printf("Radius = %lf, volume = %lf.n", radius, area); }
  • 41.
    Introduction Some simple Cprograms The traditional starter The traditional starter #include <stdio.h> main () { printf("Hello, world!n"); }
  • 42.
    Introduction Some simple Cprograms The traditional starter The traditional starter #include <stdio.h> main () { printf("Hello, world!n"); } This program takes no input, but outputs the string “Hello, world!” in a line.
  • 43.
    Introduction Some simple Cprograms The short-circuit program The short-circuit program #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",n); }
  • 44.
    Introduction Some simple Cprograms The short-circuit program The short-circuit program #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",n); } This program accepts an integer as input and outputs the same integer.
  • 45.
    Introduction Some simple Cprograms The square finder The square finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",n*n); }
  • 46.
    Introduction Some simple Cprograms The square finder The square finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",n*n); } This program takes an integer n as input and outputs the square n2 of n.
  • 47.
    Introduction Some simple Cprograms A faulty reciprocal finder A faulty reciprocal finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",1/n); }
  • 48.
    Introduction Some simple Cprograms A faulty reciprocal finder A faulty reciprocal finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",1/n); } The division 1/n is of integers (quotient).
  • 49.
    Introduction Some simple Cprograms A faulty reciprocal finder A faulty reciprocal finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%dn",1/n); } The division 1/n is of integers (quotient). The format %d is for printing integers.
  • 50.
    Introduction Some simple Cprograms The correct reciprocal finder The correct reciprocal finder #include <stdio.h> main () { int n; scanf("%d",&n); printf("%fn",1.0/n); }
  • 51.
  • 52.
  • 53.
    Introduction PDS laboratory Log in Gettingstarted Switch on your monitor.
  • 54.
    Introduction PDS laboratory Log in Gettingstarted Switch on your monitor. Switch on your PC.
  • 55.
    Introduction PDS laboratory Log in Gettingstarted Switch on your monitor. Switch on your PC. Allow the machine to boot. Wait until the log in prompt comes.
  • 56.
    Introduction PDS laboratory Log in Gettingstarted Switch on your monitor. Switch on your PC. Allow the machine to boot. Wait until the log in prompt comes. Supply your log-in and password: Login: s<nn> Password: s<nn> Here s is your section (a for 1, b for 2, and so on) <nn> is the number of your PC. This opens your window manager (usually KDE) with icons, the bottom panel, and so on. You are now ready to start your work.
  • 57.
  • 58.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt).
  • 59.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt). Edit your program (new or already existing) by an editor. emacs myprog.c &
  • 60.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt). Edit your program (new or already existing) by an editor. emacs myprog.c & Write your program in the editor and save it.
  • 61.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt). Edit your program (new or already existing) by an editor. emacs myprog.c & Write your program in the editor and save it. Go to the shell and compile your program: cc myprog.c If compilation is successful, an executable called a.out will be created.
  • 62.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt). Edit your program (new or already existing) by an editor. emacs myprog.c & Write your program in the editor and save it. Go to the shell and compile your program: cc myprog.c If compilation is successful, an executable called a.out will be created. Run your program: ./a.out
  • 63.
    Introduction PDS laboratory Edit, compileand run Getting started Click on the terminal icon to open a shell (command prompt). Edit your program (new or already existing) by an editor. emacs myprog.c & Write your program in the editor and save it. Go to the shell and compile your program: cc myprog.c If compilation is successful, an executable called a.out will be created. Run your program: ./a.out Continue your edit-compile-debug-run-debug cycle.
  • 64.
  • 65.
    Introduction PDS laboratory Shut down Gettingstarted Close all the windows you opened.
  • 66.
    Introduction PDS laboratory Shut down Gettingstarted Close all the windows you opened. Log out from your window manager. This leaves you again in the log-in console.
  • 67.
    Introduction PDS laboratory Shut down Gettingstarted Close all the windows you opened. Log out from your window manager. This leaves you again in the log-in console. Select the item to shut down the machine. Wait until the machine completely shuts down.
  • 68.
    Introduction PDS laboratory Shut down Gettingstarted Close all the windows you opened. Log out from your window manager. This leaves you again in the log-in console. Select the item to shut down the machine. Wait until the machine completely shuts down. Switch off your monitor.
  • 69.
  • 70.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor.
  • 71.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c &
  • 72.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area
  • 73.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys
  • 74.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys Save your file before closing emacs.
  • 75.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys Save your file before closing emacs. “File -> Save (Current buffer)”
  • 76.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys Save your file before closing emacs. “File -> Save (Current buffer)” Click the save button (disk)
  • 77.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys Save your file before closing emacs. “File -> Save (Current buffer)” Click the save button (disk) “File -> Save buffer as” (to another file)
  • 78.
    Introduction PDS laboratory Using emacs Usingemacs emacs is a powerful text editor. Run emacs as: emacs myprog.c & Type in your program in the text area Navigate with mouse and cursor keys Save your file before closing emacs. “File -> Save (Current buffer)” Click the save button (disk) “File -> Save buffer as” (to another file) Save your file once in every 15 minutes.
  • 79.
  • 80.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor.
  • 81.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c
  • 82.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter
  • 83.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode
  • 84.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode Hit Esc to exit insert mode
  • 85.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode Hit Esc to exit insert mode When in doubt, it is safe to hit Esc several times to come back to view mode
  • 86.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode Hit Esc to exit insert mode When in doubt, it is safe to hit Esc several times to come back to view mode Navigate with mouse and cursor keys
  • 87.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode Hit Esc to exit insert mode When in doubt, it is safe to hit Esc several times to come back to view mode Navigate with mouse and cursor keys You need to save the file by clicking on the appropriate icon (disk).
  • 88.
    Introduction PDS laboratory Using gvim Usinggvim gvim is another powerful text editor. Run gvim as: gvim myprog.c Hit Insert before you start typing matter You will exit the insert mode if you hit Insert when you are already in the insert mode Hit Esc to exit insert mode When in doubt, it is safe to hit Esc several times to come back to view mode Navigate with mouse and cursor keys You need to save the file by clicking on the appropriate icon (disk). Save your file once in every 15 minutes.
  • 89.
    Introduction PDS laboratory A practiceprogram A practice program #include <stdio.h> char name[100]; int i; main () { printf("Hello, may I know your full name? "); scanf("%s",name); printf("Welcome %s.n",name); printf("Your name printed backward is : "); for (i=strlen(name)-1; i>=0; --i) printf("%c",name[i]); printf("n"); }
  • 90.
    Introduction PDS laboratory A correctedversion A practice program (corrected) #include <stdio.h> char name[100]; int i; main () { printf("Hello, may I know your full name? "); fgets(name,100,stdin); name[strlen(name)-1] = ’0’; printf("Welcome %s.n",name); printf("Your name printed backward is : "); for (i=strlen(name)-1; i>=0; --i) printf("%c",name[i]); printf("n"); }
  • 91.
    Introduction PDS laboratory Using aweb browser Using a web browser
  • 92.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror.
  • 93.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy:
  • 94.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080
  • 95.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080 Bypass proxy for local machines.
  • 96.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080 Bypass proxy for local machines. Type in a URL (web address) in the location field
  • 97.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080 Bypass proxy for local machines. Type in a URL (web address) in the location field http://cse.iitkgp.ac.in/∼pds/
  • 98.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080 Bypass proxy for local machines. Type in a URL (web address) in the location field http://cse.iitkgp.ac.in/∼pds/ http://cse.iitkgp.ac.in/∼pds/semester/2010a/
  • 99.
    Introduction PDS laboratory Using aweb browser Using a web browser Open a web browser: mozilla or konqueror. Set a proxy: 10.3.100.211:8080 10.3.100.212:8080 144.16.192.218:8080 144.16.192.245:8080 144.16.192.247:8080 Bypass proxy for local machines. Type in a URL (web address) in the location field http://cse.iitkgp.ac.in/∼pds/ http://cse.iitkgp.ac.in/∼pds/semester/2010a/ http://cse.iitkgp.ac.in/∼pds/notes/
  • 100.
    Introduction PDS laboratory Assignments andsubmissions Assignments and submissions
  • 101.
    Introduction PDS laboratory Assignments andsubmissions Assignments and submissions Click the link on the day’s assignment.
  • 102.
    Introduction PDS laboratory Assignments andsubmissions Assignments and submissions Click the link on the day’s assignment. If your assignment is a PDF file, save it to your machine.
  • 103.
    Introduction PDS laboratory Assignments andsubmissions Assignments and submissions Click the link on the day’s assignment. If your assignment is a PDF file, save it to your machine. Use xpdf in order to view PDF files. xpdf newassgn.pdf
  • 104.
    Introduction PDS laboratory Assignments andsubmissions Assignments and submissions Click the link on the day’s assignment. If your assignment is a PDF file, save it to your machine. Use xpdf in order to view PDF files. xpdf newassgn.pdf Consult your lab instructor to know how to submit your programs.
  • 105.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands
  • 106.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs
  • 107.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/
  • 108.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../
  • 109.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF
  • 110.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename
  • 111.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename Copy a file to another: cp file1.c file2.c
  • 112.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename Copy a file to another: cp file1.c file2.c Copy a file to a directory: cp file1.c progs/file3.c
  • 113.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename Copy a file to another: cp file1.c file2.c Copy a file to a directory: cp file1.c progs/file3.c Move a file to another: mv file1.c file2.c
  • 114.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename Copy a file to another: cp file1.c file2.c Copy a file to a directory: cp file1.c progs/file3.c Move a file to another: mv file1.c file2.c Move a file to a directory: mv file1.c progs/file3.c
  • 115.
    Introduction PDS laboratory Some usefulUnix commands Some useful Unix commands Create a directory: mkdir progs Go to a new directory: cd progs/ Go to the parent directory: cd ../ List all files in a directory: ls -lF View a file: cat filename Copy a file to another: cp file1.c file2.c Copy a file to a directory: cp file1.c progs/file3.c Move a file to another: mv file1.c file2.c Move a file to a directory: mv file1.c progs/file3.c Delete a file: rm filename