55, 9, .., 28, 15, 16, 6) - Her Task Is To Check Whether A Client Exists in The List or

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Consider the following use case: FastTransfer is a small company that transfers

boxes of precious stones from Africa to Europian clients. The company aims to
maximise the number of items enter in a box (to maximise profit) so they are
willing to break stones in small pieces to add as many as they can into a single box.

What algorithm do you suggest to FastTransfer to use and why? (5 marks)


In your own words explain the differences between probabilistic and approximate
algorithms. Provide a simple example for each algorithm.

Consider the following use case: Mary wants to develop an algorithm to search for a
client-id in a list of unique client-ids. The client list looks like this  clients = [ 11, 3,
55, 9, .., 28, 15, 16, 6].  Her task is to check whether a client exists in the list or
not.  Mary is not sure what is the best way to approach this.
Does she need to (a) sort the list and then search it or (b) search the list directly
(without sorting)?
What do you suggest to Mary to do? What is the computational complexity in
both cases (a and b)?

Merge sort is a XXXXXXX algorithm that divides input array into two halves, calls itself for the two
halves and then merges the two sorted halves.
The secretary problem is an XXXXXXXXX strategy problem of choosing a time to take a particular
action, to maximize an expected reward or minimize an expected cost. (1 mark)
One of the best algorithms to search for a key in a list of sorted elements is the binary search
algorithm. The worst-case computational complexity of the algorithm is XXXXXXX . (1 mark)
A XXXXXXXXX is a special relational database table column (or combination of columns)
designated to identify all table records uniquely. In contrast, a XXXXXXXXX acts as a cross-
reference link between data in tables. (2 marks)
Gradient descent is an algorithm we often need to use to optimise a cost function.
In machine learning, we use gradient descent to update the parameters of our
model.
In your own words discuss how gradient descent algorithm works. Provide a simple
example where gradient descent can help you solve a data science problem.
https://www.youtube.com/watch?v=sDv4f4s2SB8

Create a table called cities to include:

 city_id as a numeric primary key


 name that includes 24 characters
 in_country that includes 2 characters
2.     Create a table called actors to include:

 actor_id as a numeric primary key


 first_name 24 characters
 last_name 24 characters
 gender 1 character
 birth_year number

3.     Create a table called films to include:

 film_id as a numeric primary key


 title 24 characters
 release_year number
 language_spoken 2 characters
 runtime_minutes number

Q 1.                  Show all the data from the cities table


Q 2.                  Search for cities from the United Kingdom

Q 3.                  Search for films that have a runtime of 100 minutes or more

Q 4.                  Change the runtime of the film with the id 104 to 97 minutes

Q 5.                  Search for female actors

Q 6.                  Change the birth year of an actor with actor id 4 to 1974

Q 7.                  Insert a new city as follows:


Q 8.                  Delete all cities from Greece

Q 9.                  Search for films with a running time more than 100 and less than
200 minutes.

Q 10.              Calculate the average of films runtime in hours


Q 11.              Count how many males actors are in the dataset
Mary has a list of ids for her part-time employees. The data is in a Google sheet,
and she managed to transfer it into a Python script. Her data looks like this
my_ids=[ 100, 200, 134, 302, 311, 345 ].
Mary wants to check if an employee exists in the list or not, what is the best
algorithm to use? (5 marks)
What are the differences between the following complexities: O( n^2), O( n) and O(
logn), give an example of an algorithm for each complexity and explain why it
belongs to each complexity class. (5 marks)

Harry gets a wand 11’’ and with ‘a phoenix feather core: O(n) [Linear time] Linear
search. The running time of an algorithm typically grows with the input size: n.

BS includes splitting searching space in half, in each iteration… This results in a


O(log(n)) complexity

Search a sortedarrayby repeatedly dividing thesearchinterval in half. • Begin with


an interval covering the whole array. • If the value of thesearchkey is less than the
item in the middle of the interval, narrow the interval to the lower half. • Otherwise
narrow it to the upper half.

Naïve sorting: O(𝑛^2)operations: Compare each item with every item in the list!

Merge sort: O(𝑛log𝑛)operations. Based on divide and conquer! Works on


O(𝑛log𝑛)worst case time complexity

Insertion sort: Works on O(𝑛^2)worst case time complexity.


Timsort: adaptive sorting algorithm. (First analyzes the data, secondl yapplies a
sorting algorithm). default algorithm in Java, Python, Android

Give an example of how to measure the running time of an algorithm in Python (5


marks)
Recursive algorithms
Dynamic programming algorithms
Divide and conquer algorithms
Greedy algorithms
Brute-Force algorithms
Randomized algorithms
Probabilistic algorithms
Approximation algorithms

You might also like