Algorithms + Programming Languages (Week 5) Flashcards

1
Q

What do many problems in computer science involve?

A

Searching for data, e.g. text search in Word document, Google search, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does Binary Search work? Assume the list is already sorted.

A

Step 1: Identify the middle of the list and split it into two halves

Step 2: If the element we look for is earlier/later in the alphabet than the middle, reduce the list to the lower/upper half

Step 3: Continue with step 1 unless the list contains only 1 element

Step 4: element found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Definition : Runtime Complexity

A

A function that describes the amount of time it takes to run an algorithm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Runtime Complexity of Binary Search?

A

Log2 N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How common of a task is sorting data items?

A) Very common
B) Not common
C) Never done

A

A) Very common

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some methods of sorting?

A

Quicksort, Bubble sort, Selection sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the Runtime Complexity of Quicksort?

A

N x Log2 N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the Runtime Complexity of Bubble sort?

A

N^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the Runtime Complexity of Selection sort?

A

N^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Definition : “Easy” Problem

A

Algorithms with runtime complexities like Log N, N, N × Log N or N2 - these complexities are called polynomial.

Problems that can be solved by algorithms with a complexity that looks like Nx are considered to be “easy” – N is a factor in this formula.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Definition : “Hard” Problem

A

“Hard” problems can only be solved by algorithms with exponential runtime complexity like this: x^N (N is an exponent here, e.g. 2^N)

Nature of exponential problems: if problem size increases by 1, runtime multiplies, e.g., doubles, triples, quadruples etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What situations would need a fast solution?

A

e.g., brake or swerve

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What situation would need a slow solution?

A

e.g. cryptography (decrypting data without knowing the key is “hard”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are some possible runtime complexities?

A

From fastest to slowest :

Log N
N
N x Log2 N
N^2
2^N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are computers? (In terms of what they are able to process)

A

Computers are general purpose computing machines – without software, they don’t know what to do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Definition : Software

A

The term “software” refers to instructions that make a computer do something useful => the “program”

Data is also considered to be software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Differences between hardware and software?

A

Software is intangible – it is not easy to see or put your hands on a sequence of bits (e.g. represented by electrical signals)

Software is more flexible, easier and often cheaper to change (update) than hardware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Definition : Algorithm

A

The purpose of software is to perform a task

If we focus on a task and how to complete it in general, ignoring the details of its implementation as software (e.g. the type of hardware, etc.), we talk about algorithms

An algorithm is a detailed description of a sequence of steps a software (or also a person) needs to perform and in order to solve a problem

19
Q

What is an Algorithm composed of?

A
  1. Sequence of ordered and precisely described steps to achieve a result (solve a problem)
  2. Each step is expressed in terms of basic operations whose meaning is completely specified (There should be no ambiguity about what anything means)
  3. Guaranteed to produce the desired result: all possible situations (input configurations) are covered
  4. Must stop eventually (finite number of steps)
20
Q

What is an example of a High-Level Description of an Algorithm?

A

Example task:
* Find out who is the tallest person of all in the class?
* Computer scientists call this a problem

A high-level description of an algorithm to solve this problem could be:
Ask every person in the room for their body height and report back who is tallest.

21
Q

What are 2 good methods of describing Algorithms unambiguously

A

1) Flow charts
2) Pseudo code

22
Q

Definition : Pseudo Code

A

It is a methodology that allows the programmer to represent the implementation of an algorithm. Simply, we can say that it’s the cooked up representation of an algorithm. Often at times, algorithms are represented with the help of pseudo codes as they can be interpreted by programmers no matter what their programming background or knowledge is. Pseudo code, as the name suggests, is a false code or a representation of code which can be understood by even a layman with some school level programming knowledge.

Eg :

1 set variable tallest to zero (a.k.a. as initialize it)
2 set variable selected to “blank”
3 for every person in the room, repeat steps 4-8
4 ask next person for name and height in cm
5 if height is greater than tallest: perform steps 6 & 7
6 set tallest to height
7 set selected to name
8 thank the current person for their cooperation and go to 3
9 report selected as result
23
Q

How are flowcharts used to define algorithms?

A

Flow charts are used to visualize the “flow of operations” of an algorithm.

Have standardized symbols for different
types of operations.

We will use only 5 of them.

Biggest advantage: easy to read.

Major disadvantage: might be confusing if a chart gets too large.

24
Q

Flow Chart Symbol : Arrow

A

Flow line

Indicates the next operation (the “flow” of operations = sequence) by connecting symbols.

25
Q

Flow Chart Symbol : Oval

A

Stop/Start

Used to represent start and end of a flow chart.

26
Q

Flow Chart Symbol : Parallelogram

A

Input/Output

Used for input and output operations.

27
Q

Flow Chart Symbol : Rectangle

A

Operation

Used for any kind of operation and/or data-manipulation.

28
Q

Flow Chart Symbol : Diamond

A

Decision

Represents a conditional operation that determines which one of two paths the program will take.

29
Q

What does a “good” algorithm look like?

