0% found this document useful (0 votes)
2K views

C and Data Structures Report

The document is a training report submitted by Ms. Premlata yadav for her summer training course on C Language and Data Structures from ORBIT Computer Educations from June 2nd to August 1st. The training involved learning C language fundamentals like data types, loops, arrays, pointers and strings as well as basic data structures like arrays, linked lists, stacks, queues and sorting and searching techniques. The report acknowledges the training institute and trainer for their guidance and support in helping her complete the course.

Uploaded by

Mukesh Atthuluri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

C and Data Structures Report

The document is a training report submitted by Ms. Premlata yadav for her summer training course on C Language and Data Structures from ORBIT Computer Educations from June 2nd to August 1st. The training involved learning C language fundamentals like data types, loops, arrays, pointers and strings as well as basic data structures like arrays, linked lists, stacks, queues and sorting and searching techniques. The report acknowledges the training institute and trainer for their guidance and support in helping her complete the course.

Uploaded by

Mukesh Atthuluri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

NATIONAL INSTITUTE OF TECHNOLOGY

KURUKSHETRA

TRAINING REPORT FILE


TOPIC: c-Language and Data structures

SUBMITTED TO: SUBMITTED BY:


JARUPULA ANIL Ms. Premlata yadav
ROLL NO:11610576
SECTION: IT-5
Introduction :
For my summer training, I pursued a course on “Data Structure and C-Language“ from ORBIT Computer
Educations . This is a course on C-Language and Data Structures which started on 02-06-2018 and completed
on 01-08-2018, this summer. The course is for all those who are looking forward to sit for internships and
placements in August. The course involves rigorous practice of questions based on Sorting, Searching, etcalong
with comprehensive revision of data structures.
ACKNOWLEDGEMENT

First I would like to thank ORBIT Computer Educations, HYDERABAD for giving me an opportunity as to enroll
in the well planned course. I surely have learnt a lot from here. I encouraged brilliant practical learning through real
time testing and coding, which is impossible to achieve through books. I hope that everything I have learnt here will
be helpful in future.

I take this opportunity to express my deep sense of gratitude to Mr. Bala Krishna for his immense support and
guidance. He has helped me throughout and acted as our guide. I would like to thank him for having immense
patience while teaching me about algorithms and giving his precious time to me.

I would also like to thank all my friends who helped me throughout the course by giving their valuable time and
guidelines to complete the course, and so many other countless people of ORBIT Team for helping me during my
course.

ANIL JARUPULA

11610576

IT-5

National Institute of Technology, Kurukshetra

Purpose
Logic Building

Coding in its most essential form is nothing but problem solving. It deals with figuring out logical solutions and
implementing them optimally. The process of learning to code, transforms a person into an analytical thinker with
strong mathematical and logical skills.

Career Transformation
Having been a standalone field for a long time, the software industry has now come neck to neck with most of the
other industries by close coordination and easy integration. From the smallest light bulb to the most massive
aircrafts, every industry is now implementing the use of computer programming for the convenience of the end user.
A good command over coding can thus open a wide variety of employment opportunities.

Global Impact

Computer programming these days is also being used to address some of the biggest issues that humankind is facing
with like climate change, healthcare, education and many more. More than being a developer or a designer,
knowledge of coding can also help you become the harbinger of the change that you want to see.

Computational Thinking

Computational Thinking is the ability to communicate your thoughts in a structured and logical way. This type of
thought process is like the step by step instructions that are coded into a computer. It is also the process of thinking
up and then solving problems in a methodical way that could be replicated by a machine. Software engineers,
computer programmers, and logistics specialists use this method of thinking to solve problems. Computational
thinking is a combination of advanced mathematics, algorithm development and logic. The development of
computational thinking involves considering a problem and breaking it down into single-action steps. Each of these
steps is handled in the most efficient way possible. There is also an element of abstraction in computationalthinking,
which allows your child to move from a specific solution to a specific problem and generalize it to other situations.
The result is a paradigm shift in thinking about how the world works.

About ORBIT

