0% found this document useful (0 votes)
52 views44 pages

Dsa22 13

The lecture provided a review of the key topics covered in the unit, including algorithm analysis, data structures like trees and hashing, and sorting algorithms. It also discussed the final exam format and sample questions. The lecturer provided farewell comments and feedback before concluding the lecture.

Uploaded by

Phạm Văn Hào
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views44 pages

Dsa22 13

The lecture provided a review of the key topics covered in the unit, including algorithm analysis, data structures like trees and hashing, and sorting algorithms. It also discussed the final exam format and sample questions. The lecturer provided farewell comments and feedback before concluding the lecture.

Uploaded by

Phạm Văn Hào
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Lecture 13

Unit Review
Main Content of the Lecture
q The main topics covered by this unit
q Review of Assignments
q Information about the final examination
v Examination format and rules

v Sample questions

q Farewell comments and feedback


Topics covered by the unit If there is a difference
in Big-O, they are
§ Algorithm analysis (lectures 1 & 2) significantly different;
otherwise, they may
§ Big-O notation
be different.
§ Typical efficiency:
O(1)<O(log n)<O(n)<O(nlog n)< O(n2)<O(n2log n)< O(n2log2n)<O(n3)<…< O(2n)
§ Analysis approaches: worst case (by default), average case, best
case.
§ Review approach:
» Understand big-O notation
» Know how to calculate complexity of an algorithm in big-O notation
» Remember the complexity of typical algorithms, such as typical searching
algorithms, typical sorting algorithms, major data operations, such as
insertion, deletion and traversal, with typical data structures.
» Given a piece of code that implements an algorithm, estimate its complexity
using big-O notation.
» Be aware that big-O cannot tell constant differences thus not accurate.
Example of Complexity Analysis Overall O(log n)
Item nItem(keyCount++); //Place a selling the item
nItem.inputAnItem();
itemList.AVL_Insert(nItem);// O(log n)
_createNode(treePtr, nItem);
void _createNode(TreeNode *treePtr, Item newItem){ // O(1)
TreeNode *node = new TreeNode;
node->data = newItem;
node->leftChildPtr = NULL;
node->rightChildPtr = NULL;

if (treePtr->leftChildPtr == NULL) {
treePtr->leftChildPtr = node;
} else {
TreeNode walker = treePtr->leftChildPtr; Assuming total
while (walker->rightChildPtr != NULL) number of items
walker = walker->rightChildPtr; stored in the
walker->rightChildPtr = node; general tree or
} // assuming the maximal number of AVL is n.
} // children of a node is m and m << n
Example of Complexity Analysis
void processNode(TreeNode *&treePtr, int role, int count) {
//A buyer buys the item
int thisKey = (treePtr->data).key;
Item dataOut;
itemList.AVL_Retrieve(thisKey, dataOut);//O(log n)

if (dataOut.buyASellingItem()) {
if (dataOut.getQuantity() > 1) {
int q = dataOut.getQuantity() - 1;
generatTree->data.setQuantity(q);
dataOut.setQuantity(q);
itemList.AVL_update(dataOut); //O(log n)
} else {
itemList.AVL_Delete(thisKey); //O(log n)
deleteNode(thisKey); //O(1)
}
}
} Overall O(log n)
Topics covered by the unit
§ Linear data structures and searching algorithms (lecture 2 & 3)
§ Basic operations of any linear lists: Insertion, deletion, search,
traversal
§ Basic components of a linked list: head and nodes. Each node
contains data and link.
§ vector: array-based linear data structure in STL
§ list: linked list based linear data structure in STL
§ Sequential search and binary search

n 10 100 1000 10,000 100,000 1,000,000 1,000,000,000


log2n 3 7 10 13 17 20 30
Topics covered by the unit
§ Review approach:
§ The complexity of typical operations in an array or a linked list
§ Understand the structure of data node and the use of dynamic
memory allocation to create a linked list
§ Read and enjoy the implementation of linked list
§ Know the differences of STL vector and list.
§ Understand binary search and its calculation of complexity
8

