Data Structures and Algorithms
Introduction
executive summary
How we store data is driven by the needs of algorithms that seek to manipulate said data.
In these slides, we explore some examples of tradeoffs we make when we pick certain data structures over others, using elementary examples.
link to companion notes
Data Structures
Structured Data
You may remember some so-called primitive data types from your programming courses.
Booleans (true/false)
Numbers (integers, floating point, etc.)
Characters and Strings
Etc.
You may also remember combining and manipulating these values for getting things done.
Expressions
Conditionals
Loops
Etc.
Structured Data
We are going to be doing more of this!
Start out with goals: things you want to do.
Think through the mechanics what you want to do.
Work out what would be the most useful way to store information to aid the mechanics.
Structured Data
We are going to be doing more of this!
Goal: Ace this class
Think through the mechanics what you want to do.
Work out what would be the most useful way to store information to aid the mechanics.
Structured Data
We are going to be doing more of this!
Goal: Ace this class
Study the night of the exam.
Work out what would be the most useful way to store information to aid the mechanics.
Structured Data
We are going to be doing more of this!
Goal: Ace this class
Study the night of the exam.
Maintain notes that will help you digest several weeks of material in a few hours.
Structured Data
We are going to be doing more of this!
Goal: Enjoy college life, YOLO
Study the night of the exam.
Maintain notes that will help you digest several weeks of material in a few hours.
Structured Data
We are going to be doing more of this!
Goal: Enjoy college life, YOLO
Never look at notes 馃憖
Maintain notes that will help you digest several weeks of material in a few hours.
Structured Data
We are going to be doing more of this!
Goal: Enjoy college life, YOLO
Never look at notes 馃憖
[Nothing to do.]
Structured Data
We are going to be doing more of this!
Goal: Enjoy college life, YOLO
Never look at notes 馃憖
[Nothing to do.]
Structured Data
We are going to be doing more of this!
Goal: Enjoy college life, YOLO
Never look at notes 馃憖
[Nothing to do.]
Structured Data
How you store data depends on what you want to do with it!
Clothes in your cupboard
Structured Data
Suppose you want to represent the polynomial
\(x^2 - 7x + 12\)
Polynomials
How will you talk to your program
about this object?
I pick a number from 1-10.
The Game of 100
You pick a number from the next 10 numbers.
We go on like this until someone reaches 100.
First player to reach 100 wins.
Suppose you have 52 cards.
Storing a hand from a deck
You want to maintain a hand of five cards.
Given a card you want to know if it is in the hand.
You want to be able to add/remove/replace cards in the hand.
A Rubik Cube has six sides, and 9 squares on each side.
Solving a Cube
8 corner cubes, 12 edge cubes, 6 more cubes:
one in the center of each face,
and 1 cube (which doesn't actually exist
Given a shuffled state, you want to solve the cube.
The Game of Trust
my_points = 0
user_points = 0
user_move_1 = input("Input 1 for Cooperate and 0 for Cheat.")
#Sanity check input:
if(user_move_1 != 1 and user_move_1 != 0):
express disappointment and abort
##My first move is to cooperate:
my_points += -1
user_points += 3
if(user_move_1):
my_points += 3
user_points -= 1
Majority Mover
This player looks at your entire game history, and:
-
cooperates if you have cooperated more than you have cheated,
-
cheats if you have cheated more than you have cooperated,
-
and acts randomly otherwise.
Random Player
This one chooses a number K between 1 and N uniformly at random,
(where N is the number of rounds played so far)
and mimics the other player's Kth move.
DSA 路 Introduction
By Neeldhara Misra
DSA 路 Introduction
Data Structures: Just some Structured Data
- 473