0% found this document useful (0 votes)
102 views30 pages

MA214 Lecture Slides 0

The MA214 course at the London School of Economics focuses on the design and analysis of algorithms, requiring a prerequisite understanding of mathematical proofs. Students will learn algorithmic thinking, programming in Python, and various algorithmic techniques through lectures and problem sets. The course includes assessments through a written examination and coursework, with an emphasis on self-study and active participation.

Uploaded by

daveasekas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views30 pages

MA214 Lecture Slides 0

The MA214 course at the London School of Economics focuses on the design and analysis of algorithms, requiring a prerequisite understanding of mathematical proofs. Students will learn algorithmic thinking, programming in Python, and various algorithmic techniques through lectures and problem sets. The course includes assessments through a written examination and coursework, with an emphasis on self-study and active participation.

Uploaded by

daveasekas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

MA214 – Algorithms and Data Structures

Julia Böttcher, London School of Economics and Political Science

Week 1 (part 1): Introduction and course logistics


Introduction
We are …

Julia Böttcher (lecturer and class teacher)


Email: [email protected]

Cameron Strachan (class teacher)


Email: [email protected]

Office hours: http://www.lse.ac.uk/Mathematics/internal/Office-hours

1
Course goals

This course is about

• the design and analysis of algorithms.

In this course you will

• learn to think algorithmically,


• learn to formally reason about algorithms,
• acquire a basic algorithmic toolkit.

This course has a prerequisite: MA102/MA103.

• We assume: Comfort with comprehension and construction


of mathematical proofs.
2
Course goals

You will also do

• some programming in Python.

The purpose of this is

• to make the subject more tangible,


• not to make you a stellar programmer.

Why take this course?

• Algorithms are fundamental.


• Algorithms are useful.
• Algorithms are fun.
3
What is an algorithm?

4
What is an algorithm?

Input Algorithm Output

An algorithm is any well-defined computational procedure that


• Takes some value, or set of values, as input
• Produces some value, or set of values, as output

4
What’s an algorithm?

We can also view an algorithm as a tool for solving a well-specified


computational problem.

For example:

• The sorting problem:


• Input: A sequence of n numbers ⟨a1 , a2 , . . . , an ⟩
• Output: A permutation (reordering) ⟨a′1 , a′2 , . . . , a′n ⟩ of the input
sequence such that a′1 ⩽ a′2 ⩽ . . . ⩽ a′n

E.g.: ⟨41, 39, 59, 26⟩ → ⟨26, 39, 41, 59⟩


5
What’s an algorithm?

More generally:

• A computational problem defines a desired input-output relationship.


• An algorithm describes a specific computational procedure for achieving that
input-output relationship,
• like a recipe that gives instructions for turning a given input into a
corresponding output

Which examples do you know?

6
Examples of famous algorithms

• The Euclidean Algorithm (for the greatest common divisor)


• Newton’s method (for finding approximate roots of a function)
• Simplex method (an algorithm for linear optimisation)
• RSA (public-key cryptography algorithm)
• Dijkstra’s shortest path algorithm (navigation)
• MP3 algorithm (audio data compression)
• PageRank (Google’s algorithm to find and rank search results)
• …

7
How do we describe algorithms?

Algorithms can be described in words or in pseudocode.


GCD Problem: Given integers x and y, find their greatest common divisor.
Algorithm: Euclidean algorithm

8
How do we describe algorithms?

Algorithms can be described in words or in pseudocode.


GCD Problem: Given integers x and y, find their greatest common divisor.
Algorithm: Euclidean algorithm
Verbal Description:
Given integers x and y, at each stage, replace x with the previous value of y and y
with the remainder when the previous value of x is divided by the previous value
of y. Stop this process when y becomes zero and return the current value of x as
the greatest common divisor of the original x and y.

8
How do we describe algorithms?

Algorithms can be described in words or in pseudocode.


GCD Problem: Given integers x and y, find their greatest common divisor.
Algorithm: Euclidean algorithm
Pseudocode — high level:
Iteratively calculate (xi , yi ) with x1 = x and y1 = y,
and with xi+1 = yi
and yi+1 = remainder of xi divided by yi ;
stop when yi+1 is 0, and return xi+1 .

8
How do we describe algorithms?

Algorithms can be described in words or in pseudocode.