A

For each problem we can probably think of more than one algorithm to solve it

Computer scientists want to find good (= efficient) algorithms that use minimal resources:
* Runtime: how long does it take to compute the result? How much work is it? How many steps/operations are carried out?
* Memory: how much memory is needed to do the calculations? E.g. to store intermediate and final results

Not all problems are equally difficult. Some are computationally harder to solve than others.

30
Q

What is a Linear Algorithm?

A

An algorithm with a computational complexity of N

The number of steps (#) increases linearly with problem size N

If problem size N doubles, the # steps (= runtime) doubles as well

For example:
if N=80 => runtime of 80 ms,
then N=160 => runtime of 160 ms

31
Q

What did Alan Turning do?

A

Proved in 1930’s that all computers (even the Toy) are theoretically equivalent in what they can compute.

Some may be too slow or may not have enough memory for certain tasks, but in theory all have equal capabilities

Turing used the “Turing Machine”, a very simple theoretical computer (even simpler as the Toy Computer) to show this.

32
Q

What is the Turing Award? (Who knows, this might be on a test!)

A

The Turing award, considered to be the Nobel prize of computing, is awarded annually to an individual selected for contributions “of lasting and major technical importance to the computer field”

33
Q

What is the Turing Test?

A

Turing also proposed a test (the Turing test) to assess if a computer was demonstrating human intelligence:

Can a human interrogator only by having a discussion (via keyboard and display) with a computer and a human determine which one the computer is?

34
Q

Real CPUs vs. Toy Computer

A

Real CPUs understand more instructions
* A few dozen to a few hundred instructions
* More ways to move data around (e.g. in bulk)
* More ways to do arithmetic calculations
* Ability to handle different sizes and kinds of numbers

Multiple accumulators (also known as registers)
* Perhaps 16 to 32
* Enables more elaborate instructions, e.g. add 3 numbers at once

Programs typically have millions of instructions or more

35
Q

What are some methods of speeding up CPU perfomance?

A

CPUs use several mechanisms to speed up computations e.g. Caching, Pipelining, Parallel Computing

36
Q

Definition : Caching

A

One way to improve execution speed of a program is Caching – a general strategy that is quite common

Caches store copies of data items to serve future requests faster and to avoid waiting times

Is frequently used, e.g. for buffering for video streaming

Caching is a very useful strategy for CPUs as they have to deal with much slower devices

37
Q

Sort from Fastest to slowest : RAM, CPU, Storage

A

CPU speed:
* With 1 GHz clock speed => one operation per nanosecond Accumulators inside the CPU also work with this speed

RAM speed:
* A data fetch operation (copy data from RAM into the accumulator) could take 25 to 50 nanoseconds
* That is 25 to 50 CPU cycles => CPU must wait!

Storage (HD, flash memory, optical disc) speed:
* Access times (fetching) typically are in the range of milliseconds
* 1 millisecond = 1000 microseconds = 1 million nanoseconds

38
Q

Definition : Pipelining

A

Improve CPU speed with Pipelining: let fetch, decode and execute for subsequent instructions overlap; each clock cycle performs all 3 steps!

39
Q

How does Parallel Computing work?

A

Nowadays, CPUs have multiple cores

Similar to multiple CPUs, but sharing RAM and I/O devices

Multiple cores may perform several independent tasks concurrently, e.g. playing music from a streaming provider, editing a Word document and downloading a file

To make use of multiple cores, an app has to be programmed for it. Otherwise, apps typically use only one core at a time.

Parallel computing: divide a single task into smaller subtasks and perform those subtasks in parallel to get the final result faster

40
Q

What is a Supercomputer?

A

High performance supercomputers feature a large number of processors and lots of memory, e.g. 7,299,072 cores (Fugaku)

Are used for computation- intensive scientific calculations and simulations E.g. weather and climate simulations

41
Q

What is an Embedded System?

A

Embedded systems are computer systems with a dedicated function within a larger mechanical or electrical system.

Embedded means they are part of an integrated device often including hardware and mechanical parts, e.g. washing machine

They often operate under real-time computing constraints and guarantee defined response times, e.g. anti-lock braking system of a car

98 percent of all microprocessors are manufactured as components of embedded systems.

42
Q

Representation of programs in RAM (This isn’t a question so just flip it)

A

The Toy Computer uses simplified RAM
* Every memory location can store a label and one instruction or one data item

A more realistic system would be
* Each memory location stores 1 byte (e.g., a number)
* Memory locations have a serial number (address)
* A label in fact is the address of a memory location
* Instructions are encoded as numbers
* If an instruction refers to a memory location, the location ́s address is stored in the next memory location

43
Q

Can all tasks be done with parallel computing?

A

Some tasks cannot be divided into independent subtasks

  • Task 1: Add up a list of 8 numbers
    => can easily be divided into two separate subtasks (need to add one extra addition to get the final result)
  • Task 2: Add up a list of 8 numbers with sub-totals
    => each addition depends on the previous result
    => subtasks are not independent and cannot run in parallel