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

Ho Chi Minh City University of Technology Department of Electronics and Electrical

Engineering

ECE391: Computer System Engineering

Homework 2 – chap 5
n
∑ i2 is O( n3 )
1. Show that i=1
n
∑ i /2i <2
2. Show that i=1

3. Show that log b f (n ) is Θ(log f (n )) if b >1 is a constant


4. Find the complexity of the function
int selectkth(int a[], int k, int n) {
int i, j, mini, tmp;
for (i=0; i<k; i++) {
if (a[j] < a[mini]) mini = j;
tmp = a[i];
a[i] = a[mini];
a[mini] = tmp;
}
}
5. Describe a linearly recursive algorithm for finding the minimum element in an n-element array.
6. Describe a recursive algorithm for printing all of the permutations of the sequence (1,2,…,n).
What is the running time of your algorithm?
7. Describe the output of the following series of stack operations:
push(8), push(3), pop(), push(2), push(5), pop(), pop(), push(9), push(1), pop(), push(7), push(6),
pop(), pop(), push(4), pop(), pop().

8. Describe the output for the following sequence of queue operations:


insertFirst(3), insertLast(8), insertLast(9), insertFirst(5), removeFirst(), removeLast(), first(),
insertLast(7), removeFirst(), last(), removeLast().

9. Given a class Ticket below

Class Ticket {
public:
string name;
string ID;
unsigned int birthyear;
}
a). Write a constructor for the class Ticket to assign the default values for name, ID, and
birthyear.

Instructor: Dr. Truong Quang Vinh


Ho Chi Minh City University of Technology Department of Electronics and Electrical
Engineering

Name = “NO NAME”;


ID = “0000”;
Birthyear = 0;
b). Write constructor for the class Ticket to assign the new information into the member
variables.
string new_name;
string new_ID;
unsigned int new_birthyear;

Given a QUEUE of Ticket named Waiting_list as below:

queue<Ticket> Waiting_list;

c). Write a function to add a person with the following information into the Waiting list:
string my_name = “Nguyen Van A”;
string my_ID= “0010”;
unsigned int my_birthyear = 1990;
d). Write a function to get the information of a person at the front of the Waiting_list.

Instructor: Dr. Truong Quang Vinh

You might also like