SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Introduction to Searching techniques and
Matrices

Objectives
In this lesson, you will learn to:
 State the algorithm for linear search
 Perform operations on matrices
 State the applications of matrices
 Implement Recursion




                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 1 of 32
Introduction to Searching techniques and
Matrices

Searching
 Searching is an operation that returns either:
      The location of a given item of information
      A message that the given information is not found
 Searching algorithm depends on the type of data
  structure used to store data
 For example, there can be a data structure with:
      Faster search operation (sorted array)
      Faster modification operation (linked list)



                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 2 of 32
Introduction to Searching techniques and
Matrices

Searching (Contd..)
 There is a trade-off in these data structures
      Sorted array insertion and deletion is time
       consuming
      Linked list traversal is time-consuming
 The different searching techniques are:
      Linear search
      Binary search




                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 3 of 32
Introduction to Searching techniques and
Matrices

Linear Search
 Is the simplest search technique
 In this technique begin at one end and scan until:
      The item is found
      The end of the list is reached
 Benefits:
      Can be used on any data structure
      No restrictions on the way data is arranged




                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 4 of 32
Introduction to Searching techniques and
Matrices

Linear Search (Contd..)
 Drawbacks:
      Performance is dependant on the length of the
       array
      Average number of comparisons 1/2(n+1)
      Even if required data is not present the complete
       array is searched




                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                              4/Slide 5 of 32
Introduction to Searching techniques and
Matrices

Binary Search
 Binary search technique is faster than linear search
  technique
 After every search the number of items to be
  searched is reduced by half
 In this search technique:
      Start by comparing the middle element




                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                              4/Slide 6 of 32
Introduction to Searching techniques and
Matrices

Binary Search (Contd..)
 Then the next quarter and so on until
      The required item is found
      No more data is left for searching
 Benefits:
      Faster search
      After each step number of items to be searched
       reduces by half
      More efficient for searching large volume of data



                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 7 of 32
Introduction to Searching techniques and
Matrices

Binary Search (Contd..)
 Average number of comparisons for 1 million items is
  only 20
 Drawbacks:
      Data has to be sorted
      Cannot be used on all data structures




                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                              4/Slide 8 of 32
Introduction to Searching techniques and
Matrices

Problem Statement 4.D.1
 Write a program to accept 20 numbers and store it in
  an array. Now accept a number and search it in an
  array, make sure that, before searching a number you
  perform bubble sort it in.
   Note: Implement using arrays




                  Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 9 of 32
Introduction to Searching techniques and
Matrices

Just A Minute
 In a sorted array insertion and deletion are less time
  consuming than searching.(True/False)
 In a binary tree searching is more time consuming than
  linked list ( True/False)




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 10 of 32
Introduction to Searching techniques and
Matrices

Matrices
A rectangular arrangement of rows and columns is a
matrix
                                      COLUMNS




                A            B           C           D
                      E           F           G           H


         ROWS
                E            F           G           H
                      I           J           K           L



                I            J           K           L




                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                             4/Slide 11 of 32
Introduction to Searching techniques and
Matrices

Matrices (Contd..)
 The size of the matrix is called the dimensions of the
  matrix
 The sum of rows and columns of a matrix identify the
  size
 Each number in a matrix is called an element




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 12 of 32
Introduction to Searching techniques and
Matrices

Matrices (Contd..)
 A matrix with the same number of rows and columns
  is called a square matrix



                 A         B         C
                      E         F


                 E         F         G
                      I         J


                 I         J         K




                 Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                          4/Slide 13 of 32
Introduction to Searching techniques and
Matrices

Matrices (Contd..)


               A   X                    D


               X             Z
                                  D

                       Z

                                             E


 The above figure shows another type of matrix that is,
  a sparse matrix
 A matrix with lot of blank elements is called a sparse
  matrix

                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 14 of 32
Introduction to Searching techniques and
Matrices

Operations on Matrices
 The basic operations on a matrix can be listed as:
      Create
      Store
      Delete
      Retrieve




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 15 of 32
Introduction to Searching techniques and
Matrices

Multi-dimensional Matrix


                  4 Pages




         2 Rows




                            3 Columns



 The syntax for declaring a three-dimensional matrix is
  same as that of two-dimensional array


                             Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                                      4/Slide 16 of 32