Topics covered by the unit


§ Stack (lecture 3)
§ Basic operations of stack: push, top, pop.
§ Implementation of stack ADT.
§ Review approach:
» Understand the mechanism of a stack and different ways to
implement (read code).
» Know the complexity of typical operations on a stack
» Be able to use STL stack
» Be able to use stacks (write algorithms) to solve problems,
such as reverse lists, backtracking search and depth-first
traversal in graphs.
9

Topics covered by the unit


§ Queue (lecture 4):
§ Typical operations: enqueue and dequeue
§ Queue implementation (circular array)
§ Priority queue
§ Review approach:
» Understand how a queue works and how it is implemented.
» Know the complexity of common operations on both FIFO
queue and priority queue.
» Be able to use STL queue and priority queue (operator
overloading)
» Be able to use queue or priority queue to perform operations
such as breadth- first traversals of trees or graphs.
10

Topics covered by the unit


§ Recursion (lecture 5):
§ Basic concepts: base case and general case
§ Recursive algorithms: simple but not necessarily efficient and
hard to debug
§ Most useful with tree structures
§ Review approach:
» Be familiar with common simple recursive algorithms such as
factorial and Fibonacci numbers.
» Given an input, calculate the value of a recursive function
» Convert the recursive definition of a mathematical function
into C++ code.
» Be familiar with its applications to trees.
e
Topics covered by the unit m
t b
us with
ta ated
a
D o ci
a ss s
§ Hashing technology (lectures 6): ke y

§ Hashing function: maps a key to an address


§ Collision resolution in hashing
§ Closed hashing: find a place inside of the array
§ Open hashing: extra linked list for synonyms
§ Review approach:
» Understand why search in a hash table can be in O(1).
» Understand the nature of hashing and collision resolving.
» Understand typical hash functions
» Understand linear probing and quadratic probing using
division hash functions with integer keys.
» Be able to use unordered_map in C++ or hashtable in Java
Topics covered by the unit
§ Trees, Binary trees, Binary search trees, AVL trees, heaps and B-
Trees (lectures 7, 8 & 9):
§ Tree: a graph without cyclic paths
§ Binary tree: a tree with no more than two children of each node
(an extension of linked list)
§ Binary search tree: binary tree with a certain key requirement
§ AVL tree: binary search tree with a balance requirement
§ Heap: binary tree with both key requirement and shape
requirement, which are different from BST
§ B-Tree: balanced m-way search tree b e
t
us with
§ Major operations: m
ta ated
a
D o ci
» Insertion, deletion, retrieval, traversal a ss s
ke y
Topics covered by the unit
§ Review approach:
§ Able to distinguish all these concepts
§ Be able to insert and delete a sequence of data into a BST
§ Be able to understand and calculate in-order, pre-order and post-
order traversals
§ Be able to build an AVL tree with a given sequence of key input
(two orderings: the order of input and the order of keys). AVL
tree is unique if the input sequence is strictly followed.
§ Understand the structure of a heap and major operations on a
heap (deletion is restrictive).
§ Understand the concept of m-way tree, m-way search tree, B-
Tree of order m.
§ Able to create a B-tree with given input sequence.
14

Topics covered by the unit


§ Sorting algorithms (lecture 10)
§ From insertion sort to Shell sort
§ From bubble sort to quick sort
§ From selection sort to heap sort
§ Review approach:
» Be able to write the algorithms for insertion sort, bubble sort
and selection sort
» Recognize the algorithms for quicksort, Shell sort and heap
sort.
15

Topics covered by the unit


§ Graphs (lecture 11):
§ Basic concepts of graphs
§ Representation of graph: adjacency matrix and
adjacency list
§ Spanning trees and minimum spanning trees
§ Shortest paths
§ Review approach:
» Be able to convert between a graph and its adjacency matrix
» Be able to calculate spanning trees and minimum spanning
trees – Prim’s algorithm
» Be able to calculate shortest path between two vertices –
Dijkstra’s algorithm.
16

