Ravin DR

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Array

Often, we have to deal with groups of objects of same type such


as names of persons, instrument readings in an experiment, roll
numbers of students, and so on. These groups can be
conveniently represented as elements of arrays. An array is
defined as a sequence of objects of the same data type. All the
elements of an array are either of type int (whole numbers), or
all of them are of type char, or all of them are of floating
decimal point type, etc. An array cannot have a mixture of
different data types as its elements. Also, array elements cannot
be functions; however, they may be pointers to functions. In
computer memory, array elements are stored in a sequence of
adjacent memory blocks. Since all the elements of an array are
of same data type, the memory blocks allocated to elements of
an array are also of same size. Each element of an array
occupies one block of memory. The size of memory blocks
allocated depends on the data type and it is same as for
different data types.

Declaration & Data Types


Arrays have the same data types as variables, i.e., short, long, float etc.
They are similar to variables: they can either be declared global or local.
They are declared by the given syntax:
Data type array_name[size];

Name:-ravindranath soren
b.roll:-16301060037

Page 1 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 2 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 3 of 18
Sorting Techniques
Sorting refers to arranging data in a particular format. Sorting
algorithm specifies the way to arrange data in a particular order.
Most common orders are in numerical or lexicographical order.
The importance of sorting lies in the fact that data searching can
be optimized to a very high level, if data is stored in a sorted
manner. Sorting is also used to represent data in more readable
formats. Following are some of the examples of sorting in real-
life scenarios −

• Telephone Directory − The telephone directory


stores the telephone numbers of people sorted by their
names, so that the names can be searched easily.
• Dictionary − The dictionary stores words in an
alphabetical order so that searching of any word becomes
easy.

Name:-ravindranath soren
b.roll:-16301060037

Page 4 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 5 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 6 of 18
Stack
A stack is an Abstract Data Type (ADT), commonly used in
most programming languages. It is named stack as it behaves
like a real-world stack, for example – a deck of cards or a pile
of plates, etc.
A real-world stack allows operations at one end only. For
example, we can place or remove a card or plate from the top
of the stack only. Likewise, Stack ADT allows all data operations
at one end only. At any given time, we can only access the top
element of a stack.
This feature makes it LIFO data structure. LIFO stands for Last-
infirst-out. Here, the element which is placed (inserted or
added) last, is accessed first. In stack terminology, insertion
operation is called PUSH operation and removal operation is
called POP operation.

Name:-ravindranath soren
b.roll:-16301060037

Page 7 of 18
Name:- ravindranath soren
b.roll:-16301060037

Page 8 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 9 of 18
Queue
Queue is an abstract data structure, somewhat similar to Stacks. Unlike
stacks, a queue is open at both its ends. One end is always used to insert
data (enqueue) and the other is used to remove data (dequeue). Queue
follows First-In-First-Out methodology, i.e., the data item stored first will
be accessed first.
A real-world example of queue can be a single-lane one-way road, where
the vehicle enters first, exits first. More real-world examples can be seen
as queues at the ticket windows and bus-stops. understand the basic
operations associated with queues − enqueue() − add (store) an
item to the queue Basic Operations
• Queue operations may involve initializing or defining the

queue, utilizing it, and then completely erasing it from the


memory. Here we shall try to.
dequeue() − remove (access) an item from the queue.

Name:-ravindranath soren
b.roll:-16301060037

Page 10 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 11 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 12 of 18
Linked List
A linked list is a sequence of data structures, which are
connected together via links.
Linked List is a sequence of links which contains items. Each
link contains a connection to another link. Linked list is the
second most-used data structure after array. Following are the
important terms to understand the concept of Linked List.
• Link − Each link of a linked list can store a data called an
element.
• Next − Each link of a linked list contains a link to the next link
called Next.
• LinkedList − A Linked List contains the connection link to the
first link called First.

Name:-ravindranath soren
b.roll:-16301060037

Page 13 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 14 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 15 of 18
Recursion
Recursion is the process of repeating items in a self-similar way. In programming
languages, if a program allows you to call a function inside the same function, then
it is called a recursive call of the function.

void recursion() { recursion();


/* function calls itself */
}

int main() { recursion();


}

The C programming language supports recursion, i.e., a function to call itself. But
while using recursion, programmers need to be careful to define an exit condition
from the function, otherwise it will go into an infinite loop.
Recursive functions are very useful to solve many mathematical problems, such as
calculating the factorial of a number, generating Fibonacci series, etc.

Number Factorial
The page 17 example calculates the factorial of a given number using a
recursive function
− Fibonacci Series
The page 18 example generates the Fibonacci series for a given number
using a recursive function −

Name:-ravindranath soren
b.roll:-16301060037

Page 16 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 17 of 18
Name:-ravindranath soren
b.roll:-16301060037

Page 18 of 18

You might also like