0% found this document useful (0 votes)
6 views22 pages

U1 L1 Introduction

The document explains the concepts of data, information, and data structures, highlighting the importance of organizing data for effective use. It covers the classification of data structures into linear and non-linear types, basic operations performed on data structures, and the characteristics of algorithms. Additionally, it provides guidance on writing algorithms and emphasizes their role in problem-solving within programming.

Uploaded by

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

U1 L1 Introduction

The document explains the concepts of data, information, and data structures, highlighting the importance of organizing data for effective use. It covers the classification of data structures into linear and non-linear types, basic operations performed on data structures, and the characteristics of algorithms. Additionally, it provides guidance on writing algorithms and emphasizes their role in problem-solving within programming.

Uploaded by

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

INTRODUCTION

DATA STRUCTURE =
DATA
+
STRUCTURE
DATA

Data is raw numbers, letters, symbols, sounds or images with no meaning.


Basic Building block – Raw Data
Collection of facts in raw and unorganized form

The data P952BR could have several meanings.


It could possibly be:
• a product code
• a postal / ZIP code
• a car registration number.

As it is not known what the data means, it is meaningless.


INFORMATION – who, what,
where, when
• When data items are given context and
meaning, they become information.
• A person reading the information will
then know what it means.
• For the data to become information, it
needs to be given meaning.
• Data is given context by identifying
what sort of data it is. This still does
not make it information but it is a step
on the way to it becoming information
as shown in the example.
Structure: Way of organizing information, so that it is
easier to use

In simple words we can define data structures as

• Its a way organizing data in such a way so that data


can be easier to use.
DATA STRUCTURE

Data Structure is a way of collecting and organizing data in such a way that we can
perform operations on these data in an effective way.
or
In simple language, Data Structures are structures programmed to store ordered
data, so that various operations can be performed on it easily.

It represents the knowledge of data to be organized in memory.

It should be designed and implemented in such a way that it reduces the complexity
and increases the efficiency.
Need of Data Structures
As applications are getting complexed and amount of data is increasing day by
day, there may arrise the following problems:

Processor speed: To handle very large amout of data, high speed processing is
required, but as the data is growing day by day to the billions of files per entity,
processor may fail to deal with that much amount of data.

Data Search: Consider an inventory size of 106 items in a store, If our application
needs to search for a particular item, it needs to traverse 106 items every time,
results in slowing down the search process.

Multiple requests: If thousands of users are searching the data simultaneously


on a web server, then there are the chances that a very large server can be failed
during that process
Data Structure Classification
Linear Data Structures: A data structure is called linear if all of its
elements are arranged in the linear order. In linear data structures, the
elements are stored in non-hierarchical way where each element has the
successors and predecessors except the first and last element.
or
A linear data structure traverses the data elements sequentially, in
which only one data element can directly be reached. Ex: Arrays, Linked
Lists

Non Linear Data Structures: This data structure does not form a
sequence i.e. each item or element is connected with two or more other
items in a non-linear arrangement. The data elements are not arranged in
sequential structure. Ex: Tree, Graphs
DATA STRUCTURE – BASIC OPERATIONS

1. Insertion: Insertion means addition of a new data element in a


data structure.

2. Deletion: Deletion means removal of a data element from a


data structure if it is found.

3. Searching: Searching involves searching for the specified data


element in a data structure.

4. Traversal: Traversal of a data structure means processing all


the data elements present in it.
DATA STRUCTURE – BASIC OPERATIONS

5. Sorting: Arranging data elements of a data structure in a


specified order is called sorting.

6. Merging: Combining elements of two similar data structures


to form a new data structure of the same type, is called
merging.

7. Copying: Changing the location of data.

8. Updation: Replacing data without altering size of data


stucture
BASIC CONCEPTS OF ALGORITHMS

A typical programming task can be divided into two phases:

 Problem solving phase


 produce an ordered sequence of steps that describe solution of
problem
 this sequence of steps is called an algorithm

 Implementation phase
 implement the program in some programming language
STEPS IN PROBLEM SOLVING

 First produce a general algorithm (one can use pseudo code)

 Refine the algorithm successively to get step by step detailed algorithm


that is very close to a computer language.

 Pseudo code is an artificial and informal language that helps


programmers develop algorithms. Pseudo code is very similar to
everyday English.
 Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks.