ORBIT is a privately-held company based in Hyderabad, India. Since 2008, we have been helping IT professionals
get better at what they do by providing an extensive range of training services on emerging technologies. Always
pushing the envelope, we are constantly exploring new fields of knowledge as well as new training methodologies to
better serve our clients.The company is led by a team of experts , with accumulated experience of tens of years of
software development, architectural design and project management. The team has provided most authentic,
comprehensive and high quality training services to good number of companies in recent years, ranging from small
start-ups to large enterprises.

We pride ourselves by standing by our commitment to help IT professionals get to the next level, by being in tune
with our customers' actual needs, and by always delivering on what we promise, all while having fun doing it.

Always pushing the envelope, we are constantly exploring new fields of knowledge as well as new training
methodologies to better serve our clients.
ORBIT trains with the aim of creating "Innovative Software Engineers" who can solove problems with ease. Some
of his time will be given to consulting engaments of corporates. It likes to teach Problem solving & Cutting edge
technology courses that impacts practical development/design/architecturing..

Upon successful completion of course, participants will be able to:

Enhance Thinking process


Crack any product company interview/written tests
Understand the practical application of problems&their impact on software products
Think through the solution techniques to any problem
Improve the analysis skills of the algorithms generated by themselves/others
Enhance the coding skills to maximum possible level

CONTENT

• INTRODUCTION

• Introduction of c

• Data Structures and its applications

• Contents in C

• Integer Types

• Floating point Types

• Loops:C

• Arrays

• Pointers in c

• Strings in c

• Structures in c

• Union

• BASIC DATA STRUCTURES

• Arrays

• Linked List
• Stacks

• Queue

• Sorting techniques

• Searching techniques

• INTRODUCTION

• INTRODUCTION OF C :

C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the
UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.

In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as
the K&R standard.

The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in
C. C has now become a widely used professional language for various reasons −

• Easy to learn

• Structured language

• It produces efficient programs

• It can handle low-level activities

• It can be compiled on a variety of computer platforms

Facts about C :
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around the early 1970s.

• The language was formalized in 1988 by the American National Standard Institute (ANSI).

• The UNIX OS was totally written in C.

• Today C is the most widely used and popular System Programming Language.

• Most of the state-of-the-art software have been implemented using C.

Today's most popular Linux OS and RDBMS MySQL have been written in C.

Why to use C ?
C was initially used for system development work, particularly the programs that make-up the operating system. C
was adopted as a system development language because it produces code that runs nearly as fast as the code written
in assembly language. Some examples of the use of C might be −

• Operating Systems

• Language Compilers

• Assemblers

• Text Editors

C Programs
A C program can vary from 3 lines to millions of lines and it should be written into one or more text files with
extension ".c"; for example, hello.c.

A C program basically consists of the following parts −

• Preprocessor Commands

• Functions

• Variables

• Statements & Expressions

• Comments

Hello World Example

#include <stdio.h>

int main() {

printf("Hello World \n");

return 0;
}

• The first line of the program #include<stdio.h> is a preprocessor command, which tells a C compiler to
include stdio.h file before going to actual compilation.

• The next line intmain() is the main function where the program execution begins.

• The next line printf(...) is another function available in C which causes the message "Hello World" to be
displayed on the screen.

• The next line return 0; terminates the main() function and returns the value 0.

Output:Hello World .

• DATA STRUCTURES & THEIR APPLICATIONS :

A data structure is a way to store and organize data in order to facilitate access and modifications. More
precisely, a data structure is a collection of data values, the relationships among them, and the functions or
operations that can be applied to the data. No single data structure works well for all purposes, and so it is
important to know the strengths and limitations of several of them.

• Usage

Different kinds of data structures are suited to different kinds of applications, and some are highly
specialized to specific tasks. For example, relational databases commonly use B-tree indexes for data
retrieval while compiler implementations usually use hash tables to look up identifiers.

Data structures provide a means to manage large amounts of data efficiently for uses such as
large databases and internet indexing services. Usually, efficient data structures are key to designing
efficient algorithms. Some formal design methods and programming languages emphasize data structures,
rather than algorithms, as the key organizing factor in software design. Data structures can be used to
organize the storage and retrieval of information stored in both main memory and secondary memory.

