Algorithms and Data Structures TEACH THAT
Algorithms and Data Structures An algorithm does something, solves some problem, in a mechanical way. It is a bit like a “machine” or a specialised tool
Algorithms and Data Structures A data structure is some way to represent and store data so that we can process that data efficiently
Algorithms and Data Structures Data structures use algorithms Algorithms use data structures
Algorithms and Data Structures Data Structures and Algorithms a Computer Scientist’s building blocks
Algorithms and Data Structures Computer Scientist invent and study algorithms and data structures and problems
Algorithms and Data Structures Computer Scientists do other things too
Our website, link from moodle
Lecture
14 Why don’t I just go away and read the book myself? Why come to lectures? meet new exciting people keep in touch with fashion, trends, … be part of the “in” crowd ADS2 Lecture 1 Lectures … Aye, right.
Algorithms & Data Structures Algorithms & Data Structures Great!
Now and then I will take an attendance register
Lassie, what’s in this ADS2 course ? Will it be interesting? woof!
Content linked lists single/doubly-linked, insert, delete, find, min, max, … stacks push/pop/size bracket matching, RP calculator queues enqueue/dequeue/size circular queue (in array) recursion see above big O
Content trees n-ary trees: representations & properties binary trees representations & properties & traversals binary search trees insert/find/delete/traverse/height … AVL trees heap insert/delete/sort splay trees (maybe) red-black trees (maybe) Continued
Content skip lists (maybe) Sorting bubble/insert/sift sort merge sort quick sort bucket sort (pigeon hole sort) bead sort (maybe) Dictionaries maps and hash tables open and closed hashing Continued
Content Continued 5 pieces of practical work 2 of above are assessed (20%) exam in May (80%) lab every 2 nd week woof
Algorithms & Data Structures Algorithms & Data Structures Great!
our ADS2 website under construction (permanently)
Home
News
The lectures
code & api
Lots of code in there
demos
Links to interesting & useful stuff
exercises
Questions & Answers
… and now for something completely different!!!
Lassie, why are algorithms and data structures important?
Lassie, will there be anything in the course that is challenging and exciting?
I just hope I get feedback, continuously
Lassie, will you teach us to “THINK LIKE A COMPUTER SCIENTIST”?
Lassie, honestly, I’m not that experienced as a programmer. Will you help us with our programming?
Will we use BIG data sets?
woof!
1 st lecture … “Who cares?”
algorithms are ancient Many algorithms predate computers
But first … what is an algorithm?
What is an algorithm? A finite sequence of instructions, each with a clear meaning, and can be performed with a finite amount of effort in a finite length of time [Aho, Hopcroft, Ullman 1983]
Before some of you were born
Abu Jafar Mohammed ibm Musa Al Khwarizmi 800AD Before I was born
Euclid of Alexandria 325BC to 265BC GCD
Data Structures … what’s that then?
ways to organise data/information efficiently where will I (not) see data structures? Data structure Not a Data structure – ADT (see next slide)
abstract data types?
Definitions contd. Basically an ADT is an “abstract” entity But a data structure has a fixed implementation (as well as “structural” properties). 60ADS2 Lecture 2
Who cares? Machines are getting bigger, faster, cheaper … do efficient data structures and algorithms really matter?
Bigger, faster, cheaper machines Bigger data sets, greater expectations
An Example: from problem to program Sequencing traffic lights A Formal Model
A-left A-right
A-left A-right B-right B-left B-straight
A-left A-right B-right B-left B-straight C-straight
ALAL ARAR BRBR BSBS BL CSCS
ALAL ARAR BRBR BSBS CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Draw a line (edge) between turns that CANNOT occur at the same time Draw a line (edge) between turns that CANNOT occur at the same time
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed)
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour” Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed)
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Label turns that have an edge between them (adjacent) differently. The minimum number of labels used Is the minimum (maximum) number of concurrent turns disallowed (allowed) For “label” let’s use “colour”
ALAL ARAR BRBR BSBS BL CSCS Therefore we could allow same coloured turns to go at the same time: blue, green, pink and it will be collision-free
ALAL ARAR BRBR BSBS BL CSCS We have 3 time steps
ALAL ARAR BRBR BSBS BL CSCS Could we do it in less than 3 time steps? Is this solution unique? What is the “underlying” problem? What is its complexity? Are there any algorithms that can be used?
ALAL ARAR BRBR BSBS BL CSCS Is Dobie’s Loan actually scheduled optimally?
ALAL ARAR BRBR BSBS BL CSCS Might this be an obvious solution?
B C A E D Try This One way JoJo’s intersection, Princeton
B C A E D AB AC AD BA BC BD DA DB DC EA EB EC ED turns
B C A E D JoJo’s intersection, Princeton
B C A E D JoJo’s intersection, Princeton, USA (allowed a right turn against the lights)
B C A E D JoJo’s intersection, Princeton ED EA BC EC EB DC DA BA AD AC DB AB BD
B C A E D JoJo’s intersection, Princeton ED EA BC EC EB DC DA BA AD AC DB AB BD JoJo’s intersection, Princeton, USA (allowed a right turn against the lights)
B C A E D JoJo’s intersection, Princeton ED EA BC EC EB DC DA BA AD AC DB AB BD
B C A E D JoJo’s intersection, Princeton ED EA BC EC EB DC DA BA AD AC DB AB BD 4 colours 4 steps
B C A E D JoJo’s intersection, Princeton ED EA BC EC EB DC DA BA AD AC DB AB BD 4 colours 4 steps 4-clique!