0% found this document useful (0 votes)
123 views

Data Structure Chapter 01

Here are the steps to convert the given infix expression to prefix and postfix notation: Infix: (A + B) * C - (D - E) * (F + G) Prefix: - * + A B C * - D + F G E Postfix: AB+C*DE-FG+*-

Uploaded by

Malik Kamran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

Data Structure Chapter 01

Here are the steps to convert the given infix expression to prefix and postfix notation: Infix: (A + B) * C - (D - E) * (F + G) Prefix: - * + A B C * - D + F G E Postfix: AB+C*DE-FG+*-

Uploaded by

Malik Kamran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Data Structure and Analysis

of Algorithms
BSIT-4th Semester (COMP4120 )

Arsalan Hussain.
Lecture - 01
Data Structures and its type’s
What are Data Structures?

 The data structure is a storage that is used to store and


organize data. It is a way of arranging data on a computer
so that it can be accessed and updated efficiently.
 In computer science, a data structure is a data
organization, management, and storage format that is
usually chosen for efficient access to data. 
Types of Data Structure

Basically, data structures are divided into two


categories:
 Linear data structure
 Non-linear data structure
Linear data structures

In linear data structures, the elements are arranged in


sequence one after the other. Since elements are arranged in
a particular order, they are easy to implement.
However, when the complexity of the program increases, the
linear data structures might not be the best choice because of
operational complexities.
1. Array Data Structure

In an array, elements in memory are arranged in continuous memory.


All the elements of an array are of the same type. And, the type of
elements that can be stored in the form of arrays is determined by the
programming language.
Sorting of Array

There are main two types of sorting of array.


1-Bubble Sort- By Value
2-Selection Sorting- By Index
Searches of Array

There are main two types of searches of array.


1-Linear Search/Sequential Search
2-Binary Search
Linear Search.

For Searching Value:3


Key=3;
For (i=0 ; i<=length-1 ; i++)
{
if(a[i] == key)
{
Cout<<”Index”<<i;
}
}
Binary Search.
Binary Search.
For Searching Value:3
Key=3;
Low=0;
High=length-1;
While (low<=high)
{
mid=(low+high)/2;
if(a[mid]== key)
return mid;
Else
if(a[mid]<key)
Low=mid+1
Else
High=mid-1;
}
2. Stack Data Structure

In stack data structure, elements are stored in the LIFO


principle. That is, the last element stored in a stack will be
removed first.
It works just like a pile of plates where the last plate kept on
the pile will be removed first.
3. Queue Data Structure

Unlike stack, the queue data structure works in the FIFO


principle where the first element stored in the queue will be
removed first.
It works just like a queue of people at the ticket counter
where the first person in the queue will get the ticket first.
4. Linked List Data Structure

In a linked list data structure, data elements are connected


through a series of nodes. And, each node contains the data
items and addresses to the next node.
Non-linear data structures

 Unlike linear data structures, elements in non-linear data


structures are not in any sequence. Instead, they are
arranged in a hierarchical manner where one element will
be connected to one or more elements.
 Non-linear data structures are further divided into graph
and tree-based data structures.
1. Graph Data Structure

In graph data structure, each node is called a vertex and each


vertex is connected to other vertices through edges.
2. Trees Data Structure

Similar to a graph, a tree is also a collection of vertices and


edges. However, in the tree data structure, there can only be
one edge between two vertices.
Abstract Data Type

Abstruct Data Type is a set of all operations that can perform on our
data structure.

An Abstract Data Type in data structure is a kind of a data type whose


behavior is defined with the help of some attributes and some
functions. Generally, we write these attributes and functions inside a
class or a structure so that we can use an object of the class to use that
particular abstract data type
Continue..
Different Specifications:
 Engine,
 Gear
 Petrol Tank
 Tire’s etc

Operations:
 StartEngine();
 DriveSmooth();
 ApplyBreaks();
 IsPetrolLow();
ADT Example
What is a Stack?

A Stack is a linear data structure that follows the LIFO (Last-In-First-


Out) principle. Stack has one end, whereas the Queue has two ends
(front and rear). It contains only one pointer top pointer pointing to the
topmost element of the stack. Whenever an element is added in the
stack, it is added on the top of the stack, and the element can be deleted
only from the stack.
In other words, a stack can be defined as a container in which insertion
and deletion can be done from the one end known as the top of the
stack.
Working of Stack

Stack works on the LIFO pattern.


Overflow and Underflow of Stack
Infix, Postfix & Prefix Notation
Infix: The notation commonly used in mathematical
formulae.
Postfix: A mathematical notation in which operators follow
operands.
Prefix: A mathematical notation in which operands follow
operators.
Operand: The value on which an operator is performed.
Operator: A symbol like minus that shows an operation.
Infix, Postfix & Prefix Notation
Infix toPrefix Conversion

Value in Infix = 2+3


Convert it into Prefix.
so to derive the prefix equivalent we simply
take the operator then move from left to
right reading off the operands in left-to-right
order.
Prefix: + 2 3
Infix to Prefix Conversion

Value in Infix = 2 + 3 + 4
Convert it into Prefix.
Once again the same rules apply. However
we move from the outer circle to the inner
circle.
Prefix: + 2 + 3 4
Infix to Postfix Conversion

Value in Infix = 2 + 3
Convert it into Postfix.
This is just like the prefix notation, but the
operand comes at the end of the expression,
and similarly removes the need for brackets
within any expressions.
Postfix: 23+
Infix to Postfix Conversion

Value in Infix = 2 + 3 + 4
Convert it into Postfix.
Similarly when we have two expressions we
have to remember the operators to append to
the end.
Postfix: 2 3 4 + +
Assignment:

Convert infix into Prefix and Postfix.


(A + B) * C - (D - E) * (F + G)

You might also like