0% found this document useful (0 votes)
24 views43 pages

Chapter 1

The document provides an overview of data structures, including definitions, types, and operations such as traversing and searching. It covers algorithms, pseudocode, and flowcharts as methods for problem-solving in programming. Additionally, it distinguishes between primitive and non-primitive data structures and outlines the environment setup for implementing data structures in C++.

Uploaded by

subhanhanifi9
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)
24 views43 pages

Chapter 1

The document provides an overview of data structures, including definitions, types, and operations such as traversing and searching. It covers algorithms, pseudocode, and flowcharts as methods for problem-solving in programming. Additionally, it distinguishes between primitive and non-primitive data structures and outlines the environment setup for implementing data structures in C++.

Uploaded by

subhanhanifi9
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/ 43

Faculty of Computer

Science

Subject: Data Structure


Lecturer: FARDIN “AHMADI”
Data Structure

Chapter 1
Data Structure

Learning outcomes:
 Data vs Information.
 Definition of Data Structure.
 Types of Data Structure.
 Algorithm
 Pseudo code
 Flow Chart
Data Structure

Data and information


 The words data and information may look similar and many people use these words
very frequently.
 But both have lots of differences between them.
Data Structure

Data vs Information
 Data:
 Raw collection facts and figures. such as number words measurements or just description of
things.
 Data can be qualitative or quantitative
 Information :
 when the data are processed, organized, structured or presented in a given context to make
them use full they are called information.
 The processed form of data is known as information.
Data Structure

What is data structure


 Data structure is representation of the logical relationship existing between individual
elements of data.
 Data Structure is a way to store and organize data so that it can be used efficiently.
 Our Data Structure course includes all topics of Data Structure such as Array, Pointer,
Structure, Linked List, Stack, Queue,Tree, Graph, Searching, Sorting, etc.
Data Structure

Operations on data structure


 Traversing
 Searching
 Insertion
 Deletion
 Updating
 Sorting
 Merging
Data Structure
Data Structure

Primitive Data structure


 Primitive data types are the data types available in most of the programming
languages.
 These data types are used to represent single value. It is a basic data type available
in most of the programming language.
Data Structure

Non-Primitive Data structure


 Data type derived from primary data types are known as Non-Primitive data types.
 Non-Primitive data types are used to store group of values.
It can be divided into two types:
1. Linear Data Structure
2. Non-Linear Data Structure
Data Structure

Linear Data Structure


 Linear data structure traverses the data elements sequentially.
 A data structure is said to be Linear if its elements are connected in a linear fashion
by means of logically or in sequence memory locations.
 The common examples of the linear data structure are:
 Arrays
 Queues
 Stacks
 Linked lists
Data Structure

Non-Linear Data Structure


 Non-Linear data structure is opposite to linear data structure.
 In non-linear data structure, the data values are not arranged in order and a data
item is connected to several other data items.
 It uses memory efficiently. Free contiguous memory is not required for allocating data
items.
 The common Example of Non-Linear Data Structures are:
 Tree
 Graph
Data Structure

Environment setup
 In this course we are going to implement data structure in C++ language.
 Here, all the programs of the data structure will be shown using C++. So for that,
you need to install one of the following IDE.
 Turbo C++
 Borland C++
 Dev C++
 Falcon C++
 Visual C++
Data Structure

Algorithms
 Algorithm is a step by step procedure to solve a given problem.
 An algorithm is a finite set of steps defining the solution of a particular problem.
 Algorithm should be written in such a way that it can be used in different
programming languages.
 Remember algorithm is:
 Platform independent
 Can be implemented in any programming language
Data Structure

Features of Algorithm

1. Complete: must be complete.


2. Finite: Algorithm must have finite steps.
3. Output: At least one result is to be produced.

4. Inputs: can take zero or more values as a input.


5. Correct: Algorithm must be correct.
6. Clarity: Each step in the algorithm should be clear and unambiguous.
Data Structure

Algorithm notation
 Algorithm Name
 Should be in capital form
 Meaningful
 Parameters
 Should be enclosed in parenthesis ( )
 Introductory Comment
 Description and purpose of an algorithm
 Steps
 Finite steps
Data
Structure
Algorithm notation
 Comments  Output statement
 Each step start with a comment  Write
 Enclose in [ ]  cout (if using C++)
 .Define the purpose of step
 Finish
 Input Statements
  Exit (Used in main
Read
 cin (if using C++) algorithm)
 Return (Used in sub
algorithm)
Data Structure
Example
Algorithm LARGE(No1, No2, lar)
{This algorithm is used to read two numbers and print the largest}
Step-1 [ Read numbers No1 and No2]
Read(No1,No2)
Step-2 [Find the largest]
if (No1 > No2) then lar = No1
else
lar = No2
end if
Step-3 [Display the Result ]
Write(lar)
Step-4 [Finish]
Exit
Data Structure

