Docsity

Using Abstractions: Breadth-First Search, Schemes and Mind Maps of English

Partial preview of the text

Download Using Abstractions: Breadth-First Search and more Schemes and Mind Maps English in PDF only on Docsity!

Using Abstractions:

Breadth-First Search

What new data structures have you recently

noticed in your day-to-day life?

(put your answers the chat)

vectors + grids

stacks + queues

sets + maps

Object-Oriented Programming

arrays

dynamic memory management

linked data structures

algorithmic testing analysis

recursive problem-solving

Roadmap

Life after CS106B!

C++ basics

Diagnostic

real-world algorithms

Core Tools

User/client Implementation

Object-Oriented Programming

arrays

dynamic memory management

linked data structures

algorithmic testing analysis

recursive problem-solving

Roadmap

Life after CS106B!

C++ basics

Diagnostic

real-world algorithms

Core Tools

Implementation

vectors + grids

stacks + queues

sets + maps

User/client

Today’s

question

How can we use the

unique properties of

different abstractions to

solve problems?

Review

(sets and maps)

What is a set?

● A set is a collection of elements with no duplicates.

● Sets are faster than ordered data structures like vectors – since there are no duplicates, it’s faster for them to find things. ○ (Later in the quarter we’ll learn about the details of the underlying implementation that makes this abstraction efficient.) ○ We’ll formally define “faster” on Thursday.

● Sets don’t have indices!

Ordered ADTs

Elements accessible by indices:

● Vectors (1D) ● Grids (2D)

Elements not accessible by indices:

● Queues (FIFO) ● Stacks (LIFO)

Unordered ADTs

● Sets (elements unique) ● Keys (keys unique)

Useful when numerical ordering of

data isn’t optimal

Activity:

Counting Sort

Counting Sort

● Sorting is a fundamental topic in computer science and one that we will revisit in more depth later this quarter

● For now, let's consider this question: how would you efficiently sort all the letters in a word in alphabetical order? ○ How can we take advantage of some of the data structures we've recently learned about to meaningfully structure the data that we want to sort?

Example and slides taken from a slide deck by Keith Schwarz

Counting Sort

● Sorting is a fundamental topic in computer science and one that we will revisit in more depth later this quarter

● For now, let's consider this question: how would you efficiently sort all the letters in a word in alphabetical order? ○ How can we take advantage of some of the data structures we've recently learned about to meaningfully structure the data that we want to sort?

● Idea: If we can tally up how many times each of the letters from 'a' to 'z' shows up, we can then build a new string composed of the correct number of 'a's, followed by the correct number of 'b's, … etc.

Example and slides taken from a slide deck by Keith Schwarz

Counting Sort Example

Example and slides taken from a slide deck by Keith Schwarz

Counting Sort Example

Example and slides taken from a slide deck by Keith Schwarz

Counting Sort Example

Example and slides taken from a slide deck by Keith Schwarz

Counting Sort Example

Example and slides taken from a slide deck by Keith Schwarz