Introduction to Searching techniques and
Matrices

Multi-dimensional Matrix (Contd..)
 Example:
      int Newone[2][3][4];
      The array Newone[2][3][4] contains 2*3*4=24
       elements
 The subscripts of the array are called:
      row
      column
      page



                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                              4/Slide 17 of 32
Introduction to Searching techniques and
Matrices

Multi-dimensional Matrix (Contd..)
 In this array, we can store 8 different set of details.
 Sum of row and page gives the number of different
  sets of information that can be stored
 Example: 4*2 = 8 for the array Newone




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 18 of 32
Introduction to Searching techniques and
Matrices

Applications
 Matrices can be applied in:
   Finding the shortest route
      Map coloring
      Search engines for the WEB when combined with
       queues and hash tables




                      Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 19 of 32
Introduction to Searching techniques and
Matrices

Problem Statement 4.D.2
Write a program to store the details of a student
( Student name, Registration number, and the Subject
marks) in a three-dimensional array. Also, give an option
to the user to query and print the details for a specific
student requested by the user by entering the
registration number of the student. Accept the student
data from the user?




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 20 of 32
Introduction to Searching techniques and
Matrices

Recursion
 Whenever a function invokes itself, it is called
  recursion.
 Every time a recursive function calls itself, it must call
  itself with different values.
 A recursive procedure or function must satisfy the
  following two conditions:
      There must be certain values called base values
       for which the function will not call back itself.
      Each time the function refers to itself, the
       arguments passed must be closer to its base
       value.
 It is useful in writing clear, short, and simple programs
                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                             4/Slide 21 of 32
Introduction to Searching techniques and
Matrices

Practice Statement 4.P.1
 Identify the erroneous step(s) in the following Table
  A.2

         Step 1               0!=1

         Step 2               1! =1*1=1

         Step 3               2!=2*1=2

         Step 4               3! =3x2 =6




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 22 of 32
Introduction to Searching techniques and
Matrices

Just a Minute…
 The factorial() function will repeatedly invoke itself until
  the parameter passed to it is _____.
 When the above function is invoked with a parameter of
  5, the factorial() function is invoked ____ times in all.
 State whether True or False.
   With large values (say,100) of the parameter passed to
   the factorial() function, there is a danger of the program
   crashing.




                      Introduction to Searching techniques and Matrices/Lesson
  ©NIIT
                                                               4/Slide 23 of 32
Introduction to Searching techniques and
Matrices

Summary
In this lesson, you learned that:
 Information retrieval is one of the most important
  applications of computers
 Searching is an operation, which:
        Returns the location in memory of some given
     item of information




                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                             4/Slide 24 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 The search algorithm depends mainly on the type of
  data structure we use to store the data in memory
 In a sorted array the search time can be greatly
  reduced by using a search technique called binary
  search
 In sorted array, there is an overhead-involved that is,
  insertion and deletion of data is a time-consuming
  process




                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 25 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 In a linked List:
      Search time will be high
      Only sequential search is possible
      Insertion and deletion will be fast
 Binary Tree combines the advantage of sorted array
  and a linked list




                      Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 26 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 Linear search is also referred to as sequential search
  is the simplest search technique
 In Linear Search, to search an item begin at one end
  of the list and scan down the list until:
          The desired item is found
          The end of the list is reached




                       Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                                4/Slide 27 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 The average number of comparison for a linear
  search can be worked out by applying the formula
  1/2(n+1)
 Linear search technique has some drawbacks:
      Even if there is no match for the item in the list, the
       complete list is searched
      The search time is directly proportional to the
       length of the list




                      Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 28 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 Binary search is faster than linear search technique
 In Binary Search, to search an item begin at the
  middle of the list and scan one half of the list , then
  the quarter and so on until:
      the desired item is found or
      there is no more data to search
 In a binary search, after every comparison, the data to
  be searched reduces by half.




                     Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                              4/Slide 29 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 The drawbacks of binary search are:
      The list has to be sorted
      There should be a method to access the middle
       element of the list
 A rectangular arrangement of rows and columns is
  called a matrix
 A matrix with the same number of rows and columns
  is called a square matrix
 A matrix with a lot of zero or unused elements is
  generally called a sparse matrix

                    Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                             4/Slide 30 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
