0% found this document useful (0 votes)
77 views2 pages

ECE391: Computer System Engineering Homework 2 - chap 5: f (n) is Θ (log f (n) ) if b >1

This document contains the homework assignment for ECE391 Computer System Engineering. It includes 9 questions covering topics like complexity analysis, recursive algorithms, stacks, queues and classes. The homework involves analyzing time complexities, describing outputs of operations on stacks and queues, and writing constructors and functions for a Ticket class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

ECE391: Computer System Engineering Homework 2 - chap 5: f (n) is Θ (log f (n) ) if b >1

This document contains the homework assignment for ECE391 Computer System Engineering. It includes 9 questions covering topics like complexity analysis, recursive algorithms, stacks, queues and classes. The homework involves analyzing time complexities, describing outputs of operations on stacks and queues, and writing constructors and functions for a Ticket class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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