SlideShare a Scribd company logo
1 of 29
Data Structures
What are Data Structures?
•  Data may be organized in many different ways.
•  A Data Structure is an arrangement of data in a
   computer’s memory or on a disk.
• The logical or mathematical model of a particular
   organization of a data is called Data Structures.
• The choice of a data model depends on two
   consideration:
1) It must be rich enough in structure to mirror the actual
   relationships of the data in the real world.
2) The structure should be simple enough that one can
   effectively process the data when necessary.
Types Of Data Structures
•    The more commonly used data structures include lists,
     arrays, stacks, queues, heaps, trees, and graphs.

1)   Arrays: The simplest type of data structure is linear
     array. A linear array is list of a finite number n of
     similar data elements referenced respt by a set of n
     consecutive numbers.
2) Linked List: A list is an ordered set of data. It is often
     used to store objects that are to be processed
     sequentially. A list can be used to create a queue.
3) Trees: Data frequently contain a hierarchical
     relationships between various elements. The data
     structure which reflects this relationships is called a
     rooted tree graph or a tree.
4) Stack: A stack also called a last-in first-out (LIFO)
   system, is a linear list in which insertions and deletions
   can take place only at one end, called top.
5) Queue: A queue also called first-in first-out (FIFO)
   system, is a linear list in which deletion can take place
   only at one end of the list, the “front” of the list, and
   insertion can take place only at the other end of the list,
   the “rear” of the list.
6) Graph: Graphs are data structures rather like trees.
   Graphs often have a shape dictated by a physical or
   abstract problem. For example, nodes in a graph may
   represent cities, while edges may represent airline flight
   routes between the cities. Nodes are traditionally called
   vertices
Data Structure Operations
• The data appearing in data structures are processed by
  means of operations. The following are operations are
  major operations:
  a) Traversing: Accessing each record exactly once so
  that certain items in the record may be processed.
  b) Searching: Finding the location of the record with a
  given key value, or finding the locations of all records
  which satisfy one or more conditions.
  c) Inserting: Adding a new record to the structure.
  d) Deleting: Removing a record from the structure.

Following two are special operations:
  a) Sorting: Arranging the records in some logical order.
  b) Merging: Combining the records in two different
  sorted files into a single sorted file.
What are Algorithms?
• An algorithm is a well-defined list of steps for solving a
  particular problem.
• Algorithms manipulate the data present in data structures in
  various ways, such as searching for a particular data item and
  sorting the data.
• Flowcharts are pictorial representations of the algorithms.
• Properties/ characteristics of the algorithm:
  a) Finiteness: Total number of steps used in an algorithm
  should be finite.
  b) Definiteness: Each step of algorithm must be clear and
  unambiguous.
  c) Effectiveness: Every step must be basic and essential.
  d) Input/Output: The algorithm must accept zero or more
  input and must produce at least on output.
Algorithmic Problem
• There are mainly two types of algorithm:
  a) Simple Flow Problem: these are very simple
  problems and the procedure flow is sequential
  manner ie step-by-step.
  b) Branching Flow Problem: These sentences
  are not simple. It consists of condition, it tests
  the condition and accordingly transfers the flow.

Eg: simpleFlowProblem.txt branchingFlowPrblm.txt
Complexity of Algorithm
• The analysis of algorithm is a major task. In order to compare
  algorithms, we must have some criteria to measure the
  efficiency of an algorithm. The efficiency of an algorithm
  depends on time and space factors.
• Suppose M is an algorithm, and suppose n is the size of the
  input data. The time is measured by counting the number of
  key operations ,eg in sorting and searching algo, key
  operation is number of comparisons. The space is measured
  by counting the maximum of memory needed by the
  algorithm.
• The complexity of an algo M is the function f(n) which gives
  the running time and/or storage space requirement of the
  algorithm in terms of size n of the input data.
Example
• Suppose we are given an English short story TEXT, and
  suppose we want to search through TEXT for the first
  occurrence of a gvn 3-letter word W. If W is the 3-letter word
  “the” then it is likely that W occurs near the beginning of
  TEXT. So f(n) will be small. On the other hand, if W is the 3-
  letter word “zoo”, then W may not appear in TEXT at all, so
  f(n) will be large.
• From the above example complexity can be investigated as
  follows:
  a) Worst Case: When any searching algo finds required
  element in last attempt.
  b) Average Case: When any searching algo finds required
  element in some avg number of attempts.
  c) Best Case: When any searching algo finds required
  element in first attempt.