The basic operations on a matrix can be listed as:
      Create
      Store
      Delete
      Retrieve
The subscripts of a three-dimensional array are called:
      Row
      Column
      Page
                   Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                            4/Slide 31 of 32
Introduction to Searching techniques and
Matrices

Summary (Contd..)
 Matrices can be applied for:
      Finding a shortest route
      Map coloring
 Recursion can be defined as defining something in
  terms of itself. A function is recursive if it makes a call
  to itself, i.e. invokes itself.
 Advantage of recursion is that it is useful in writing
  clear, short, and simple programs.




                      Introduction to Searching techniques and Matrices/Lesson
 ©NIIT
                                                               4/Slide 32 of 32

Weitere ähnliche Inhalte

Andere mochten auch

National Air And Space Museum Washington DC
National Air And Space Museum Washington DCNational Air And Space Museum Washington DC
National Air And Space Museum Washington DCShivakumar Patil
 
Dc parent 14 2
Dc parent 14 2Dc parent 14 2
Dc parent 14 2mtaft
 
Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Andreas Jaffke
 
Google Algorithm Change History - 2k14-2k16.
Google Algorithm Change History - 2k14-2k16.Google Algorithm Change History - 2k14-2k16.
Google Algorithm Change History - 2k14-2k16.Saba SEO
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithmspppepito86
 
Ancient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionAncient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionJohn Lynch
 
History of Creationism, Parts II & III
History of Creationism, Parts II & IIIHistory of Creationism, Parts II & III
History of Creationism, Parts II & IIIJohn Lynch
 
The Chemical Revolution
The Chemical RevolutionThe Chemical Revolution
The Chemical RevolutionJohn Lynch
 
The Scientific Revolution
The Scientific RevolutionThe Scientific Revolution
The Scientific RevolutionJohn Lynch
 
Why Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceWhy Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceJohn Lynch
 
Introduction to Information Technology ch 01_b
Introduction to Information Technology ch 01_bIntroduction to Information Technology ch 01_b
Introduction to Information Technology ch 01_bShahi Raz Akhtar
 
Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"John Lynch
 

Andere mochten auch (20)

National Air And Space Museum Washington DC
National Air And Space Museum Washington DCNational Air And Space Museum Washington DC
National Air And Space Museum Washington DC
 
Dc parent 14 2
Dc parent 14 2Dc parent 14 2
Dc parent 14 2
 
Google at a glance 1998 - 2008
Google at a glance 1998 - 2008Google at a glance 1998 - 2008
Google at a glance 1998 - 2008
 
Google Algorithm Change History - 2k14-2k16.
Google Algorithm Change History - 2k14-2k16.Google Algorithm Change History - 2k14-2k16.
Google Algorithm Change History - 2k14-2k16.
 
Google
GoogleGoogle
Google
 
simple-sorting algorithms
simple-sorting algorithmssimple-sorting algorithms
simple-sorting algorithms
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Ancient Ideas of Creation & Evolution
Ancient Ideas of Creation & EvolutionAncient Ideas of Creation & Evolution
Ancient Ideas of Creation & Evolution
 
Algorithms - Aaron Bloomfield
Algorithms - Aaron BloomfieldAlgorithms - Aaron Bloomfield
Algorithms - Aaron Bloomfield
 
sPen Data Management
sPen Data ManagementsPen Data Management
sPen Data Management
 
Sorting pnk
Sorting pnkSorting pnk
Sorting pnk
 
How We Got Where We Are: 40 Years of Planning...
How We Got Where We Are: 40 Years of Planning...How We Got Where We Are: 40 Years of Planning...
How We Got Where We Are: 40 Years of Planning...
 
History of Creationism, Parts II & III
History of Creationism, Parts II & IIIHistory of Creationism, Parts II & III
History of Creationism, Parts II & III
 
The Chemical Revolution
The Chemical RevolutionThe Chemical Revolution
The Chemical Revolution
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
The Scientific Revolution
The Scientific RevolutionThe Scientific Revolution
The Scientific Revolution
 
