0% found this document useful (0 votes)
5 views19 pages

Data Structures and Algorithms

The document provides an introduction to data structures and algorithms, emphasizing their importance in writing efficient programs. It explains the concepts of data structures, algorithms, and their analysis in terms of time and space complexity, along with the significance of abstract data types and pseudocode. The content is aimed at second-year ECE students to enhance their understanding of data management and programming efficiency.

Uploaded by

aritrak727
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views19 pages

Data Structures and Algorithms

The document provides an introduction to data structures and algorithms, emphasizing their importance in writing efficient programs. It explains the concepts of data structures, algorithms, and their analysis in terms of time and space complexity, along with the significance of abstract data types and pseudocode. The content is aimed at second-year ECE students to enhance their understanding of data management and programming efficiency.

Uploaded by

aritrak727
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Data Structures and Algorithms

Prepared by : Debajyoti Sengupta (IEM faculty)


For 2nd year students of ECE department
Data Structure- Introduction
A correct program should undoubtedly give correct results, but along with
that it should also run efficiently. A program is said to be efficient when it
executes in minimum time and with minimum memory space. In order to
write efficient programs, we need to apply certain data management
concepts.

Data structure is a crucial part of data management and is basically a


group of data elements that are put together under one name, and which
defines a particular way of storing and organizing data in a computer so
that it can be used efficiently.

Think about Dictionaries!


Data Structure- Introduction

▪ Each Data Structure allows data to be stored in a specific manner.

▪ Data Structure allows efficient data search and retrieval.

▪ Specific Data Structures are decided to work for specific problems.


Data Structure- Introduction
What is an Algorithm?
An algorithm is a well-defined computational procedure that
transforms inputs into outputs achieving the desired input-output
relationship. We must design a process to solve a specific problem
before programming. This process must be formulated as a
detailed sequence of basic/elementary steps, which is called an
algorithm.
What is an Algorithm?
What is an Algorithm?

The input to Algorithm 1 is a sequence of integers. The output is the largest integer in the
sequence. Each step of the algorithm is precisely defined, because only assignments, a finite loop,
and conditional statements occur. To show that the algorithm is correct, we must show that when
the algorithm terminates, the value of the variable max equals the maximum of the terms of the
sequence. To see this, note that the initial value of max is the first term of the sequence; as
successive terms of the sequence are examined, max is updated to the value of a term if the term
exceeds the maximum of the terms previously examined. This argument shows that when all the
terms have been examined, max equals the value of the largest term.
What is an Algorithm?

The algorithm uses a finite number of steps, because it terminates after all the
integers in the sequence have been examined. The algorithm can be carried out in a
finite amount of time because each step is either a comparison or an assignment,
there are a finite number of these steps, and each of these two operations takes a
finite amount of time. Finally, Algorithm 1 is general, because it can be used to find
the maximum of any finite sequence of integers.
Analysis of Algorithms
Suppose P is a problem and A & B are two different algorithms to solve the problem P.
There must have some performance measurement system to decide that which
algorithm is better than the other.

Suppose M is an algorithm and n is the size of the input data. The time and space used
by the algorithm M are two main measures for the efficiency of M.

Therefore, the performance of the algorithm can be measured on the scales of time
and space. Time means, we are looking for the fastest algorithm for the problem.
Space means we are looking for an algorithm that consumes or needs minimum
memory space for its execution.

When performance is measured in terms of space, it is known as Space complexity


and when performance is measured in terms of time, it is termed as Time complexity.
Analysis of Algorithms
There are a number of algorithms that will solve a problem. Studying the analysis of
algorithms gives us the tools to choose between algorithms. For example, consider the
following two algorithms to find the largest of four values:
Analysis of Algorithms
a>b

a>c b>c

a>d b>d c>d


c>d

Return a Return d Return c Return d


Analysis of Algorithms

If you examine these two algorithms, you will see that each
one will do exactly three comparisons to find the answer.
Even though the first is easier for us to read and
understand, they are both of the same level of complexity
for a computer to execute. In terms of time, these two
algorithms are the same, but in terms of space, the first
needs more because of the temporary variable called
largest.
Data Structure- Introduction

A program is a set of instructions, which involve a computer performing some


kind of computation or algorithm. Data Structure affects the design of both
structural and functional aspects of a program. To implement a program of an
algorithm, we should select an appropriate data structure for that algorithm.

Algorithm + Data Structure = Program


Data Structure- Introduction

Data type : Data type of a variable is the set of values that the variable can take.
We have already read the basic data types in C include int, char, float, and
double. When we talk about a primitive type (built-in data type), we actually
consider two things: a data item with certain characteristics and the permissible
operations on that data. For example, an int variable can contain any whole-
number value from –32768 to 32767 and can be operated with the operators +,
–, *, and /. In other words, the operations that can be performed on a data
type are an inseparable part of its identity. Therefore, when we declare a
variable of an abstract data type (e.g., stack or a queue), we also need to specify
the operations that can be performed on it.
Data Structure- Introduction

An Abstract Data Type (ADT) is the way we look at a data structure,


focusing on what it does and ignoring how it does its job. For example,
stacks and queues are perfect examples of an ADT. We can implement both
these ADTs using an array or a linked list. This demonstrates the ‘abstract’
nature of stacks and queues.

Abstract:

The word ‘abstract’ in the context of data structures means considered apart
from the detailed specifications or implementation.
Data Structure- Introduction

Abstract Data Type (ADT)


For example, when we use a stack or a queue, the user is
concerned only with the type of data and the operations that can
be performed on it. Therefore, the fundamentals of how the data
is stored should be invisible to the user. They should not be
concerned with how the methods work or what structures are
being used to store the data. They should just know that to work
with stacks, they have push() and pop() functions available to
them. Using these functions, they can manipulate the data
(insertion or deletion) stored in the stack.
Well its Abstract!

The Abstract View and NOT the Implementation View


What is Pseudo Code?
In computer science, pseudocode is a plain language description of
the steps in an algorithm. It is intended for human reading rather
than machine reading. It typically omits details that are essential
for machine understanding of the algorithm, such as variable
declarations and language-specific code.

The purpose of using pseudocode is that it is easier for people to


understand than conventional programming language code, and
that it is an efficient and environment-independent description of
the key principles of an algorithm.
What is Pseudo Code?

You might also like