ARRAYS
• An array is a group of related data items
  that share a common name.
• An array should be of a single type,
  comprising of integers or strings and so
  on.
• Array elements are accessed by using
  index which is mentioned inside the
  subscript operator ([ ]).
Types of Array
1)   One-Dimensional Array: Creating array involves three
     steps:
     a) Declaration:
        type[ ] arrayname;
                 or
        type arrayname[ ];
     b) Creating new object of array:
        arrayname= new type[size];
     c) Initialization of array:
        arrayname[index] = value;
                 or
        type arrayname[ ]={list of values};

*****Give one example
2) Two-Dimensional Array:
   Eg: int table[][]; //declaration
       table=new int[2][3]; //creating new object of 2D
                               //array with 2 rows and 3 cols.
       int table[][]={{0,0,0},{1,1,1}}; //initialization

****Give one example.

 Duplicating Array: this is one of the properties of an
  array by which we can make duplication of array.
  Object.clone() method is used for duplication.

  Eg: Duplication.java
Searching Techniques
•    Searching is used to locate the position of specific item in
     the array. Search can be performed by using following
     techniques:
     a) Sequential Search.
     b) Binary Search.

1)   Sequential Search: It is also called linear search since we
     can search element on after the other in the array. First we
     compare the search key value with first index variable, then
     second and so on till we get the search key.
     Algorithm: sequentialSearchAlgo.txt
     Eg: SequentialSearch.java
2) Binary Search: Binary search relies on a divide and
   conquer strategy to find a value within an already-sorted
   collection.
   Algorithm: binarySearch.txt
   Eg: Find 6 in {-1, 5, 6, 18, 19, 25, 46, 78, 102, 114}.
• Step 1 (middle element is 19 > 6): -1 5 6 18 19 25
   46 78 102 114
• Step 2 (middle element is 5 < 6):       -1 5 6 18 19 25
   46 78 102 114
• Step 3 (middle element is 6 == 6): -1 5 6 18 19 25
   46 78 102 114
STACK
•    Stack is the collection of ordered elements, which can
     be accessed through LIFO manner. One end is used
     for insertion as well as deletion purpose.
 Stack Interface: Stack interface contains various
     operations on the stack which are as follows:
1)   public void push (E element): inserting element on
     the stack is called as a PUSH operation.
2)   public E pop(): deleting element from stack is called
     as POP operation.
3)   public boolean isEmpty(): function checks if stack is
     empty or not. This function basically required when we
     remove elements from stack.
4)   public E peek(): Access the topmost element.
5)   public int size(): To check size of the stack.
Algorithms for Handling Stack
a)   Create a stack:
1)   Start.
2)   Assign the initial capacity to the elements through its object.
3)   Stop.

b) To check stack is empty or not?
1) Start.
2) Check that size=0.
     If yes
         Then return true.
     else
         return false.
3) Stop.
c) To insert element in the stack:
1) If stack is full?
      if yes
          resize the stack.
2) size=size+1;
3) Stack[size]= element
4) Return stack/top.

d) To delete element from stack:
1) Check that stack is empty
      if yes
          then print stack underflow & throw exception for empty
      stack
      otherwise follow next step.
2) item=stack[top].
3) top=top-1.
4) Return item.
5) Stop.
e) To access the topmost element from stack:
1) Check that stack is empty.
     if yes
         then print stack overflow & throw exception for empty
     stack.
     otherwise follow next step.
2) Return item of the top.
3) Stop.

Eg: usestack.java
Queue
•    A queue is a linear list of elements in which deletions can
     take place only at one end, called the front, and insertions
     can take place only at the other end called rear.
•    Queues access elements in FIFO manner.
•    Real world example: queues in hospital, college office’s,
     bus stop etc.
•    Logically size of queue is infinite but practically it should be
     finite.
•    Operations provided for queue are present in Queue
     interface:
1)   public void add(E element): inserts element in the queue.
2)   public E remove(): deletes element from the queue.
3)   public boolean isEmpty(): function which checks queue is
     empty or not.
4)   public E element(): access the front side element.
5)   public int size(): to check the size of queue.
•    Types of the Queue:
1)   Simple or Linear Queue.
2)   Circular Queue.
3)   Priority Queue.
4)   Dequeue.
Algorithm of Indexed Implementation of
                    Queue