Why Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & ScienceWhy Ben Stein Is Wrong About History & Science
Why Ben Stein Is Wrong About History & Science
 
CSS 3, Style and Beyond
CSS 3, Style and BeyondCSS 3, Style and Beyond
CSS 3, Style and Beyond
 
Introduction to Information Technology ch 01_b
Introduction to Information Technology ch 01_bIntroduction to Information Technology ch 01_b
Introduction to Information Technology ch 01_b
 
Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"Introduction to "Origins, Evolution & Creation"
Introduction to "Origins, Evolution & Creation"
 

Ähnlich wie Ds 4

From data mining to knowledge discovery in
From data mining to knowledge discovery inFrom data mining to knowledge discovery in
From data mining to knowledge discovery inRaj Kumar Ranabhat
 
Efficient Temporal Association Rule Mining
Efficient Temporal Association Rule MiningEfficient Temporal Association Rule Mining
Efficient Temporal Association Rule MiningIJMER
 
Classification Techniques: A Review
Classification Techniques: A ReviewClassification Techniques: A Review
Classification Techniques: A ReviewIOSRjournaljce
 
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351IRJET Journal
 
Study of Density Based Clustering Techniques on Data Streams
Study of Density Based Clustering Techniques on Data StreamsStudy of Density Based Clustering Techniques on Data Streams
Study of Density Based Clustering Techniques on Data StreamsIJERA Editor
 
A classification of methods for frequent pattern mining
A classification of methods for frequent pattern miningA classification of methods for frequent pattern mining
A classification of methods for frequent pattern miningIOSR Journals
 
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...theijes
 
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEY
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEYCLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEY
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEYEditor IJMTER
 
BI Chapter 04.pdf business business business business
BI Chapter 04.pdf business business business businessBI Chapter 04.pdf business business business business
BI Chapter 04.pdf business business business businessJawaherAlbaddawi
 

Ähnlich wie Ds 4 (20)

Ds 7
Ds 7Ds 7
Ds 7
 
Ijetcas14 338
Ijetcas14 338Ijetcas14 338
Ijetcas14 338
 
Ds 1
Ds 1Ds 1
Ds 1
 
From data mining to knowledge discovery in
From data mining to knowledge discovery inFrom data mining to knowledge discovery in
From data mining to knowledge discovery in
 
Efficient Temporal Association Rule Mining
Efficient Temporal Association Rule MiningEfficient Temporal Association Rule Mining
Efficient Temporal Association Rule Mining
 
Efficient Temporal Association Rule Mining
Efficient Temporal Association Rule MiningEfficient Temporal Association Rule Mining
Efficient Temporal Association Rule Mining
 
A04010105
A04010105A04010105
A04010105
 
Classification Techniques: A Review
Classification Techniques: A ReviewClassification Techniques: A Review
Classification Techniques: A Review
 
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351
Irjet v4 iA Survey on FP (Growth) Tree using Association Rule Mining7351
 
COMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERING
COMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERINGCOMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERING
COMPUTER LABORATORY-4 LAB MANUAL BE COMPUTER ENGINEERING
 
E502024047
E502024047E502024047
E502024047
 
E502024047
E502024047E502024047
E502024047
 
Study of Density Based Clustering Techniques on Data Streams
Study of Density Based Clustering Techniques on Data StreamsStudy of Density Based Clustering Techniques on Data Streams
Study of Density Based Clustering Techniques on Data Streams
 
Ay4201347349
Ay4201347349Ay4201347349
Ay4201347349
 
J017114852
J017114852J017114852
J017114852
 
A classification of methods for frequent pattern mining
A classification of methods for frequent pattern miningA classification of methods for frequent pattern mining
A classification of methods for frequent pattern mining
 
G045033841
G045033841G045033841
G045033841
 
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...
Applying K-Means Clustering Algorithm to Discover Knowledge from Insurance Da...
 
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEY
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEYCLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEY
CLASSIFICATION ALGORITHM USING RANDOM CONCEPT ON A VERY LARGE DATA SET: A SURVEY
 
BI Chapter 04.pdf business business business business
BI Chapter 04.pdf business business business businessBI Chapter 04.pdf business business business business
BI Chapter 04.pdf business business business business
 

