stuff bad Flashcards

1
Q

A new employee called CHRISTOPHER WAY is added to a hash table, however the key generated is the same as that of CAMERON WALKER. Explain what the affect of this would be and suggest a possible solution.

A
  • the two names would be written to the same address
  • the new name would overwrite the old one
  • store the new name in the next open address in the hash table
  • store a pointer that points to a list fo values that have the same key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

One advantage for storing text data in a file.

A

human readable

can be opened in a general purpose text editor

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

Explain what is meant by LIFO

A

(you must say last in first out)

the most recently added item will be the first on not be accessed. LIFO is a stack

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

state a set that is infinite.

A

N OR R (natural or real)

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

Explain ‘encapsulate what vaires’

A

means that individual classes should only contain attributes and methods that differ from other classes

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

State two items that will be stored in the stack frame when a subroutine is stored.

A
  • local variables
  • parameters
  • return address
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain what is meant by inheritance

A

a class/subclass/child class that shares attributes or methods from a base/parent/super class

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

State the name for adding two vectors

A

translation

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

How do you identify a constructor from a class diagram?

A

The constructor method should always have same identifier as the class

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

explain what is meant by the base case of a BNF rule

A

a non-recursive case
or
a case that doesn’t include an example of the definition within the definition

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

sate the base case of rule 1

1 ::= | _
2 ::= | _
3 ::= a|b|c|d|e|f|g|h|….

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

State one disadvantage of using a binary search instead of a linear search

A

list must be sorted

linear search is easier to program

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

There is an attribute fuellevel explain why there is also a method named getfuellevel()

A

the fuellevel attribute is private and so can only be accessed within its class.

the getfuelevel method is public and so can be accessed within other classes.

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

Difference between public, private, protected.

A
public = can be accessed/called by any class
private = can only be accessed/called by that class
protected = can only be accessed by derived class/ subclass (and its self)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe a typical use for calculating a dot product of two vectors

A

find the angle between two vectors

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

give the Cartesian product of

A = {1, 2} and B = {5, 6, 7}

A

{(1, 5), (1, 6), (1, 7), (2, 5), (2, 6), (2, 7)}

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

Explain how and why hashing algorithms are often used for storing passwords

A

HOW
complex hashing algorithms are used to create complex keys

the keys are stored instead of the password

each time the user enters their password, the hashing algorithm is applied and the key is compared to the key that is stored

WHY
in the event of a data breach, only the hash keys can be discovered

a malicious user who is able to access the hash keys, will not be able to login

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

Describe the difference between association aggregation and composition aggregation

A

association aggregation describes a ‘has a’ relationship between two classes where both exist independently

in composition aggregation the parent class is composed of the child class object, so if the parents object is destroyed so are the child objects.

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

Describe two advantages for using procedures and functions in a program. (4 marks)

A

(in pairs)
- code can be called from different points in the program |
reducing the need to duplicate code

or

  • code is easier to update/maintain |
    because the programmer only had to update one subroutine no matter how many times its used

or

  • easier to debug code |
    because an error will likely only need to be found and fixed once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Give two potential disadvantages for storing binary data in a file.

A

only this program will be able to decode the date/understand

the file can not be read/understood by general purpose software

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

Describe one advantage of storing binary data in a file

A

smaller file size

data more secure/ no human readable, so cannot be easily altered

developer has more control over the program/data

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

State the most appropriate data type for:

12.67

A

real/float

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

Explain why it is preferable to use a procedural paradigm rather than a program that does not use procedures.

A

code can be reused
each change of the code only needs to be changed once
easier to find and debug errors

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

State two reasons why it is usually preferable that subroutines don’t use global variables?

A
  • easier to reuse in another program.
  • subroutine can be used in a library
  • the code is easier to understand
  • make sure the code is independent of the rest of the program
  • more memory efficient
  • makes it easier to debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Describe what is meant by a dictionary data structure

A

key-value pair, in which the value is accessed via the key

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

Explain what is meant by the term instantiation.

A

instantiation is the process of creating an object based on a class | it is carried out using a constructor providing values for each of the attributes.

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

Explaining what is meant by overriding

A

overriding is creating a method in a subclass that has the same identifier as a method of a parent class

in order to give the subclass method different functionality

in this case, the subclasses have different attributes to set and so different functionality/code is required

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

