Comp Exam paper 1 Flashcards

1
Q

What is meant by recursion?

A

A recursive route is one that is defined in terms of itself

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

How do stacks work?

A

They store items and follow a last in first out (LIFO) rule. (Like taking from a stack of plates). Used to stored actions so they can be undone.

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

What does pushing the stack do?

A

Used to add items to the stack. Pushes the top position of the stack up and adds the item to the stack.

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

What does popping the stack do?

A

Used to remove elements from the stack. Moves the top of the counter down and removes the item.

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

What function has a constant time?

A

f= O(n^0)

f=O(1)

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

What function has a logarithmic time?

A

f= O(log n) : The Binary search
List is split into half with one rejected
f = O(n log n) : Merge sort

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

What function has a linear time?

A

f= O(n) : Linear Search

Checks each element of the list individually

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

What function has a polynomial time?

A

f= O(n^2) : Bubble sort- swaps item if one is bigger

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

What function has exponential time?

A

f= O(2^n) : Fibonacci

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

What function has factorial time?

A

f= O(n!) : Travelling salesman problem

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

What are intractable problems?

A

Problems that can be solved by a computer, but not in a reasonable amount of time when there are large inputs. (Less than polynomial time)

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

What is an heuristic approach?

A

A guessed solution can be checked in polynomial time. Problem becomes tractable.

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

What is the halting problem?

A

An unsolvable problem which asks whether it is possible to create a program which takes another program as an input and determines whether it will halt or loop infinitely.

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

How should you compare Algorithms?

A

Time complexity: How long it takes to complete a task with a given input
Space complexity: How much memory an algorithm needs to complete a task with a given input
Order of growth: How quickly the complexity grows with growth in input size

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

What is the proof of the halting problem?

A
def(g):
           If halts(g):
                   loop_forever()
If halts(g) is true, g will call loop forever and will never halt.
If halts(g) is false, g will halt as it doesn’t call loop forever. This is a contradiction.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do queues work?

A

They follow a first in, first out rule (FIFO). Has a front of queue, end of queue, size of queue and max size of queue.

17
Q

What is a static data structure?

A

They have a fixed size The allocated memory cannot change at runtime. An example is a static array. Doesn’t have overflow or underflow errors

18
Q

What is a dynamic data structure?

A

It’s size can grow or shrink at runtime. Often consists of pointers. More efficient use of memory

19
Q

What are the differences between static and dynamic structures?

A

Static data structures have a fixed maximum size, whereas the size of dynamic data structures can change

20
Q

What does peeking the stack do?

A

Looks at the previous item in the stack

21
Q

What are trees and graphs?

A

A way of representing real world problems. It has vertices and edges

22
Q

What is used to models trees and graphs?

A

Arrays

23
Q

When would you use an Adjacency matrix?

A

When there are many connections (edges)

24
Q

When would you use an Adjacency list?

A

When there are few edges(connections)

25
Q

What is a weighted graph?

A

A graph with edges that are labelled with numbers (a weight)

26
Q

How would you trace a breadth-first search? ⭐️

A

Use a queue and would find the route with the great vertexes between the start and the end. Finds shortest path for an unweighted graph.

27
Q

How would you trace a depth first search?

A

Use a stack and exhaustively search each branch to its depth, then back track. Uses less more than breadth first search. Good for navigating a maze.

28
Q

What is the purpose of Dijkstra’s algorithm?

A

It finds the shortest path between a node and every other node in a weighted graph. Similar to breadth search but uses a priority queue rather than fifo.

29
Q

What are the properties of a tree?

A

It is a connected, unidirectional graph with no cycles.

30
Q

What is an array?

A

A data structure that holds similar or related data

31
Q

What is a one dimensional array?

A

A type of linear array. Good for storing a vector

32
Q

What is a two-dimensional array?

A

Can be visualised on a grid with rows or columns. Good for representing a matrix