Mehr von Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Ds 4

  • 1. Introduction to Searching techniques and Matrices Objectives In this lesson, you will learn to: State the algorithm for linear search Perform operations on matrices State the applications of matrices Implement Recursion Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 1 of 32
  • 2. Introduction to Searching techniques and Matrices Searching Searching is an operation that returns either: The location of a given item of information A message that the given information is not found Searching algorithm depends on the type of data structure used to store data For example, there can be a data structure with: Faster search operation (sorted array) Faster modification operation (linked list) Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 2 of 32
  • 3. Introduction to Searching techniques and Matrices Searching (Contd..) There is a trade-off in these data structures Sorted array insertion and deletion is time consuming Linked list traversal is time-consuming The different searching techniques are: Linear search Binary search Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 3 of 32
  • 4. Introduction to Searching techniques and Matrices Linear Search Is the simplest search technique In this technique begin at one end and scan until: The item is found The end of the list is reached Benefits: Can be used on any data structure No restrictions on the way data is arranged Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 4 of 32
  • 5. Introduction to Searching techniques and Matrices Linear Search (Contd..) Drawbacks: Performance is dependant on the length of the array Average number of comparisons 1/2(n+1) Even if required data is not present the complete array is searched Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 5 of 32
  • 6. Introduction to Searching techniques and Matrices Binary Search Binary search technique is faster than linear search technique After every search the number of items to be searched is reduced by half In this search technique: Start by comparing the middle element Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 6 of 32
  • 7. Introduction to Searching techniques and Matrices Binary Search (Contd..) Then the next quarter and so on until The required item is found No more data is left for searching Benefits: Faster search After each step number of items to be searched reduces by half More efficient for searching large volume of data Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 7 of 32
  • 8. Introduction to Searching techniques and Matrices Binary Search (Contd..) Average number of comparisons for 1 million items is only 20 Drawbacks: Data has to be sorted Cannot be used on all data structures Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 8 of 32
  • 9. Introduction to Searching techniques and Matrices Problem Statement 4.D.1 Write a program to accept 20 numbers and store it in an array. Now accept a number and search it in an array, make sure that, before searching a number you perform bubble sort it in. Note: Implement using arrays Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 9 of 32
  • 10. Introduction to Searching techniques and Matrices Just A Minute In a sorted array insertion and deletion are less time consuming than searching.(True/False) In a binary tree searching is more time consuming than linked list ( True/False) Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 10 of 32
  • 11. Introduction to Searching techniques and Matrices Matrices A rectangular arrangement of rows and columns is a matrix COLUMNS A B C D E F G H ROWS E F G H I J K L I J K L Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 11 of 32
  • 12. Introduction to Searching techniques and Matrices Matrices (Contd..) The size of the matrix is called the dimensions of the matrix The sum of rows and columns of a matrix identify the size Each number in a matrix is called an element Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 12 of 32
  • 13. Introduction to Searching techniques and Matrices Matrices (Contd..) A matrix with the same number of rows and columns is called a square matrix A B C E F E F G I J I J K Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 13 of 32
  • 14. Introduction to Searching techniques and Matrices Matrices (Contd..) A X D X Z D Z E The above figure shows another type of matrix that is, a sparse matrix A matrix with lot of blank elements is called a sparse matrix Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 14 of 32
  • 15. Introduction to Searching techniques and Matrices Operations on Matrices The basic operations on a matrix can be listed as: Create Store Delete Retrieve Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 15 of 32
  • 16. Introduction to Searching techniques and Matrices Multi-dimensional Matrix 4 Pages 2 Rows 3 Columns The syntax for declaring a three-dimensional matrix is same as that of two-dimensional array Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 16 of 32
  • 17. Introduction to Searching techniques and Matrices Multi-dimensional Matrix (Contd..) Example: int Newone[2][3][4]; The array Newone[2][3][4] contains 2*3*4=24 elements The subscripts of the array are called: row column page Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 17 of 32
  • 18. Introduction to Searching techniques and Matrices Multi-dimensional Matrix (Contd..) In this array, we can store 8 different set of details. Sum of row and page gives the number of different sets of information that can be stored Example: 4*2 = 8 for the array Newone Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 18 of 32
  • 19. Introduction to Searching techniques and Matrices Applications Matrices can be applied in: Finding the shortest route Map coloring Search engines for the WEB when combined with queues and hash tables Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 19 of 32
  • 20. Introduction to Searching techniques and Matrices Problem Statement 4.D.2 Write a program to store the details of a student ( Student name, Registration number, and the Subject marks) in a three-dimensional array. Also, give an option to the user to query and print the details for a specific student requested by the user by entering the registration number of the student. Accept the student data from the user? Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 20 of 32
  • 21. Introduction to Searching techniques and Matrices Recursion Whenever a function invokes itself, it is called recursion. Every time a recursive function calls itself, it must call itself with different values. A recursive procedure or function must satisfy the following two conditions: There must be certain values called base values for which the function will not call back itself. Each time the function refers to itself, the arguments passed must be closer to its base value. It is useful in writing clear, short, and simple programs Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 21 of 32
  • 22. Introduction to Searching techniques and Matrices Practice Statement 4.P.1 Identify the erroneous step(s) in the following Table A.2 Step 1 0!=1 Step 2 1! =1*1=1 Step 3 2!=2*1=2 Step 4 3! =3x2 =6 Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 22 of 32
  • 23. Introduction to Searching techniques and Matrices Just a Minute… The factorial() function will repeatedly invoke itself until the parameter passed to it is _____. When the above function is invoked with a parameter of 5, the factorial() function is invoked ____ times in all. State whether True or False. With large values (say,100) of the parameter passed to the factorial() function, there is a danger of the program crashing. Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 23 of 32
  • 24. Introduction to Searching techniques and Matrices Summary In this lesson, you learned that: Information retrieval is one of the most important applications of computers Searching is an operation, which: Returns the location in memory of some given item of information Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 24 of 32
  • 25. Introduction to Searching techniques and Matrices Summary (Contd..) The search algorithm depends mainly on the type of data structure we use to store the data in memory In a sorted array the search time can be greatly reduced by using a search technique called binary search In sorted array, there is an overhead-involved that is, insertion and deletion of data is a time-consuming process Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 25 of 32
  • 26. Introduction to Searching techniques and Matrices Summary (Contd..) In a linked List: Search time will be high Only sequential search is possible Insertion and deletion will be fast Binary Tree combines the advantage of sorted array and a linked list Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 26 of 32
  • 27. Introduction to Searching techniques and Matrices Summary (Contd..) Linear search is also referred to as sequential search is the simplest search technique In Linear Search, to search an item begin at one end of the list and scan down the list until: The desired item is found The end of the list is reached Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 27 of 32
  • 28. Introduction to Searching techniques and Matrices Summary (Contd..) The average number of comparison for a linear search can be worked out by applying the formula 1/2(n+1) Linear search technique has some drawbacks: Even if there is no match for the item in the list, the complete list is searched The search time is directly proportional to the length of the list Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 28 of 32
  • 29. Introduction to Searching techniques and Matrices Summary (Contd..) Binary search is faster than linear search technique In Binary Search, to search an item begin at the middle of the list and scan one half of the list , then the quarter and so on until: the desired item is found or there is no more data to search In a binary search, after every comparison, the data to be searched reduces by half. Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 29 of 32
  • 30. Introduction to Searching techniques and Matrices Summary (Contd..) The drawbacks of binary search are: The list has to be sorted There should be a method to access the middle element of the list A rectangular arrangement of rows and columns is called a matrix A matrix with the same number of rows and columns is called a square matrix A matrix with a lot of zero or unused elements is generally called a sparse matrix Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 30 of 32
  • 31. Introduction to Searching techniques and Matrices Summary (Contd..) The basic operations on a matrix can be listed as: Create Store Delete Retrieve The subscripts of a three-dimensional array are called: Row Column Page Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 31 of 32
  • 32. Introduction to Searching techniques and Matrices Summary (Contd..) Matrices can be applied for: Finding a shortest route Map coloring Recursion can be defined as defining something in terms of itself. A function is recursive if it makes a call to itself, i.e. invokes itself. Advantage of recursion is that it is useful in writing clear, short, and simple programs. Introduction to Searching techniques and Matrices/Lesson ©NIIT 4/Slide 32 of 32