DSA1 | Week 1

Data Structures: Just Some Structured Data

Logistics

Classes
9PM - 10:30 PM on Tuesdays and Thursdays at (1/102)

 

Lab
9PM - 10:30 PM on Fridays at (1/102)

 

Office Hours
Open door policy (i.e, catch me if you can at AB 4/305)

Logistics

Materials
Slides and (usually) notes → Course Webpage

Classes may be recorded: no guarantees!
 

Lab Assignments, Class Quizzes, Exams

Gradescope
 

Announcements & Discussions

WhatsApp Group + Course Webpage

Grading policy

Each of the three exams account for 20% of the grade.
The first and last exams will be pen-and-paper exams. The second exam will be a lab exam.

Each non-practice lab will have a collection of tasks worth 2 points (all-or-none grading). The total number of points you can earn through labs is capped at 20, and accounts for 20% of the grade. There are (tentatively) 11 labs that have graded exercises.

A random subset of classes will start with a short quiz based on the material from recent lectures, worth 2 points. The total number of points you can earn through quizzes is capped at 20, and accounts for 20% of the grade. There are (tentatively) 16 quizzes planned for this course.

The are three assignments that are not graded but are recommended for practice.

Attendance will be tracked for classes and labs. However, there are no points for attending.

Timelines

Lab Assignments are due by midnight on Sundays.

Theory Assignments are ungraded and need not be submitted.

Quizzes will take place in-class.

TAs

1. Yash More

2. Viramgami Gaurav

3. Xhitij Choudhary

TOPICS OVerview

Week 1. Introduction + Stable Marriages

Week 2. Sequences and Graphs

Week 3: Dequeues and Cards

Weeks 4 & 5: Euler Tours

Weeks 6, 7, 8 & 9: BFS/DFS & Applications

Weeks 10: Sorting Algorithms, Asymptotics

Weeks 11, 12, 13 & 14: Heaps, Trees & Search

Weeks 15 & 16: Balanced BSTs

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.

Some more logistics

Notes: https://dsanotes.netlify.app/

Email: neeldhara.m@iitgn.ac.in

Slides: https://slides.com/neeldhara/es242-wXX

XX = 01,02,...,15

The story, all names, characters, and incidents portrayed in this class are fictitious.

No identification with actual persons is intended or should be inferred.

The

Stable Marriage

Problem

Blocking Pairs

When A is matched to B

and X is matched to Y

but A prefers Y over B

and Y prefers A over X.

Goal: Stable Marriage

An assignment with

no blocking pairs.

A Greedy Approach

A strategy for the men: try their best

A strategy for the women: pick the best choice

algorithm stable_matching is
    Initialize m ∈ M and w ∈ W to free
    whilefree man m who has a woman w to propose to do
        w := first woman on m's list to whom m has not yet proposed
        if ∃ some pair (m', w) then
            if w prefers m to m' then
                m' becomes free
                (m, w) become engaged
            end if
        else
            (m, w) become engaged
        end if
    repeat

Men = [n] & Women = [n]

ManPref[m, j] is the identity of the j-th ranked woman in m’s preference list 

WomanPref[w, j] is the identity of the jth
ranked man in w’s preference list.

Next[w] →  the rank of the best unproposed man for w.

Current[m] →   is the identity of the woman m is currently
engaged to and is −1 otherwise

FreeWomenList is the set of unmatched women.

Rank is an n ×n 2D array such that Rank[m,w] is the rank of w in m’s preference list.

To begin with, all women are free (aka, single).

Initialize the best option of woman ito the first position.

Initialize the current matched partner of man i to nobody.

Initialize rank information.

w is a free woman

w is a free woman

Confirm that w is for real.

Check that w has someone left to propose to.

w is a free woman

Confirm that w is for real.

Check that w has someone left to propose to.

m is the best unproposed man for w

w is a free woman

Confirm that w is for real.

Check that w has someone left to propose to.

m is the best unproposed man for w

w' is the current matched partner of m

m is currently free.

match m to w

i.e, m accepts w's proposal

m is currently engaged to w'.

m has a better matched partner in w' compared to w

so, m rejects the proposal from w

and w remains single.

m has a better offer in w compared to his current matched partner w'

so, m accepts the proposal from w

and w goes back to being single.

Book-keeping

Update the position of the best choice for w.

Update w to the next woman who is single.