GCD Problem: Given integers x and y, find their greatest common divisor.
Pseudocode — lower level:
Algorithm 1 The Euclidean Algorithm
1: Algorithm GCD(x, y)
2: a←x
3: b←y
4: while b ̸= 0 do
5: t←a
6: a←b
7: b ← t mod b
8: return a
8
How do we describe algorithms?

Algorithms can be described in words or in pseudocode.


GCD Problem: Given integers x and y, find their greatest common divisor.

Python code:

def gcd(x,y):
a=x
b=y
while b!=0:
t=a
a=b
b=t%b
return a

8
What is there to understand?

Correctness
• How can we show that an algorithm actually computes
a valid solution?

Running time
• How do we measure how fast a specific algorithm
for a given problem is?

9
Analysis versus design

Is it correct? How fast is it? How do we compute it?

10
Often important

How do we store and organise the data?

• A data structure is a way of storing and organising data so as to facilitate


different types of access and manipulations.
• No single data structure works well for all purposes.
• So it is important to know the strengths and limitations of several of them.

11
Topics

Week 1 Introduction, Course logistics,


Do you know how to multiply integers?
Week 2 The sorting problem, InsertionSort, MergeSort, Loop invariants,
Big-O notation
Week 3 Working with Big-O notation, HeapSort
Week 4 QuickSort, Beyond worst-case analysis, Randomised QuickSort
Week 5 Lower bound for comparison sorts, Sorting in linear time

12
Tentative topics

Week 6 Lists in Python, Stacks, Queues, Hashing


Week 7 Graph problems, Breadth-first search, Depth-first search
Week 8 Minimum Spanning Trees, Prim’s algorithm, Kruskal’s algorithm,
Greedy Algorithms
Week 9 Single-Source Shortest Paths
Week 10 Maximum Flow problems, The Ford-Fulkerson Method,
Edmonds-Karp algorithm

13
Course logistics
(See also the course moodle page.)
Lectures and classes

Lectures

• On-campus lectures on Tuesdays, 15:00-17:00 (CLM.5.02)

Classes (consult Timetable)

Note: Classes start in Week 2, not this week. They are compulsory.

In Week 11, there will be no new material, only the last class.

14
Pre-sessional & Self-study Python tutorials

I hope you have completed the Python pre-sessional on Dataquest,


and enjoyed it!

There will also be a number of additional self-study tutorials to prepare you for
the Python programming in this course.

The first two will be available this week, and will cover

(a) how to use Python on the LSE computers or how to install Python on your
personal machine,
(b) the very basics of Python programming to set you up for the programming
that you will do in the first few weeks.

Additional self-study tutorials will be released after the first couple of weeks.
15
Python usage

• The LSE computers should have Python installed.


• Programs can be edited with Notepad++ (or other text editors).

• If you can, working on your own computer is recommended.


• You can use any IDE (Integrated Development Environment).
• For a simple IDE, you can try Wing 101, which is free and linked on Moodle.
• Another nice and powerful IDE is Spyder, which is also installed on LSE
computers (you can find it under ‘Anaconda’). This is also free and linked on
Moodle.

16
Problem sets

• Weekly problem sets: Mix of theoretical and practical questions.

• They will be released after the lectures and are due the following week. .
• The first problem set will be released this week.

• They will be marked for feedback, but do not contribute to final mark.
• You will submit your solutions on a platform called Gradescope.
• Please write your name and class group number on solutions that you hand
in.

17
Lectures

Purpose of the lectures:


• provide background and introduce important algorithmic ideas,
• focus on the design and analysis of algorithms.

Material provided:
• slides,
• pointers to relevant chapters/sections in the course’s main textbook.
• Read those sections!

18
Textbook

Cormen, Leiserson, Rivest, Stein.


Introduction to Algorithms, 3rd edition.
MIT Press.
Available online via LSE Library.

In addition:
Kleinberg, Tardos. Algorithm Design,
1st edition. Pearson.

19
Classes

Purpose of the classes:


• discuss the most recent homework,
• additional material/examples as time permits.

Material provided:
• written solutions,
• python code.

20
Assessment

Written examination (80%):


• standard, closed-book in-person exam,
• In the summer examination period.

Assessed coursework (20%):


• released at the end of WT,
• “big” problem set.
• You will have 14 days to solve it.

21
How to be successful in this course

Start working early! Expect a decent amount of self study!


• Do the self-study tutorials.
• Do the problem sets.
• Recap right after lectures.
• Read relevant book chapters.

Ask questions!
• Ask questions in lectures, classes, office hours.
• Use the discussion forum on Moodle.

22

You might also like