Submit Search
Upload
9781337102087 ppt ch16
•
Download as PPTX, PDF
•
0 likes
•
162 views
T
Terry Yoast
Follow
ch 16
Read less
Read more
Education
Report
Share
Report
Share
1 of 29
Download now
Recommended
9781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
Â
9781337102087 ppt ch06
9781337102087 ppt ch06
Terry Yoast
Â
9781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
Â
9781337102087 ppt ch05
9781337102087 ppt ch05
Terry Yoast
Â
9781337102087 ppt ch08
9781337102087 ppt ch08
Terry Yoast
Â
SPARQL 1.1 Status
SPARQL 1.1 Status
LeeFeigenbaum
Â
Extended LargeRDFBench
Extended LargeRDFBench
Muhammad Saleem
Â
Extending LargeRDFBench for Multi-Source Data at Scale for SPARQL Endpoint F...
Extending LargeRDFBench for Multi-Source Data at Scale for SPARQL Endpoint F...
Holistic Benchmarking of Big Linked Data
Â
Recommended
9781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
Â
9781337102087 ppt ch06
9781337102087 ppt ch06
Terry Yoast
Â
9781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
Â
9781337102087 ppt ch05
9781337102087 ppt ch05
Terry Yoast
Â
9781337102087 ppt ch08
9781337102087 ppt ch08
Terry Yoast
Â
SPARQL 1.1 Status
SPARQL 1.1 Status
LeeFeigenbaum
Â
Extended LargeRDFBench
Extended LargeRDFBench
Muhammad Saleem
Â
Extending LargeRDFBench for Multi-Source Data at Scale for SPARQL Endpoint F...
Extending LargeRDFBench for Multi-Source Data at Scale for SPARQL Endpoint F...
Holistic Benchmarking of Big Linked Data
Â
9781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
Â
9781337102087 ppt ch10
9781337102087 ppt ch10
Terry Yoast
Â
9781337102087 ppt ch04
9781337102087 ppt ch04
Terry Yoast
Â
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
pullaravikumar
Â
9781337102087 ppt ch09
9781337102087 ppt ch09
Terry Yoast
Â
9781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
Â
Sql9e ppt ch02
Sql9e ppt ch02
Dr. Ahmed Al Zaidy
Â
Access 2016 module 2 ppt presentation
Access 2016 module 2 ppt presentation
dgdotson
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
Â
Sql9e ppt ch08
Sql9e ppt ch08
Dr. Ahmed Al Zaidy
Â
Access 2016 module 4 ppt presentation
Access 2016 module 4 ppt presentation
dgdotson
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
Â
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
JohnSnyders
Â
Excel module 1 ppt presentation
Excel module 1 ppt presentation
dgdotson
Â
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
mshellman
Â
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
sleeperharwell
Â
Sql9e ppt ch05
Sql9e ppt ch05
Dr. Ahmed Al Zaidy
Â
An introduction to R is a document useful
An introduction to R is a document useful
ssuser3c3f88
Â
Sql9e ppt ch03
Sql9e ppt ch03
Dr. Ahmed Al Zaidy
Â
GraphQL Advanced
GraphQL Advanced
LeanIX GmbH
Â
9781305078444 ppt ch12
9781305078444 ppt ch12
Terry Yoast
Â
9781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
Â
More Related Content
Similar to 9781337102087 ppt ch16
9781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
Â
9781337102087 ppt ch10
9781337102087 ppt ch10
Terry Yoast
Â
9781337102087 ppt ch04
9781337102087 ppt ch04
Terry Yoast
Â
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
pullaravikumar
Â
9781337102087 ppt ch09
9781337102087 ppt ch09
Terry Yoast
Â
9781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
Â
Sql9e ppt ch02
Sql9e ppt ch02
Dr. Ahmed Al Zaidy
Â
Access 2016 module 2 ppt presentation
Access 2016 module 2 ppt presentation
dgdotson
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
Â
Sql9e ppt ch08
Sql9e ppt ch08
Dr. Ahmed Al Zaidy
Â
Access 2016 module 4 ppt presentation
Access 2016 module 4 ppt presentation
dgdotson
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
Â
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
JohnSnyders
Â
Excel module 1 ppt presentation
Excel module 1 ppt presentation
dgdotson
Â
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
mshellman
Â
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
sleeperharwell
Â
Sql9e ppt ch05
Sql9e ppt ch05
Dr. Ahmed Al Zaidy
Â
An introduction to R is a document useful
An introduction to R is a document useful
ssuser3c3f88
Â
Sql9e ppt ch03
Sql9e ppt ch03
Dr. Ahmed Al Zaidy
Â
GraphQL Advanced
GraphQL Advanced
LeanIX GmbH
Â
Similar to 9781337102087 ppt ch16
(20)
9781337102087 ppt ch17
9781337102087 ppt ch17
Â
9781337102087 ppt ch10
9781337102087 ppt ch10
Â
9781337102087 ppt ch04
9781337102087 ppt ch04
Â
Software Development, Data Types, and Expressions
Software Development, Data Types, and Expressions
Â
9781337102087 ppt ch09
9781337102087 ppt ch09
Â
9781337102087 ppt ch13
9781337102087 ppt ch13
Â
Sql9e ppt ch02
Sql9e ppt ch02
Â
Access 2016 module 2 ppt presentation
Access 2016 module 2 ppt presentation
Â
9781337102087 ppt ch11
9781337102087 ppt ch11
Â
Sql9e ppt ch08
Sql9e ppt ch08
Â
Access 2016 module 4 ppt presentation
Access 2016 module 4 ppt presentation
Â
9781337102087 ppt ch15
9781337102087 ppt ch15
Â
APEX Office Hours Interactive Grid Deep Dive
APEX Office Hours Interactive Grid Deep Dive
Â
Excel module 1 ppt presentation
Excel module 1 ppt presentation
Â
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
Â
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
9781337117562_ppt_ch01.pptxChapter 1An Overview of Compute.docx
Â
Sql9e ppt ch05
Sql9e ppt ch05
Â
An introduction to R is a document useful
An introduction to R is a document useful
Â
Sql9e ppt ch03
Sql9e ppt ch03
Â
GraphQL Advanced
GraphQL Advanced
Â
More from Terry Yoast
9781305078444 ppt ch12
9781305078444 ppt ch12
Terry Yoast
Â
9781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
Â
9781305078444 ppt ch10
9781305078444 ppt ch10
Terry Yoast
Â
9781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
Â
9781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
Â
9781305078444 ppt ch07
9781305078444 ppt ch07
Terry Yoast
Â
9781305078444 ppt ch06
9781305078444 ppt ch06
Terry Yoast
Â
9781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
Â
9781305078444 ppt ch04
9781305078444 ppt ch04
Terry Yoast
Â
9781305078444 ppt ch03
9781305078444 ppt ch03
Terry Yoast
Â
9781305078444 ppt ch02
9781305078444 ppt ch02
Terry Yoast
Â
9781305078444 ppt ch01
9781305078444 ppt ch01
Terry Yoast
Â
9781337102087 ppt ch14
9781337102087 ppt ch14
Terry Yoast
Â
9780538745840 ppt ch10
9780538745840 ppt ch10
Terry Yoast
Â
9780538745840 ppt ch09
9780538745840 ppt ch09
Terry Yoast
Â
9780538745840 ppt ch08
9780538745840 ppt ch08
Terry Yoast
Â
9780538745840 ppt ch07
9780538745840 ppt ch07
Terry Yoast
Â
9780538745840 ppt ch06
9780538745840 ppt ch06
Terry Yoast
Â
More from Terry Yoast
(18)
9781305078444 ppt ch12
9781305078444 ppt ch12
Â
9781305078444 ppt ch11
9781305078444 ppt ch11
Â
9781305078444 ppt ch10
9781305078444 ppt ch10
Â
9781305078444 ppt ch09
9781305078444 ppt ch09
Â
9781305078444 ppt ch08
9781305078444 ppt ch08
Â
9781305078444 ppt ch07
9781305078444 ppt ch07
Â
9781305078444 ppt ch06
9781305078444 ppt ch06
Â
9781305078444 ppt ch05
9781305078444 ppt ch05
Â
9781305078444 ppt ch04
9781305078444 ppt ch04
Â
9781305078444 ppt ch03
9781305078444 ppt ch03
Â
9781305078444 ppt ch02
9781305078444 ppt ch02
Â
9781305078444 ppt ch01
9781305078444 ppt ch01
Â
9781337102087 ppt ch14
9781337102087 ppt ch14
Â
9780538745840 ppt ch10
9780538745840 ppt ch10
Â
9780538745840 ppt ch09
9780538745840 ppt ch09
Â
9780538745840 ppt ch08
9780538745840 ppt ch08
Â
9780538745840 ppt ch07
9780538745840 ppt ch07
Â
9780538745840 ppt ch06
9780538745840 ppt ch06
Â
Recently uploaded
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Dr. Mazin Mohamed alkathiri
Â
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
Conquiztadors- the Quiz Society of Sri Venkateswara College
Â
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Carlos105
Â
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
Conquiztadors- the Quiz Society of Sri Venkateswara College
Â
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
navabharathschool99
Â
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
lakshayb543
Â
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
MaryGraceBautista27
Â
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
SamikshaHamane
Â
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
YousafMalik24
Â
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Sabitha Banu
Â
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Celine George
Â
Full Stack Web Development Course for Beginners
Full Stack Web Development Course for Beginners
Sabitha Banu
Â
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
Celine George
Â
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
nelietumpap1
Â
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
Celine George
Â
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
KayeClaireEstoconing
Â
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
Anupkumar Sharma
Â
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
SherlyMaeNeri
Â
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
thorishapillay1
Â
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
MiaBumagat1
Â
Recently uploaded
(20)
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Â
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
Â
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Â
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
Â
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
Â
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Â
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Â
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
Â
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
Â
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
Â
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Â
Full Stack Web Development Course for Beginners
Full Stack Web Development Course for Beginners
Â
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
Â
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
Â
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
Â
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
Â
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
Â
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
Â
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
Â
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
Â
9781337102087 ppt ch16
1.
1 C++ Programming: From
Problem Analysis to Program Design, Eighth Edition Chapter 16 Searching, Sorting, and the vector Type
2.
2 Objectives • In this
chapter, you will: • Learn about list processing and how to search a list using sequential search • Explore how to sort an array using the bubble sort and insertion sort algorithms • Learn how to implement the binary search algorithm • Become familiar with the vector type © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 2
3.
3 List Processing • List:
a collection of values of the same type • Array is a convenient place to store a list • Basic list operations: • Search the list for a given item • Sort the list • Insert an item in the list • Delete an item from the list • Print the list © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 3
4.
4 Searching • Sequential search
algorithm: • Not very efficient for large lists • On average, number of key comparisons is equal to half the size of the list • Does not assume that the list is sorted • If the list is sorted, the search algorithm can be improved © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 4
5.
5 Bubble Sort (1
of 7) • list[0]...list[n - 1] • List of n elements, indexed 0 to n – 1 • Example: a list of five elements (Figure 16-1) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 5
6.
6 Bubble Sort (2
of 7) • Series of n - 1 iterations • Successive elements list[index] and list[index + 1] of list are compared • If list[index] > list[index + 1] - Swap list[index] and list[index + 1] • Smaller elements move toward the top (beginning of the list) • Larger elements move toward the bottom (end of the list) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 6
7.
7 Bubble Sort (3
of 7) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 7 FIGURE 16-2 Elements of list during the first iteration
8.
8 Bubble Sort (4
of 7) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 8 FIGURE 16-3 Elements of list during the second iteration
9.
9 Bubble Sort (5
of 7) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 9 FIGURE 16-4 Elements of list during the third iteration
10.
10 Bubble Sort (6
of 7) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 10 FIGURE 16-5 Elements of list during the fourth iteration
11.
11 Bubble Sort (7
of 7) • List of length n • Exactly n(n - 1) / 2 key comparisons • On average n(n - 1) / 4 item assignments • If n = 1000 • 500,000 key comparisons and 250,000 item assignments • Can improve performance if we stop the sort when no swapping occurs in an iteration C++ Programming: Fro© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom m Problem Analysis to Program Design, Seventh Edition 11
12.
12 Insertion Sort (1
of 8) • Sorts the list by moving each element to its proper place C++ Programming: From Problem Analysis© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom to Program Design, Seventh Edition 12 FIGURE 16-6 list FIGURE 16-7 Sorted and unsorted portion of list
13.
13 Insertion Sort (2
of 8) • Consider the element list[4] • First element of unsorted list • list[4] < list[3] - Move list[4] to proper location at list[2] C++ Programming: From Problem Analysis to Prog© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom ram Design, Seventh Edition 13 FIGURE 16-8 Move list[4] into list[2]
14.
14 Insertion Sort (3
of 8) C++ Programming: From Pro© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom blem Analysis to Program Design, Seventh Edition 14 FIGURE 16-9 Copy list[4] into temp
15.
15 Insertion Sort (4
of 8) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 15 FIGURE 16-10 list before copying list[3] into list[4] and then list[2] into list[3]
16.
16 Insertion Sort (5
of 8) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 16 FIGURE 16-11 list after copying list[3] into list[4] and then list[2] into list[3]
17.
17 Insertion Sort (6
of 8) © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 17 FIGURE 16-12 li s t after copying t emp into li s t[ 2 ]
18.
18 Insertion Sort (7
of 8) • During the sorting phase, the array is divided into two sublists: sorted and unsorted • Sorted sublist elements are sorted • Elements in the unsorted sublist are to be moved into their proper places in the sorted sublist, one at a time © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 18
19.
19 Insertion Sort (8
of 8) • List of length n • About (n2 + 3n – 4) / 4 key comparisons • About n(n – 1) / 4 item assignments • If n = 1000 • 250,000 key comparisons • 250,000 item assignments C++ Progra© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom mming: From Problem Analysis to Program Design, Seventh Edition 19
20.
20 Binary Search (1
of 2) • Much faster than a sequential search • List must be sorted • “Divide and conquer” • Compare search item with middle element • If less than middle: search only upper half of list • If more than middle: search only lower half of list © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 20
21.
21 Binary Search (2
of 2) C++ Programming: From P© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom roblem Analysis to Program Design, Seventh Edition 21 FIGURE 16-14 Search list, list[0]...list[11] FIGURE 16-15 Search list, list[6]...list[11]
22.
22 Performance of Binary
Search • If L is a sorted list of size 1024 • Every iteration of the while loop cuts the size of the search list by half • At most, 11 iterations to determine whether x is in L • Binary search will make 22 comparisons at most • If L has1,048,576 elements • Binary search makes 42 item comparisons at most • For a sorted list of length n: • Maximum number comparisons is 2log2n + 2 © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 22
23.
23 vector type (class)
(1 of 4) • Only a fixed number of elements can be stored in an array • Inserting and removing elements causes shifting of remaining elements • vector type implements a list • vector container • vector • vector object • object C++ Programming: From Problem© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom Analysis to Program Design, Seventh Edition 23
24.
24 vector type (class)
(2 of 4) C++ Programming: From Problem© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom Analysis to Program Design, Seventh Edition 24 TABLE 16-1 Various Ways to Declare and Initialize a vector Object
25.
25 vector type (class)
(3 of 4) C++ Prog© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom ramming: From Problem Analysis to Program Design, Seventh Edition 25 TABLE 16-2 Operations on a vector Object
26.
26 vector type (class)
(4 of 4) C++ Programming: From Prob© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom lem Analysis to Program Design, Seventh Edition 26 TABLE 16-2 Operations on a vector Object (cont’d.)
27.
27 Vectors and Range-Based
for loops • Can use range-based for loop in C++11 Standard to process vector elements for (auto p : list) //for all p in list cout << p << " "; cout << endl; • Can initialize a vector object vector<int> intList = {13, 75, 28, 35}; © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 27
28.
28 Summary (1 of
2) • List • Set of elements of the same type • Sequential search • Searches each element until item is found • Sorting algorithms • Bubble sort • Insertion sort © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 28
29.
29 Summary (2 of
2) • Binary search • Much faster than sequential search • Requires that the list is sorted • vector type • Implements a list • Can increase/decrease in size during program execution • Must specify the type of object the vector stores © 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a password-protected website for classroom 29
Download now