Course topics 8 and 9

Self-study

The topics for this week are (i) Graphs and Trees, (ii) Tree data structures and traversals and (iii) Invalidation in containers

The following links will take you to the video-lectures and the accompanying slides:

Trees

With regard to a general rooted tree, which of the following are true? (Note: more than 1 statement may be true.)
Suppose we are considering the subtrees of node \(x\) in some rooted tree. Which of the following is true?
Suppose we are considering a rooted tree whose height is 4. Which of the following statements is always true?
Let \(x\) be a node in a rooted tree. A descendant of node \(x\) is any node in any subtree of \(x\). Which of the following statements is always true?

Tree data structures and traversals

Assume a node in a binary tree is stored using children pointers left_child and right_child. If the entire binary tree has 4 nodes, how many of these children pointers will be equal to nullptr?
Which of the following best describes the difference between how a node is stored in a general rooted tree and how a node is stored in binary tree?
Suppose we perform preorder and postorder traversals on an entire rooted tree having at least two nodes. Which of the following is true?
Three tree traversals were presented, preorder, postorder and inorder. In what way does inorder differed from the other two traversals?

Invalidation

With regard to invalidation and different STL containers, which of the following statements is true? (More than 1 statement may be true.)
What can be said in general about invalidation and iterators, pointers and indices?
What does invalidation cause when using an STL container?

Extra links on the topic:

Week07 - Glossary

Submit weekly exercises

Questions to be submitted this week

Topic 8 of the course

Self-study

The topics for this week are the following: (i) Amortized performance and std::vector (ii) Verifying asymptotic performance (iii) Tips for increasing actual performance and (iv) Randomization

The following links will take you to the video-lectures and the accompanying slides:

Amortized performance and std::vector

Amortized efficiency means
Suppose we use an STL vector \(v\) and all we do is add elements to the end of \(v\). Suppose also that the size of \(v\) is doubled in situations when \(v\) runs out of memory. Which of the following is true concerning the efficiency of adding a single element to \(v\)?

Verifying asymptotic performance

With regard to verifying an algorithm’s asymptotic efficiency, which of the following are true? (More than 1 statement may be true.)
Suppose for algorithm \(X\) we have a large collection of input data cases where the size of the input data spans several orders of magnitude. Suppose we run \(X\) for all inputs cases and we measure the execution time (say in seconds). If we want to say something about asymptotic efficiency of \(X\), why should we do some statistical analysis of the measurements?

Tips for increasing actual performance

Choose the methods that can be used to improve the actual performance of some program. (There may be more than 1 correct choice.)
Suppose in C++ we have stored a collection of \(n\) numbers in a vector \(v\) and \(n\) is very large. For which of the following situations does it make sense to first sort all the elements of \(v\)?
Suppose in C++ we have a large collection of numbers stored in an unsorted vector \(v\) and we often add new elements to \(v\), but we never remove elements from \(v\). Suppose in addition we often need the largest element in \(v\). Of the following, which is the least efficient way of calculating the largest element?

Randomization

What is a valid reason for using randomization in some algorithm?
When randomization is added to Quicksort to avoid Quicksort’s worst case behaviour, how is it typically added?
Suppose we have a vector \(v\) having \(n\) elements and we randomly shuffle all \(n\) elements. What can be said about this shuffling operation?
What is a central question, related to this course, whose answer can be found in this week’s videos?
Of the following topics, which do you think deserves further discussion/explanation during the weekly consultation session?
Were there any parts of the video lectures that were particularly difficult? Particularly interesting? Something about which you wish to learn more?

Extra links on the topic:

There is no shortage of opinions on how to improve the efficiency of C++ code. Here is one link and a warning. Some of information is quite technical. -A long discussion in stackoverflow:

Week08 - Glossary

Homework to be returned for these topics

Questions to be submitted this week

Course 9 topics

Self-study

The topics for this week are (i) The heap data structure, (ii) Implementing a heap as an array

The following links will take you to the video-lectures and the accompanying slides:

Heap and heap operations

In a max-heap having at least two nodes
A heap is a binary tree. Which of the following properties does a heap’s binary tree possess? (More than 1 property may be valid.)
Which of the following happens when we add a new node to a max-heap?
In which of the following situations would we need to use the Heapify algorithm in a max-heap?
Regarding the Buildheap algorithm, which of the following are true? (More than 1 statement may be true.)
What does the Heap-Extract-Max algorithm compute?
Consider the following four algorithms: Buildheap, Heap-Extract-Max, Heapify and Heap-Insert. Assume that the heap used as input to each algorithm has \(n\) nodes. Of these four algorithms, which have runtime efficiencies that are logarithmic in \(n\)?

A Heap as an array

Suppose a binary tree max-heap is stored in an array \(A\). Suppose \(A[i]\) corresponds to node \(x\). Which of the following are true? (More than one statement may be true.)
Of the following, what are the advantages of Heapsort as an algorithm for sorting numbers? (More than one statement may be true.)
Formulate a central question for the course, which this week’s videos will cover give the answer.
Which video topic should be discussed in particular in a discussion session?
Was there anything particularly difficult about the content of the videos? What about interesting? Something you’d like to learn more about?

Extra links on the topic:

Typically a priority queue is implemented as a binary tree heap. An alternative data structure that can be used for a priority queue is a binomial tree heap

Week09 - Glossary