Fundamental Problems Flashcards
What are compiled languages?
The whole program is converted/compiled into machine code before being run, and only runs on a specific type of machine
What are interpreted languages?
An interpreter reads a small number of instructions at a time and translates them
Differences between compiled and interpreted languages
Compiled: Faster, code is analysed and optimised during compilation, avoids certain runtime errors
Interpreted: Better use of memory, easier to develop software with
How do bytecode languages such as Java work?
Programs are compiled into bytecode, which is higher level than machine code but still fast to interpret, and then translated by a virtual machine
Difference between syntax and semantics
Syntax is how a program is written, semantics is what it means
Denotational semantics
A program’s meaning is given mathematically as a suitable mathematical structure
Typical problems in Computer Science
How can we write programs that don’t have bugs?
How do we store things and find things?
Is P equal to NP?
How do we make computers easily programmable?
What is key to problems in Computer Science?
Solutions to problems are constructive, we want methodologies (algorithms) that are general (for all inputs)
We want to be able to repeatedly apply solutions
The concern with measuring the difficulty of solving problems (big O etc.)
Important notions for solving problems
Computation (the machine that does the work)
Resources (time and memory taken)
Correctness (the quality and accuracy of the answer)
What is abstraction?
Hiding unnecessary information to make a problem easier to represent and solve
Abstraction vs models
Models have a time component
How would we abstract the internet?
As a collection of nodes, connected by channels along which they can send and receive messages
We can also associate a time with each channel
Travelling salesman’s problem
Calculating the shortest tour of a given collection of cities and finishing where you started
Core information: number of cities, start city, distances between cities
Offline vs online problems
Offline = know all the data in advance
Online = data keeps arriving
Map colouring problem
You have a plane map of regions, which either share a border, meet at a point, or don’t share a border
Can you colour the regions of the map with 3 colours so that if any two regions touch then they must be coloured differently
Applications of colouring
Scheduling jobs onto a CPU
Register allocation
Radio frequency assignment
Draughts problem
n by n board
Given a legal position of white and black checkers where it’s white’s turn, does black have a winning strategy
Informal definition of a decision problem
Consist of a set of instances
Each instance either corresponds to the answer “yes” or the answer “no”, and it’s our job to decide which one
We solve a decision problem by coming up with an algorithm to determine whether a given instances is a yes-instance or not
Formal definition of a decision problem
Consists of a set of instances I, and a subset Y of yes-instances
The no instances are I \ Y
How would we abstract the map-colouring problem?
Represent an instance of the problem as a graph G = (V, E) where V is a set of vertices (one for each region), and E is a set of pairs of vertices
(u, v) is only in E if region u touches region v
The problem is solved when each vertex in V is coloured and no pair in E contains two vertices of the same colour
How can the scheduling, register allocation and radio frequency assignment problems be represented as graph colouring problems?
If two tasks depend on each other and can’t run at the same time, represent them in a graph as nodes with an edge joining them and then colour the graph. Only tasks with the same colour can run at the same time.
Definition of a search problem
Consists of a set of instances I, set of solutions J, and a binary search relation that maps one instance to one solution. There can be any number of solutions corresponding to an instance
Solving a search problem
For an instance x in I, find a solution y in J such that (x, y) is in R, otherwise answer “no”
Decision problem vs search problem
For any decision problem, there is usually a search problem. For example, the search problem corresponding to the 3-colouring problem is actually finding a valid colouring.
There is always a decision problem corresponding to a search problem. The yes-instances are the instances which have a solution.