Topics covered by the unit


§ Algorithm Design Techniques (lecture 12):
§ Concept of computer algorithms
§ Algorithm Design Paradigms
» Recursive algorithms
» Greedy algorithms
» Divide and conquer
» Dynamic programming
» Backtracking algorithms
» Randomized algorithms
§ Review approach:
» Be able to recognize the type of algorithms
17

Review of assignments
§ The purpose of assignment 1 (Cephalopod game) is to:
§ Learn to use STL data structures to solve real-world problems.
§ Learn to design relatively highly complicated algorithms
§ Learn to design greedy algorithms
§ Learn to design randomized algorithms
§ Learn to design relatively complicated recursive algorithms
§ The purpose of assignment 2 (Catalog sale) is to:
§ Learn to create customised data structures to solve real-world
problems.
§ Be aware of efficiency of implementation and learn how to
improve efficiency.
§ Train ourselves to be a professional programmer
18

Review of assignments
§ Data structures involved in Assignment 1: vector, queue and priority
queue.
§ Data structures involved in Assignment 2: AVL tree and general
tree.
§ Typical algorithms involved in the assignments: sequential search,
heuristic search, randomization, recursion, AVL tree operations,
general tree operations, dynamic programming, ...

Read code for Assignment 2


19

Reading materials
§ Lecture notes
§ Textbook
§ Example code
§ Your solution to tutorial questions
§ Your solution to practical tasks
§ Assignment specifications and your solutions
20

Format of final exam


The examination consists of two parts: multiple choice
questions (30 marks) + programming tasks (20 marks). You
will be given 135 minutes (45 minutes for MCQ, 75 minutes
for programming tasks and 15 minutes for submission)
§ Multiple choice questions:
§ 30 questions, one mark each.
§ Designed for being completed within 30-45 minutes
(control your time).
§ Questions are taken from a big pool (120 questions) and
presented one question each time in random order.
21

Format of final exam


§ Programming tasks:
§ The programming part consists of four to five tasks for 20 marks
in total.
§ Designed to be completed within 75 minutes.
§ You will be given a base code in C++ to start with.
§ The code and documentation for the programming tasks must be
submitted on vUWS by the end of the examination (submission
time has been included in the examination time).
§ Only source code is needed for submission. It can be based on
any IDE. If we can’t run your code, we will contact you but we
will mainly focus on your implementation logic.
§ You must claim what you did in the provided claim sheet.
22

Format of deferred exam


§ The deferred examination will be in the same format as the
final examination except that every student must be on
campus and demonstrate their code for programming
tasks.
23

Example questions: multiple choice


Consider the following procedure:
for (i=1;i<=2*n;i++)
for(j=1;j<=n;j++)
j*=2;

The complexity of the above algorithm in terms of Big-O


notation is
(a). O(n)
(b). O(n2)
(c). O(log2n)
(d). O(nlog2n)
24

Example questions: multiple choice


Consider the following procedure:
for (i=1;i<=2*n;i++)
for(j=1;j<=n;j++)
j*=2;

The complexity of the above algorithm in terms of Big-O


notation is
(a). O(n)
(b). O(n2)
(c). O(log2n)
(d). O(nlog2n)
25

Example questions: multiple choice


Which of the following statement about priority queues is
INCORRECT?
(a). A priority queue has the same operations as FIFO
queues
(b). FIFO queue is a special priority queue and the priority is
given by the arriving time
(c). The element with the highest priority is the first to remove
(d). To implement a priority queue, the elements of the queue
must be sorted in terms of priority.
26

Example questions: multiple choice


Which of the following statement about priority queues is
INCORRECT?
(a). A priority queue has the same operations as FIFO
queues
(b). FIFO queue is a special priority queue and the priority is
given by the arriving time
(c). The element with the highest priority is the first to remove
(d). To implement a priority queue, the elements of the queue
must be sorted in terms of priority.
27

Example questions: multiple choice


Based on the following adjacency matrix of a graph