• Implementation

Data structures are generally based on the ability of a computer to fetch and store data at any place
in its memory, specified by a pointer—a bit string, representing a memory address, that can be itself stored
in memory and manipulated by the program. Thus, the array and record data structures are based on
computing the addresses of data items with arithmetic operations; while the linked data structures are based
on storing addresses of data items within the structure itself. Many data structures use both principles,
sometimes combined in non-trivial ways

• DATA TYPES IN C:

Data types in c are used for declaring variables or functions of different types. The type of a variable
determines how much space it occupies in storage and how the bit pattern stored is interpreted.

The types in C can be classified as follows −

Sr.No. Types & Description

1 Basic Types:

They are arithmetic types and are further classified into: (a) integer types and (b) floating-point
types.

2 Enumerated types

They are again arithmetic types and they are used to define variables that can only assign certain
discrete integer values throughout the program.

3 The type void

The type specifier void indicates that no value is available.

4 Derived types

They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e)
Function types.

• Integer Types :
The following table provides the details of standard integer types with their storage sizes and value ranges –

Type Storage size Value range


char 1 byte -128 to 127 or 0 to 255

unsigned char 1 byte 0 to 255

signed char 1 byte -128 to 127

int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647

unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295

short 2 bytes -32,768 to 32,767

unsigned short 2 bytes 0 to 65,535

long 4 bytes -2,147,483,648 to 2,147,483,647

unsigned long 4 bytes 0 to 4,294,967,295

To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The
expressions size of(type) yields the storage size of the object or type in bytes.

• Floating-Point Types :
The following table provide the details of standard floating-point types with storage sizes and value ranges and their
precision –

Type Storage size Value range Precision

float 4 byte 1.2E-38 to 3.4E+38 6 decimal places

double 8 byte 2.3E-308 to 1.7E+308 15 decimal places

long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

• LOOPS: C

when a block of code needs to be executed several number of times. In general, statements are executed
sequentially: The first statement in a function is executed first, followed by the second, and so on.

Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times. Given below is the
general form of a loop statement in most of the programming languages −

C programming language provides the following types of loops to handle looping requirements.

Sr.No. Loop Type & Description

1 while loop: Repeats a statement or group of statements while a given condition is true. It tests the
condition before executing the loop body.

2 for loop: Executes a sequence of statements multiple times and abbreviates the code that manages
the loop variable.

3 do...while loop: It is more like a while statement, except that it tests the condition at the end of the
loop body.

4 nested loops: You can use one or more loops inside any other while, for, or do..while loop.

Loop Control Statements:


Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic
objects that were created in that scope are destroyed.

C supports the following control statements.

Sr.No. Control Statement & Description

1 break statement: Terminates the loop or switch statement and transfers execution to the statement
immediately following the loop or switch.

2 continuestatement:Causes the loop to skip the remainder of its body and immediately retest its
condition prior to reiterating.

3 goto statement: Transfers control to the labeled statement.

The Infinite Loop :


A loop becomes an infinite loop if a condition never becomes false. The forloop is traditionally used for this
purpose. Since none of the three expressions that form the 'for' loop are required, you can make an endless loop by
leaving the conditional expression empty.

#include <stdio.h>