Pseudo code: Algorithm:

 Input a set of 4 marks


S1: Input M1,M2,M3,M4
 Calculate their average by summing and S2: GRADE (M1+M2+M3+M4)/4
dividing by 4 S3: if (GRADE < 50) then
 if average is Print “FAIL”
below 50 Print else
“FAIL” Print “PASS”
else endif
Print
“PASS”
PSEUDOCODE

 Pseudocode is an artificial and informal language that helps programmers


develop algorithms.
 Pseudocode is an informal high-level description of the operating principle of a
computer program or other algorithm.
 It can use the structural conventions of a normal programming language, but is
intended for human reading rather than machine reading.
 The pseudocode notation specifies operations that a machine can perform in as
human-friendly (e.g., easy to read) way as possible, while avoiding ambiguity.
ALGORITHM
 Recipe, process, method, technique, procedure, routine,…

Many Real-Life Examples


Cooking: Recipe for preparing a dish
Origami: The Art of Paper Folding
Directions: How to go to Delhi from Jaipur

 Algorithm is a step by step procedure, which defines a set of


instructions to be executed in certain order to get the desired output.

 Algorithms are generally created independent of underlying languages,


i.e. an algorithm can be implemented in more than one programming
language.
Let's understand the algorithm through a real-world example. Suppose we
want to make a lemon juice, so following are the steps required to make a
lemon juice:
Step 1: First, we will cut the lemon into half.
Step 2: Squeeze the lemon as much you can and take out its juice in a
container.
Step 3: Add two tablespoon sugar in it.
Step 4: Stir the container until the sugar gets dissolved.
Step 5: When sugar gets dissolved, add some water and ice in it.
Step 6: Store the juice in a fridge for 5 to minutes.
Step 7: Now, it's ready to drink.
The above real-world can be directly compared to the definition of the
algorithm. We cannot perform the step 3 before the step 2, we need to
follow the specific order to make lemon juice. An algorithm also says that
each and every instruction should be followed in a specific order to
perform
a specific task.
ALGORITHM
 From data structure point of view, following are
some important categories of algorithms −

 Search − Algorithm to search an item in a data structure.


 Sort − Algorithm to sort items in certain order
 Insert − Algorithm to insert item in a data structure
 Update − Algorithm to update an existing item in a data structure
 Delete − Algorithm to delete an existing item from a data structure
CHARACTERISTICS OF AN ALGORITHM
 An algorithm should have the below characteristics
 Unambiguous/Definiteness − Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their input/outputs should be clear and must lead to only one
meaning.
 Input − An algorithm should have 0 or more well defined inputs.
 Output − An algorithm should have 1 or more well defined outputs, and should match
the desired output.
 Finiteness − Algorithms must terminate after a finite number of steps.
 Effectiveness− steps are sufficiently simple and basic.
 Feasibility− Should be feasible with the available resources.
 Independent − An algorithm should have step-by-step directions which should be
independent of any programming code.
HOW TO WRITE AN ALGORITHM ??
• There are no well-defined standards for writing algorithms. Rather, it is problem and
resource dependent.

• Algorithms are never written to support a particular programming code.

• As we know that all programming languages share basic code constructs like loops
(do, for, while), flow-control (if-else), etc. These common constructs can be used to
write an algorithm.

• Algorithm writing is a process and is executed after the problem domain is well-
defined. That is, we should know the problem domain, for which we are designing a
solution.
EXAMPLES

• Problem − Design an algorithm to add two numbers and display the


result.

• START/BEGIN Step 1 − START


• DECLARE: Step 2 − declare three integers a, b & c
• Define/read Step 3 − define values of a & b a=5,b=10
• Print/write Step 4 − add values of a & b =a+b
Step 5 − store output of step 4 to c c=a+b
• STOP/END Step 6 − print c
Step 7 − STOP
EXAMPLES
Algorithms tell the programmers how to code the program. Alternatively,
the algorithm can be written as −

Step 1 − START ADD


Step 2 − get values of a & b
Step 3 − c ← a + b
Step 4 − display c
Step 5 − STOP
 We design an algorithm to get solution of a given problem. A problem
can be solved in more than one ways.

Hence, many solution algorithms can be derived for a given problem. The next step is to
analyze those proposed solution algorithms and implement the best suitable solution.

You might also like