Which of the following edges cannot be in the spanning tree generated from a
breadth first traversal starting from A?
(a). (E, A)
(b). (E, B)
(c). (E, C)
(d). (E, D)
28

Example questions: multiple choice


Based on the following adjacency matrix of a graph

Which of the following edges cannot be in the spanning tree generated from a
breadth first traversal starting from A?
(a). (E, A)
(b). (E, B)
(c). (E, C)
(d). (E, D)
29

Example questions: multiple choice


What is the output of the following program segment?
priority_queue<int> intQueue;
int x, y;
x = 2;
y = 3;
intQueue.push(x);
intQueue.push(y);
(a). x=2, y=3
x = intQueue.top();
(b). x=4, y=6
intQueue.pop(); (c). x=3, y=6
intQueue.push(x-2); (d). x=6, y=3
intQueue.push(x);
intQueue.push(y+3);
y = intQueue.top();
intQueue.pop();
cout<<"x = "<< x << ", ";
cout<<"y = "<< y << endl;
30

Example questions
What is the output of the following program segment?
priority_queue<int> intQueue;
int x, y;
x = 2;
y = 3;
intQueue.push(x);
intQueue.push(y);
x = intQueue.top(); (a). x=2, y=3
(b). x=4, y=6
intQueue.pop();
(c). x=3, y=6
intQueue.push(x-2); (d). x=6, y=3
intQueue.push(x);
intQueue.push(y+3);
y = intQueue.top();
intQueue.pop();
cout<<"x = "<< x << ", ";
cout<<"y = "<< y << endl;
31

Example questions
Show the left and right children of 32, and the parent
of 11 in the following array-represented heap:
40, 27, 32, 15, 14, 20, 25, 11

(a). 15, 14, 25


(b). 40, 27, 15
(c). 14, 20, 25
(d). None of the above
32

Example questions
Show the left and right children of 32 and the parent
of 11 in the following array represented heap:
40, 27, 32, 15, 14, 20, 25, 11

40
32
27

15 14 20 25

11 (a). 15, 14, 25


(b). 40, 27, 15
(c). 14, 20, 25
(d). None of the above
Example of programming tasks
Download the code from vUWS, which provide you with an
AVL tree ADT.

Task 1. Write a program that reads words from the given text
file and store the occurrence frequency of each word in an AVL
tree.
Task 2. Print the AVL tree, showing the key, level and balance
factor of each node.
Task 3. List all the words by traversing the AVL tree in pre-
order
Task 4. List all the words in the order of frequency
Task 5. Assume that a text file contains n words. Analyse the
complexity of your algorithm for Task 1 and Task 4.
Example of programming tasks
struct Data { int main() {
string key; AvlTree<Data, string> tree;
int info; ifstream fin(“article.txt”);
}; string word;
while (fin >> word) { Any better solution?
Data item;
item.key = word;
item.frequency = 1;
if(tree.AVL_Retrieve(word, item)) {
tree.AVL_Delete(word);
Item.info++;
}
tree.AVL_Insert(item);
}
fin.close();
return 0;
}

Complexity of the algorithm is O(nlog n)


35

How will the final exam be run?


§ The final examination will be run online vUWS under ProctorU
starting between 9:00am-10:00am on 24 June 2022.
§ You must register to ProctorU (separated from vUWS) to book a time
slot and access the examination (you will be given a unique password
to access the exam).
§ ProctorU is supervised by human invigilators (similar to on-campus
exams) under ProcterU with assistance of AI software. You are NOT
allowed to contact me or Alex L
36

How will the final exam be run?