1) To create a queue:
     a) Start.
     b) Declare space for queue that means assign capacity for the
     queue.
     c) Stop.

2) To check Queue is Empty or Not?
     a) Start
     b) Call size() method & check its value=1
        If yes
                 return true
        else
                 return false
     c) Stop
3) To insert element in the queue:
   a) Start
   b) Check queue is full or not by its size
       if yes
              then call resize() function for extra size
   c) Add element by rear size.
   d) Check that rear < total element-1
       if yes
              increase rear size by 1.
       else
              rear=0
   e) Stop.
4) To delete element from queue:
   a) Start
   b) check that queue is empty or not by checking its size.
        if yes
                then throw exception
   c) Item=queue[Front]
   d) check that Rear=Front
        if yes then
                Rear=0.
                Front=0.
   e) Check that front==total elements length
        if yes
                then front=0
   f) stop.
5) To count size of the Queue:
   a) Start.
   b) Check that front <=rear
       If yes
              Return rear-front
       else
              return rear-front + element.length
   c) Stop.
Applications of Queue
1) Queues are more useful in OS:
     a) Processor management creates ready queue of the
        process by the CPU Scheduler Algorithm.
     b) Batch Processing.
     c) File Manager.
     d) Job scheduling & Device scheduling.
     e) Every IO devices has their own queue to collect requests
        from different applications or processing.
2) Queues are used to traversing all nodes of the graph.
3) Queues are used to traversing all nodes of the tree.
4) It is also used in different Artificial Intelligent programs.
Data structures

More Related Content

What's hot

Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its typesRameesha Sadaqat
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Array operations
Array operationsArray operations
Array operationsZAFAR444
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 

What's hot (20)

stack & queue
stack & queuestack & queue
stack & queue
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Binary search
Binary searchBinary search
Binary search
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Stack
StackStack
Stack
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
stack presentation
stack presentationstack presentation
stack presentation
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Array operations
Array operationsArray operations
Array operations
 
Java swing
Java swingJava swing
Java swing
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 

Viewers also liked

Viewers also liked (20)

DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Data structures
Data structuresData structures
Data structures
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
List 2
List 2List 2
List 2
 
lecture 17
lecture 17lecture 17
lecture 17
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Heapsort using Heap
Heapsort using HeapHeapsort using Heap
Heapsort using Heap
 
Data structure unitfirst part1
Data structure unitfirst part1Data structure unitfirst part1
Data structure unitfirst part1
 
Entity relationship modeling
Entity relationship modelingEntity relationship modeling
Entity relationship modeling
 
Ch 8 introduction to data structures
Ch 8 introduction to data structuresCh 8 introduction to data structures
Ch 8 introduction to data structures
 
Data mining 1
Data mining 1Data mining 1
Data mining 1
 
Graph theory short presentation
Graph theory short presentationGraph theory short presentation
Graph theory short presentation
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
Lec5
Lec5Lec5
Lec5
 
Lec30
Lec30Lec30
Lec30
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
 
Kuliah1 Struktur Data V1.0
Kuliah1 Struktur Data V1.0Kuliah1 Struktur Data V1.0
Kuliah1 Struktur Data V1.0
 
datamodel_vector
datamodel_vectordatamodel_vector
datamodel_vector
 

Similar to Data structures

01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptxDwijBaxi
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptxAnuJoseph95
 
Slide 1.-datastructure
Slide 1.-datastructureSlide 1.-datastructure
Slide 1.-datastructureMinhaz Leo
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2Abbott
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechniclavparmar007
 

Similar to Data structures (20)

01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Data structure
Data structureData structure
Data structure
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Slide 1.-datastructure
Slide 1.-datastructureSlide 1.-datastructure
Slide 1.-datastructure
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
CSE 443 (1).pptx
CSE 443 (1).pptxCSE 443 (1).pptx
CSE 443 (1).pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Data structure
Data structureData structure
Data structure
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 