int main () {

for( ; ; ) {

printf("This loop will run forever.\n");

} return 0;

When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment
expression, but C programmers more commonly use the for(;;) construct to signify an infinite loop.

NOTE − You can terminate an infinite loop by pressing Ctrl + C keys.

• ARRAYS:

Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An
array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables
of the same type.

Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array
variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A
specific element in an array is accessed by an index.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the
highest address to the last element.
Declaring Arrays in C :
To declare an array in C, a programmer specifies the type of the elements and the number of elements required by
an array as follows –

typearrayName [ arraySize ];

This is called a single-dimensional array. The arraySize must be an integer constant greater than zero and type can
be any valid C data type. For example, to declare a 10-element array called A of type int, use this statement –

IntA[10]

Here A is a variable array which is sufficient to hold up to 10 integers.

Initializing Arrays :
You can initialize an array in C either one by one or using a single statement as follows −

int A[5]={100,20,30,40,50};

The number of values between braces { } cannot be larger than the number of elements that we declare for the
array between square brackets [ ].

Accessing Array Elements :


An element is accessed by indexing the array name. This is done by placing the index of the element within square
brackets after the name of the array. For example −

Int b=A[5];

The above statement will take the 5th element from the array and assign the value to b variable.

• POINTERS in C:

Pointers in C are easy and fun to learn. Some C programming tasks are performed more easily with pointers, and
other tasks, such as dynamic memory allocation, cannot be performed without using pointers. So it becomes
necessary to learn pointers to become a perfect C programmer. Let's start learning them in simple and easy steps.

As you know, every variable is a memory location and every memory location has its address defined which can be
accessed using ampersand (&) operator, which denotes an address in memory. Consider the following example,
which prints the address of the variables defined −

#include <stdio.h>
int main () {

int var1;

char var2[10];

printf("Address of var1 variable: %x\n", &var1 );

printf("Address of var2 variable: %x\n", &var2 );

return 0;

When the above code is compiled and executed, it produces the following result-

Address of var1 variable: bff5a400

Address of var2 variable: bff5a3f6

What are Pointers ?


A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location.
Like any variable or constant, you must declare a pointer before using it to store any variable address. The general
form of a pointer variable declaration is −

type *var-name;

Here, type is the pointer's base type; it must be a valid C data type and var-name is the name of the pointer
variable. The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this
statement the asterisk is being used to designate a variable as a pointer

The actual data type of the value of all pointers, whether integer, float, character, or otherwise, is the same, a long
hexadecimal number that represents a memory address. The only difference between pointers of different data
types is the data type of the variable or constant that the pointer points to.

NULL Pointers
It is always a good practice to assign a NULL value to a pointer variable in case you do not have an exact address
to be assigned. This is done at the time of variable declaration. A pointer that is assigned NULL is called
a nullpointer.

The NULL pointer is a constant with a value of zero defined in several standard libraries. Consider the following
program −

#include <stdio.h>

int main () {
int *ptr = NULL;

printf("The value of ptr is : %x\n", ptr );

return 0;

When the above code is compiled and executed, it produces the following result –the value of ptr is 0.

In most of the operating systems, programs are not permitted to access memory at address 0 because that memory
is reserved by the operating system. However, the memory address 0 has special significance; it signals that the
pointer is not intended to point to an accessible memory location. But by convention, if a pointer contains the null
(zero) value, it is assumed to point to nothing.

• STRINGS in C:

Strings are actually one-dimensional array of characters terminated by a nullcharacter '\0'. Thus a null-terminated
string contains the characters that comprise the string followed by a null.

The following declaration and initialization create a string consisting of the word "Hello". To hold the null
character at the end of the array, the size of the character array containing the string is one more than the number of
characters in the word "Hello."

char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

If you follow the rule of array initialization then you can write the above statement as follows −

char greeting[] = "Hello";

Following is the memory presentation of the above defined string in C/C++ −

Actually, you do not place the null character at the end of a string constant. The C compiler automatically places
the '\0' at the end of the string when it initializes the array. Let us try to print the above mentioned string −

#include <stdio.h>

int main () {

char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};


printf("Greeting message: %s\n", greeting );

return 0;

When the above code is compiled and executed, it produces the following result

Output: Greeting message: Hello

C supports a wide range of functions that manipulate null-terminated strings −

Sr.No. Function & Purpose

1 strcpy(s1, s2); Copies string s2 into string s1.

2 strcat(s1, s2); Concatenates string s2 onto the end of string s1.

3 strlen(s1); Returns the length of string s1.

4 strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.

5 strchr(s1, ch); Returns a pointer to the first occurrence of character ch in string s1.

6 strstr(s1, s2); Returns a pointer to the first occurrence of string s2 in string s1.

• STRUCTURES in C:

Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is
another user defined data type available in C that allows to combine data items of different kinds.Structures are
used to represent a record.

Defining a Structure :
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more
than one member. The format of the struct statement is as follows −

struct [structure tag] {

member definition;
member definition;

...

member definition;

} [one or more structure variables];

The structure tag is optional and each member definition is a normal variable definition, such as int i; or float f; or
any other valid variable definition. At the end of the structure's definition, before the final semicolon, you can
specify one or more structure variables but it is optional.

• UNION:

A union is a special data type available in C that allows to store different data types in the same memory location.
You can define a union with many members, but only one member can contain a value at any given time. Unions
provide an efficient way of using the same memory location for multiple-purpose.

Defining a Union :
To define a union, you must use the union statement in the same way as you did while defining a structure. The
union statement defines a new data type with more than one member for your program. The format of the union
statement is as follows −

union [union tag] {

member definition;

member definition;

...

member definition;

} [one or more union variables];

The union tag is optional and each member definition is a normal variable definition, such as int i; or float f; or any
other valid variable definition. At the end of the union's definition, before the final semicolon, you can specify one
or more union variables but it is optional.

3. BASIC DATA STRUCTURES


• Array:Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the
same type. An array is used to store a collection of data, but it is often more useful to think of an array as a
collection of variables of the same type.

Applications:

• Stores Elements of Same Data Type

• Array Can be Used for Sorting Elements

• Array Can be Used in CPU Scheduling.

• Linked List: Linked list is a linear collection of data elements, in which linear order is not given by
their physical placement in memory. Instead, each element points to the next. It is a data
structure consisting of a group of nodes which together represent a sequence.

Applications:

• Linked Lists can be used to implement Stacks , Queues.

• Linked Lists can also be used to implement Graphs. (Adjacency list representation of Graph).

• Implementing Hash Tables :- Each Bucket of the hash table can itself be a linked list. (Open chain
hashing.

• Stack :A stack is an abstract data type that serves as a collection of elements, with two principal
operations:
• push, which adds an element to the collection, and
• pop, which removes the most recently added element that was not yet removed.
The order in which elements come off a stack gives rise to its alternative name, LIFO (last in, first out).
Applications :
• Expression evaluation

• Backtracking (game playing, finding paths, exhaustive searching)

• Memory management, run-time environment for nested language features.

2.3. Queue : A queue is a particular kind of ADT in which the entities in the collection are
kept in order and the principle (or only) operations on the collection are the addition of entities to
the rear terminal position, known as enqueue, and removal of entities from the front terminal
position, known as dequeue. This makes the queue a FIFO data structure

Applications :

• When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk
Scheduling..

• When data is transferred asynchronously (data not necessarily received at same rate as sent)
between two processes. Examples include IO Buffers, pipes, file IO, etc.

• Sorting techniques ;

• Puts elements of a list in an order

• Often implemented before search or merge

• One of the oldest data structure in computer science

• Internal or external
• E.g ;quick sort, selection sort, bubble sort, insertion sort

• Practical sorting is based on average complexity

3.5.1) Selection sort

• simplest method of sorting

• sorts data in place

• 0th element compared with all elements and swapped if its found to be greater

• Each iteration fixates lowest element at relatively top position

• For an array of n elements it takes (n-1) iteration to sort

3.5.2) Bubble sort

• Also known as sinking sort

• 0th element compared with 1st element and swapped it its found to be greater

• Then first element is compare with 2nd and the process continues

• Each iteration fixates highest element at relative bottom position

• For an array of n elements it takes (n-1) iteration to sort

• Searching

• To find an item in a collection

• Can be a hit or miss,brute force or divide and conquer

• Internet ,data base ,spread sheet,word processor

• May need the data to be sorted

• Analysis and efficiency based on no of comparisions

3.6.1) linear search

• Simplest search algorithm


• Used mostly with smaller or unordered list

• No of comparisions can be reduced by using a sentinel value at the end of the list

3.6.2) Binary search

• One of the fast and efficient

• Requires list to be sorted

• Uses divide and conquer using binary tree

• Checks center element in the list ,if not a match then list is divided into two halves ,left and right

• Comparing and dividing continues till element is found or no more elements

You might also like