Explain why inheritance might be preferable (2 marks)

A

the attributes and methods in the base/parent class can be reused in each sub/child class (1)

One from (1)
avoids duplication of code
makes the code easier to maintain or update.
29
Q

how do you know when the scaling factor of two vectors doesn’t change the translation.

A

sum of coefficients = 1

30
Q

State a simple rule for recognising which of a list of BNF rules could or could not be defined using a regular expression.

A

Definitions involving recursion cannot be defined using a regular expression.

31
Q

There is an attribute fuellevel and there is also a method named getfuellevel()

Why is this favoured in object oriented programming?

A

this allows classes to maintain control over their own attributes

this allows for the way that the fuellevel is stored to be changed in the future without having to rewrite or modify code in their classes

OR

this stops other classes from changing the attributes of your class. Your class should control all it’s attributes and never other classes.

32
Q

Explain what is meant by FIFO

A

(you must say first in first out)

the items will be accessed in the order they were entered. FIFO is a queue

33
Q

Other than time complexity, state one other measure of the efficiency of an algorithm.

A

space complexity

memory requirements

34
Q

describe one example of inefficiency in the bubble sort algorithm

A

even if the list is fully sorted before the bubble sort is complete it will continue to run unnecessarily

35
Q

explain how the bubble sort algorithm could be changed to reduce then number of comparisons required

A

if a swap is needed then a flag should be set to true

a while loop based on the value of the flag will repeat while the flag is true

the flag is set to false before you start the inner loop

36
Q

describe 3 uses for a depth first search

A

navigating a maze
creating a minimum spanning tree
detecting a cycle in graph

37
Q

state whether a programmer should use a stack data structure or a queue data structure when creating a breadth first search algorithm, and why

A

queue

a queue is a first in first out (FIFO) data structure and the nodes will be visited in the order they are found

38
Q

suggest one feature of a graph that may make it more complex to traverse than a tree

A

a graph may have cycles (but a tree won’t)

39
Q

some graphs require a more complex traversal algorithm suggest one reason why this might be the case

A

some graphs that aren’t trees contain loops

40
Q
you have a parents class called animal a subclass called bird and other one called mammal.
all three classes include a procedure called move()

explain why this technique is appropriate in this case

A

birds and mammals both move in very different ways so need their own implementation of move

all animals can move so it makes sense to include this in the base class

41
Q

explain what is meant by the halting problem

A

it is impossible to know,

whether a program, will eventually stop

42
Q

state the difference between a function and a procedure

A

a function returns a value a procedure does not

43
Q

describe a difference between the way data is stored in a textfile and the way data is stored in a binary file

A

in textfiles all values are stored using a character set (ASCII / UNICODE)

in binary files data is stored using different data types, in binary files data can only be read by the application that created them

44
Q

describe a priority queue

A

A priority queue is essentially two queues. You have a queue for priority items, and a queue for standard items. New priority items are added to the back of the priority queue, and new standard items are added to the back of the standard queue.

Items are removed from the front of the priority queue first. When no priority items are queued, items will be removed from the front of the standard queue.

45
Q

describe a linear queue

A

A linear queue is where items are removed from the front of queue and items are added to the back of the queue. As items are removed from the front of the queue the front of the queue will move further and further back.

If we simply add to the back of the queue and remove from the front in a linear fashion we would eventually reach the maximum limit of the queue and have no more space to add items. Also, there will be wasted empty space at the front of the queue.

It is also impractical to move all the items up a place when an item is removed (as would happen in a shop queue). This would require each item in the queue to be moved every time an item was removed from the queue. This would require too much processing especially for large queue sizes.

46
Q

describe a circular queue

A

Rather than move the data items, we move the front and back pointers as data is added or removed. We still need to know when the queue is full or empty. The easiest method is to simply count the number of items in the queue.

Pointers are required to point to the front and back of the queue. The back pointer always points to the last item in the queue and the front pointer points to the next item to be removed from the front of the queue. Initially rear pointer would be set to 0 and front pointer to 1.

We have a limit to the size of the queue (ie queuemax). To make the queue circular when either pointer reaches queuemax it will next move to position 1.

The queue is full when Number of items = queuemax and the queue is empty when Number of items = 0. We can only add an item if the queue is not full and we can only remove an item if the queue is not empty.

47
Q

explain what is meant by a heuristic technique giving an example

A

