EE2331 Data Structures and
Algorithms:
Analysis of Algorithms
1
The Story
Once upon a time in a country,
a warrior won a crucial battle
and saved the country
The King was very happy and
gave a trunk of golden coins to
the hero
The warrior said: the tru
/*
* Student name:
* Student ID :
*
* You are asked to implement the functions reversedPrint() and sortedInsert()
as specified below.
* Your implementation can use c+ STL builtin stack.
* Test cases are defined in the main() function. No modification is
/*
* Student name:
* Student ID :
*
* You are asked to implement the functions reversedPrint() and sortedInsert()
as specified below.
* Your implementation can use c+ STL builtin stack.
* Test cases are defined in the main() function. No modification is
/*
* Student name:
* Student ID :
*
* You are asked to implement the functions infix2postfix() and
evaluatePostfix() as specified below.
* Your implementation can use c+ STL builtin stack.
* Test cases are defined in the main() function. No modification
/*
* Student name:
* Student ID :
*
* You are asked to implement the functions infix2postfix() and
evaluatePostfix() as specified below.
* Your implementation can use c+ STL builtin stack.
* Test cases are defined in the main() function. No modification
4
5 3
1 3 5 7 9
5 5
0 2 4 6 8
1 1
1
0 0
=
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case contains two integers N and K, which are the length of an input list and the number of rota
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools  Templates
* and open the template in the editor.
*/
/*
* File:
stackAndQueue.cpp
* Author: Van
*
* Created on 2016 10 29 , 7:1
EE2331 Data Structures and Algorithms 2016/17A
Midterm Test (Paper A)
Q1. Given a LIFO (LastInFirstOut) data structure as shown below, you are asked to implement the two
member functions  in() and out() using only an instance of queue. You can use the
EE2331 Data Structures and
Algorithms
Trees
1
Remember?
How does a computer evaluate mathematical
expressions?
e.g. (4 + 5) * (7  2)
Use postfix expressions (4 5 + 7 2  *)
May we transform it to tree representation?
*
Tree representation
+
4

5
7
2
EE2331 Data Structures and
Algorithms
Sorting
1
Given a List in Random Order
How to find the
largest number?
How to find the
smallest number?
How to determine if
an arbitrary number
exists in the list?
2
Given a List in Ascending Order
How to determin
EE2331 Data Structures and
Algorithms
Recursion
1
Outline
Recursion
Towers of Hanoi
Factorial
Fibonacci Sequence
Ackermann Function
Binary Search
Greatest Common Divisor (GCD)
Backtracking
Cross River Problem
Maze Solver
N Queen
2
Towers of Hanoi
A
B
EE2331 Data Structures and
Algorithms
Linked Lists
1
Linear List
Each element in the list has a unique predecessor
(previous) and successor (next).
Unordered/Random list
There is no ordering of the data.
Ordered list
The data are arranged according t
EE2331 Data Structures and
Algorithms:
Analysis of Algorithms
1
The Story
Once upon a time in a country,
a warrior won a crucial battle
and saved the country
The King was very happy and
gave a trunk of golden coins to
the hero
The warrior said: the tru
EE2331 Data Structures and
Algorithms
Introduction
1
Intended Learning Outcomes
Students should be able to
apply structural programming approach to solve more
complex computation problems;
demonstrate applications of standard data structures
such as li
CITY UNIVERSITY OF HONG KONG
Course Code & Title: EE2331 Data Structures and Algorithms
Session: Semester B, 200910
Time Allowed: Two hours
This paper has 7 pages (including this cover page).
Answer ALL questions in this paper.
Material, aids & instrument
/*
* Student name:
* Student ID :
*
* You are asked to implement the function solve() and define the values in
xMove[] and yMove[] as specified below.
* Test cases are defined in the main() function. No modification is needed.
*
*/
#include
#include
#incl
/*
* Student name:
* Student ID :
*
* You are asked to implement the functions reverseList() and rotateList() as
specified below.
* Your implementation cannot use any c+ builtin data structures or
algorithms.
* Test cases are defined in the main() functi
EE2331 Data Structures and
Algorithms
Introduction
1
Intended Learning Outcomes
Students should be able to
apply structural programming approach to solve more
complex computation problems;
demonstrate applications of standard data structures
such as li
EE2331 Data Structures and
Algorithms
Stacks and Queues
1
Abstract Data Type (ADT)
To manage the complexity of problems and the problemsolving
process, computer scientists use abstractions to allow them to focus
on the big picture without getting lost in
EE2331 Data Structures and
Algorithms
Trees
1
Remember?
How does a computer evaluate mathematical
expressions?
e.g. (4 + 5) * (7  2)
Use postfix expressions (4 5 + 7 2  *)
May we transform it to tree representation?
*
Tree representation
+
4

5
7
2
2
S
EE2331 Data Structures and
Algorithms
Recursion
1
Towers of Hanoi
A
B
C
The initial setup of the Towers of Hanoi
2
Towers of Hanoi
Three pegs, named as A, B, and C.
n disks each with different diameters, stacked in
order of diameter.
Disk with larger d
EE2331 Data Structures and
Algorithms
Trees
1
Remember?
How does a computer evaluate mathematical
expressions?
e.g. (4 + 5) * (7  2)
Use postfix expressions (4 5 + 7 2  *)
May we transform it to tree representation?
*
Tree representation
+
4

5
7
2
2
S
EE2331 Data Structures and
Algorithms
C+ Programming Review
1
Outline
Standard Libraries
Basic Data Types
Arithmetic, Bitwise, Logical Operators
Control Structures
Pointers
Arrays
Composite Structures
Parameter Passing in Functions
Standard I/O
Pseudo Cod
EE2331 Data Structures and
Algorithms
Linked Lists
1
Linear List
Each element in the list has a unique predecessor and
successor.
Unordered/Random list
There is no ordering of the data.
Ordered list
The data are arranged according to a key. A key is one o
EE2331 Data Structures and
Algorithms:
ObjectOriented C+ Review
1
Outline
Classes and Objects
Functions/Operators Overloading
Friend Function
NULL Pointer, Void Pointer and Function Pointer
Dynamic Memory Allocation
Templates
Inheritance
Virtual Function
EE2331 Data Structures and
Algorithms
Introduction
1
Intended Learning Outcomes
Students should be able to
apply structural programming approach to solve more
complex computation problems;
demonstrate applications of standard data structures
such as linke