§ The final examination will be run online vUWS under ProctorU
starting between 9:00am-10:00am on 24 June 2022.
§ ProctorU is operated by human invigilators (like on-campus exams)
under ProcterU with assistance of AI software. You are NOT allowed
to contact me or Alex L
§ PRIOR TO THE DAY OF YOUR EXAM YOU MUST:
§ Navigate to the ProctorU website
(https://www.proctoru.com/portal/western-sydney-university)
and follow the set-up instructions. Be sure to become familiar
with the process and ensure your computer meets the minimum
requirements.
§ You must create a ProctorU account if you have not one (different
from vUWS) and login to it to book a time slot for the exam of
this subject.
37

How will the final exam be run?


ON THE DAY OF YOUR EXAM YOU MUST:
§ Please log into your ProctorU account 10 minutes before the scheduled time of
the exam.
§ On the My Sessions page in your ProctorU account, there will be a countdown
timer showing you how much time to your exam.
§ When the timer reaches 0:00, a Start Session button will appear. Please note, if
you log in 15 minutes after your scheduled time, the start button will no longer
show under My Sessions.
§ After the authorisation process is finished, please click Begin Exam and
navigate to vUWS > Final Exam folder. Please log in with your Western
Student ID if you are prompted to and navigate to Final Exam folder.
§ Your ProctorU facilitator will unlock a password-protected Exam,
named Begin Final Exam in the Final Exam folder, which will allow you to
complete the online Exam.
38

How will the final exam be run?


ON THE DAY OF YOUR EXAM YOU MUST:
§ Please DO NOT close your browser window as it will terminate your
invigilated exam. You will see the exam questions displayed
§ Timer warnings appear in the test window when half the time, 5 minutes, 1
minute, and 30 seconds remain. At 1 minute, the warning is red, and at 30
seconds, both the status bar and the warning are red. If you collapse the timer,
you won't see the colour changes.
§ Leave at least 5 minutes for you to submit your code and claim sheet
§ Once you have completed the exam, press the Save and Submit button,
otherwise when the time runs out, your exam will be automatically submitted
and the invigilation will conclude.
39

Permitted Resources
§ Paper and pen
§ Textbooks, lecture notes, your solution of tutorials, practicals and
assignments, your noted related to the subject
§ Subject related reference books in Computer Science
§ Subject related local files in your computer
§ Search in the Internet
§ C++ IDEs
§ C++ Compilers
§ Text editors
40

Actions that are not permitted


Please DO NOT try the following actions as these will get flagged by
the system and create an incident report:
§ Taking screenshots
§ Read or write emails, messages unless approved by ProctorU
§ Make phone call unless approved by ProctorU
§ Visit social media, such facebook, twitter, instagram, discord,
whatsapp, ...
§ Leaving your computer
§ Not facing your computer screen
§ Not providing a valid ID
Final chance of online tutorials
§ Practice for final examination is available Thursday 3 June on
vUWS (under Final exam – Sample questions for practice).
§ If you have missed any online tutorials (the ones with marks), there
is a chance for you to make up. These online tutorials will be re-
opened on
§ Wednesday 8 June at 7pm until 8pm for Tutorials 2 and 4
§ Thursday 9 June at 7pm until 8pm for Tutorials 6 and 8
§ Friday 10 June at 7pm until 8pm for Tutorial 10.
If you have not reached the maximal attempts, you may choose to
redo any of them. Please note that the result of each tutorial will be
based on your final attempt.
Consultation and feedback
§ Consultation for final examination:
§ Wednesday 9am – 11am.
§ Email me to open a zoom session.
§ Call me any day by 10pm at 0435353562.
§ Please complete your SFU and SFT for this unit. Your feedback is
important to me especially for the practice of post pandemic with a
mixture of online and onsite.
§ A separate survey will be available on vUWS with one bonus mark
after the final examination.
43

Scholarship opportunities

2022 PARTNERSHIP WINTER SCHOLARSHIP


§ Project: Automated Support for Managing Machine
Learning Interpretability and Causality in CRISP-ML
Process Methodology
§ Principal supervisor: Prof Simeon Simoff
§ Partner: Analytikk Consulting
§ Scholarship: $3500
44

Scholarship opportunities

2022 PARTNERSHIP WINTER SCHOLARSHIP


§ Project: Model-Agnostic Methods for Interpretability of
Neural Networks
§ Principal supervisor: Prof Simeon Simoff
§ Partner: Analytikk Consulting
§ Scholarship: $3500

You might also like