Data structures

  • 2. What are Data Structures? • Data may be organized in many different ways. • A Data Structure is an arrangement of data in a computer’s memory or on a disk. • The logical or mathematical model of a particular organization of a data is called Data Structures. • The choice of a data model depends on two consideration: 1) It must be rich enough in structure to mirror the actual relationships of the data in the real world. 2) The structure should be simple enough that one can effectively process the data when necessary.
  • 3. Types Of Data Structures • The more commonly used data structures include lists, arrays, stacks, queues, heaps, trees, and graphs. 1) Arrays: The simplest type of data structure is linear array. A linear array is list of a finite number n of similar data elements referenced respt by a set of n consecutive numbers. 2) Linked List: A list is an ordered set of data. It is often used to store objects that are to be processed sequentially. A list can be used to create a queue. 3) Trees: Data frequently contain a hierarchical relationships between various elements. The data structure which reflects this relationships is called a rooted tree graph or a tree.
  • 4. 4) Stack: A stack also called a last-in first-out (LIFO) system, is a linear list in which insertions and deletions can take place only at one end, called top. 5) Queue: A queue also called first-in first-out (FIFO) system, is a linear list in which deletion can take place only at one end of the list, the “front” of the list, and insertion can take place only at the other end of the list, the “rear” of the list. 6) Graph: Graphs are data structures rather like trees. Graphs often have a shape dictated by a physical or abstract problem. For example, nodes in a graph may represent cities, while edges may represent airline flight routes between the cities. Nodes are traditionally called vertices
  • 5. Data Structure Operations • The data appearing in data structures are processed by means of operations. The following are operations are major operations: a) Traversing: Accessing each record exactly once so that certain items in the record may be processed. b) Searching: Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions. c) Inserting: Adding a new record to the structure. d) Deleting: Removing a record from the structure. Following two are special operations: a) Sorting: Arranging the records in some logical order. b) Merging: Combining the records in two different sorted files into a single sorted file.
  • 6. What are Algorithms? • An algorithm is a well-defined list of steps for solving a particular problem. • Algorithms manipulate the data present in data structures in various ways, such as searching for a particular data item and sorting the data. • Flowcharts are pictorial representations of the algorithms. • Properties/ characteristics of the algorithm: a) Finiteness: Total number of steps used in an algorithm should be finite. b) Definiteness: Each step of algorithm must be clear and unambiguous. c) Effectiveness: Every step must be basic and essential. d) Input/Output: The algorithm must accept zero or more input and must produce at least on output.
  • 7. Algorithmic Problem • There are mainly two types of algorithm: a) Simple Flow Problem: these are very simple problems and the procedure flow is sequential manner ie step-by-step. b) Branching Flow Problem: These sentences are not simple. It consists of condition, it tests the condition and accordingly transfers the flow. Eg: simpleFlowProblem.txt branchingFlowPrblm.txt
  • 8. Complexity of Algorithm • The analysis of algorithm is a major task. In order to compare algorithms, we must have some criteria to measure the efficiency of an algorithm. The efficiency of an algorithm depends on time and space factors. • Suppose M is an algorithm, and suppose n is the size of the input data. The time is measured by counting the number of key operations ,eg in sorting and searching algo, key operation is number of comparisons. The space is measured by counting the maximum of memory needed by the algorithm. • The complexity of an algo M is the function f(n) which gives the running time and/or storage space requirement of the algorithm in terms of size n of the input data.
  • 9. Example • Suppose we are given an English short story TEXT, and suppose we want to search through TEXT for the first occurrence of a gvn 3-letter word W. If W is the 3-letter word “the” then it is likely that W occurs near the beginning of TEXT. So f(n) will be small. On the other hand, if W is the 3- letter word “zoo”, then W may not appear in TEXT at all, so f(n) will be large. • From the above example complexity can be investigated as follows: a) Worst Case: When any searching algo finds required element in last attempt. b) Average Case: When any searching algo finds required element in some avg number of attempts. c) Best Case: When any searching algo finds required element in first attempt.
  • 11. • An array is a group of related data items that share a common name. • An array should be of a single type, comprising of integers or strings and so on. • Array elements are accessed by using index which is mentioned inside the subscript operator ([ ]).
  • 12. Types of Array 1) One-Dimensional Array: Creating array involves three steps: a) Declaration: type[ ] arrayname; or type arrayname[ ]; b) Creating new object of array: arrayname= new type[size]; c) Initialization of array: arrayname[index] = value; or type arrayname[ ]={list of values}; *****Give one example
  • 13. 2) Two-Dimensional Array: Eg: int table[][]; //declaration table=new int[2][3]; //creating new object of 2D //array with 2 rows and 3 cols. int table[][]={{0,0,0},{1,1,1}}; //initialization ****Give one example.  Duplicating Array: this is one of the properties of an array by which we can make duplication of array. Object.clone() method is used for duplication. Eg: Duplication.java
  • 14. Searching Techniques • Searching is used to locate the position of specific item in the array. Search can be performed by using following techniques: a) Sequential Search. b) Binary Search. 1) Sequential Search: It is also called linear search since we can search element on after the other in the array. First we compare the search key value with first index variable, then second and so on till we get the search key. Algorithm: sequentialSearchAlgo.txt Eg: SequentialSearch.java
  • 15. 2) Binary Search: Binary search relies on a divide and conquer strategy to find a value within an already-sorted collection. Algorithm: binarySearch.txt Eg: Find 6 in {-1, 5, 6, 18, 19, 25, 46, 78, 102, 114}. • Step 1 (middle element is 19 > 6): -1 5 6 18 19 25 46 78 102 114 • Step 2 (middle element is 5 < 6): -1 5 6 18 19 25 46 78 102 114 • Step 3 (middle element is 6 == 6): -1 5 6 18 19 25 46 78 102 114
  • 16. STACK
  • 17. Stack is the collection of ordered elements, which can be accessed through LIFO manner. One end is used for insertion as well as deletion purpose.  Stack Interface: Stack interface contains various operations on the stack which are as follows: 1) public void push (E element): inserting element on the stack is called as a PUSH operation. 2) public E pop(): deleting element from stack is called as POP operation. 3) public boolean isEmpty(): function checks if stack is empty or not. This function basically required when we remove elements from stack. 4) public E peek(): Access the topmost element. 5) public int size(): To check size of the stack.
  • 18. Algorithms for Handling Stack a) Create a stack: 1) Start. 2) Assign the initial capacity to the elements through its object. 3) Stop. b) To check stack is empty or not? 1) Start. 2) Check that size=0. If yes Then return true. else return false. 3) Stop.
  • 19. c) To insert element in the stack: 1) If stack is full? if yes resize the stack. 2) size=size+1; 3) Stack[size]= element 4) Return stack/top. d) To delete element from stack: 1) Check that stack is empty if yes then print stack underflow & throw exception for empty stack otherwise follow next step. 2) item=stack[top]. 3) top=top-1. 4) Return item. 5) Stop.
  • 20. e) To access the topmost element from stack: 1) Check that stack is empty. if yes then print stack overflow & throw exception for empty stack. otherwise follow next step. 2) Return item of the top. 3) Stop. Eg: usestack.java
  • 21. Queue
  • 22. A queue is a linear list of elements in which deletions can take place only at one end, called the front, and insertions can take place only at the other end called rear. • Queues access elements in FIFO manner. • Real world example: queues in hospital, college office’s, bus stop etc. • Logically size of queue is infinite but practically it should be finite. • Operations provided for queue are present in Queue interface: 1) public void add(E element): inserts element in the queue. 2) public E remove(): deletes element from the queue. 3) public boolean isEmpty(): function which checks queue is empty or not. 4) public E element(): access the front side element. 5) public int size(): to check the size of queue.
  • 23. Types of the Queue: 1) Simple or Linear Queue. 2) Circular Queue. 3) Priority Queue. 4) Dequeue.
  • 24. Algorithm of Indexed Implementation of Queue 1) To create a queue: a) Start. b) Declare space for queue that means assign capacity for the queue. c) Stop. 2) To check Queue is Empty or Not? a) Start b) Call size() method & check its value=1 If yes return true else return false c) Stop
  • 25. 3) To insert element in the queue: a) Start b) Check queue is full or not by its size if yes then call resize() function for extra size c) Add element by rear size. d) Check that rear < total element-1 if yes increase rear size by 1. else rear=0 e) Stop.
  • 26. 4) To delete element from queue: a) Start b) check that queue is empty or not by checking its size. if yes then throw exception c) Item=queue[Front] d) check that Rear=Front if yes then Rear=0. Front=0. e) Check that front==total elements length if yes then front=0 f) stop.
  • 27. 5) To count size of the Queue: a) Start. b) Check that front <=rear If yes Return rear-front else return rear-front + element.length c) Stop.
  • 28. Applications of Queue 1) Queues are more useful in OS: a) Processor management creates ready queue of the process by the CPU Scheduler Algorithm. b) Batch Processing. c) File Manager. d) Job scheduling & Device scheduling. e) Every IO devices has their own queue to collect requests from different applications or processing. 2) Queues are used to traversing all nodes of the graph. 3) Queues are used to traversing all nodes of the tree. 4) It is also used in different Artificial Intelligent programs.