a heuristic approach involves finding a solution that might not be the best

eg

  • the algorithm might need to consider visiting less/fewer cells/coordinates
  • algorithm might consider visiting certain cells/coordinates first
48
Q

explain the differences between static and dynamic structures and an advantage for each

A

static data structures = have fixed storage size, determined at compile time
less data to process at execution (faster)
Example - array; whenever you declare an array you always specify its size - it’s a static data structure

dynamic data structures = can grow/shrink during execution time (using pointers)
if null field/value key doesn’t have to be stored so can potentially save data
Example - linked list, dictionary; whenever you declare a new dictionary it starts off empty and no space is reserved in memory - it’s a dynamic data structure

49
Q

Describe the relationship between a class and an object of that class (2 marks)

A
One from (1)
A class related to a type of real-world object
A class lists the attributes and methods that a type of object will have
A class describes a type of object
One from (1)
An object is a specific instance of that class
An object is an object based on a class
50
Q

State one advantage for using a named constant value (2 marks)

A

Any one from (2)

If the programmer needs to change the value at a later time (1) they only need to update it once in the program (1)

Makes the code more readable (1) as someone reading the code can more easily understand what the value is for (1)

The same value is used each time (1) so less likelihood of errors (e.g. mistyping one instance of the value) (1)

51
Q

Describe how values can be passed between different procedures (3 marks)

A

Passing values/arguments/parameters to subroutines
Returning values/arguments/parameters back from functions
Using constants/global variables

52
Q

Describe an advantage of using a static data structure of a dynamic data structure

A

Memory allocation is fixed which means there will be no issues with adding an removing items from the data structure

OR

Easier to program as there isn’t a requirement to check on the size of the data structure at any point before accessing it

53
Q

Describe an advantage of using a dynamic data structure over a static data structure

A

Makes efficient use of memory because the data structure only uses as much memory as it needs

54
Q

Describe a disadvantage of using a dynamic data structure over a static data structure

A

Dynamic data structures run the risk of ‘overflow’. This happens when it exceeds its allowed limit. Can also ‘underflow’ if it becomes empty

OR

Dynamic data structures are harder to program because the code needs to keep track of the data structures size and location of items inside it at all times.

55
Q

Describe a disadvantage of using a static data structure over a dynamic data structure

A

Can be very inefficient as memory for the data structure is set aside at the start of the program but might not be needed.
Example declare an array[1000] but only ever use 10 elements. that is a waste

56
Q

Describe the 4 steps to insert an item onto a stack

A
  1. Check to see if the stack is full
  2. If the stack is full report an error and stop
  3. Increment the stack pointer
  4. Insert new data item into location pointed to by the stack pointer and stop
57
Q

Describe the 4 steps to take something off the stack

A
  1. Check to see if the stack is empty
  2. If the stack is empty report an error and stop
  3. Copy data item in the location pointed to by stack pointer
  4. Decrement the stack pointer and stop
58
Q

Describe the 4 steps to add something to a queue

A
  1. Check to see if the queue is full
  2. If the queue is full report error and stop
  3. Increment the back pointer
  4. Insert new data item into the location pointed to by the back pointer and stop
59
Q

Describe the 4 steps to read from a queue

A
  1. Check to see if the queue is empty
  2. If the queue is empty reoprt an error and stop
  3. Copy data item in the location pointed to by the front pointer
  4. Increment front pointer and stop
60
Q

Describe two typical uses for a tree structure

A

Store an ordered list
Represent hierarchical data
Store a list so it is easily searchable

61
Q

Explain why a developer might choose to use a hashing algorithm to store data (2 marks)

A

Faster to search than an unsorted array/list/data structure (1)
No need to re-sort/move items when adding new records (1)

62
Q

State the time complexity for linear search

A

O(n)

63
Q

State the time complexity for Bubble sort

A

O(n^2)

64
Q

State the time complexity for Binary search

A

O(logn)

65
Q

State the time complexity for Merge sort

A

O(nlogn)

66
Q

State the time complexity for finding the first item in a list

A

O(1)

67
Q

State the time complexity for creating every possible order of letters from a word

A

O(n!)

68
Q

State the time complexity for binary tree search

A

O(logn)

69
Q

describe the halting problem

A

The unsolvable problem of writing a program that can tell whether a given program and its inputs will halt, without running the given program.
(unsolvable)