Example description
 Algorithm Name (Large )
 Parameters (No1, No2 and lar)
 Input and Output Statement(Read, Write)
 Selection Statement (if-else)
 Comments (enclosed in [ ] before start of each step)
 Introductory comments (enclosed in { } )
 Finish (exit)
Data Structure

ADD Two Number:


step 1: Start
step 2: Declare Variables n1,n2 and sum.
step 3: Read values n1 and n2.
step 4: Add n1 and n2 and assign the result to sum.
sum=n1+n2
step 5: Display sum.
step 6: Stop
Data Structure

Algorithm to find the largest among three different numbers entered


by the user.
Step 1:
start
Step 2:
Declare variable a, b and c
Step 3:
Read variable a, b and c
Step 4:
if a>b
if a>c
Display a is the largest number
else
Display c is the largest number
else
if b>c
Display b is the largest number
else
Display c is the largest number
Step 5: Stop
Data Structure

Pseudo Code
 Is one of the methods that could be used to represent an algorithm.
 Pseudocode is an informal language that helps programmers develop algorithms.
 It is not written in specific syntax and cannot be executed in a computer.
 It is written in symbolic code which must be translated into a programming language
before it can be executed.
 is a methodology that allows the programmer to represent the implementation of an
algorithm.
Data Structure

Pseudo Code is useful:


 To describe how an algorithm should work.
 To explain a computing process to less technical users.
Data Structure

Advantages of Pseudocode
 Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
 Acts as a bridge between the program and the algorithm.
 The main goal of a pseudo code is to explain what exactly each line of a program
should do.
 It can be written easily.
 It can be read and understood easily
Data Structure

Disadvantages of pseudo code


 It's not visual.
 Introduce error possibilities in translating to code.
 There is no standardized style or format, so one pseudocode may be different from
another.
Data Structure

Example
 IF you are happy THEN
 Smile
 ELSE
 Cry
 ENDIF
Data Structure

Example
 Input color
 Case color of
 Red : print “red”
 Green : print “green”
 Blue : print “blue
 Other
 Print “Not Match”
 Endcase
Data Structure

Example
 If student's grade is greater than or equal to 55
 Print "passed"
 else
 Print "failed"
Data Structure

Example
compute the area of a rectangle
 Get the length, l, and width, w
 Compute the area = l*w
 Display the area
Data Structure

Flow chart
 A flowchart is a diagram that depicts the flow of a program.
 Flowchart is a type of diagram that represents an algorithm or process.
 The pictorial representation of the programs or the algorithm is known as flowcharts.
 The purpose of using flowcharts is to graphically present the logical flow of data in the
system and defining major phases of processing along with the various media to be
used.
Data Structure

Flow chart rules


 Flowchart is generally drawn from top to bottom.
 All boxes of flowchart must be connected with arrow.
 All flowchart start with a terminal or process symbol.
 Decision symbol have two exit points, one for TRUE and another for FALSE.
Data Structure

Algorithm Vs Flow chart

S.NO ALGORITHM FLOWCHART

Flowchart is a diagram created by


Algorithm is step by step
.1 different shapes to show the flow
.procedure to solve the problem
.of data
Algorithm is complex to
.2 .Flowchart is easy to understand
.understand
In flowchart, symbols/shapes are
.3 .In algorithm plain text are used
.used
.5 .Algorithm is difficult to construct .Flowchart is simple to construct
Data Structure

Flow chart symbol


Data Structure

 Terminals
 represented by rounded rectangles
 indicate a starting or ending point
START

END
Data Structure

 Flow line
 represented by arrow.
 Used to Indicates the relationship between shapes.
Data Structure

 Input/Output Operations
 represented by parallelograms
 indicate an input or output operation

Print “Enter a
number for x”; Read x
Data Structure

 Processes
 represented by rectangles
 indicates a process such as a mathematical computation or variable assignment.

Multiply x & y.
Data Structure

 Decision
 Use for asking question that can have either TRUE or FALSE as an answer.

X>Y
Data Structure

Add two number

Algorithm
Flowchart
Add 10 with 20
1. Start
2. Initialize sum=0 (process)
3. Enter the numbers (I/O)
4. Add them and store the result in sum (process)
5. Print (I/O)
6. End
Data Structure

1. Add two numbers entered by the user.


Data Structure

2. Find the largest among


three different numbers
entered by the user.
Data Structure

Review Question:
 What is Data and Information?
 What is Data Structure?
 Explain types of Data Structure?
 What is Algorithm?
 What is Pseudo Code and Flow Chart?
 Write Algorithm for any program?
 Write algorithm to calculate the sum and average of two numbers?
 Create a Flow chart to determine whether the student passed the exam or not?
 Create a Flow chart to determine number N is Even or Odd?
Data Structure

Thanks You
For Your Patience

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy