Recursion Revisited
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Introduction to Recursion
Solving a problem by extending the solution to
a smaller version of the same problem.
Similar to mathematical
Hash Tables
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Hash Tables
Data structure where items are stored in a
location determined by their content.
Content-based index
vs.
Comparison-based index
E
Binary Search Trees
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Binary Search Trees
Binary Tree with additional properties:
nodes can be compared by some value.
all nodes in the left child are < nod
Binary Trees
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Trees
Data structure of linked nodes that are not linear.
Why? Some operations can be more efficient.
Defined as:
set of nodes + set of directe
Data Structures 1
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Topics
Introduction to Data Structures
Analysis of algorithms
Recursion revisited
Trees
AVL Trees
Hash Tables
Maybe more balanced tr
CSC2001F: Graphs and
Paths
Omowunmi Isafiade
Email: [email protected]
Office: Room 306
A graph consists of a set of vertices (nodes) and a set of edges (arcs) that
connect the vertices.
G=(V,E) where V is the set of vertices and E the set of edg
AVL Trees
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
AVL Trees
Binary Search Tree with additional balance
properties:
Every node is balanced (in AVL terms).
Height of left and right sub-trees are a
Red-Black Trees
Hussein Suleman <[email protected]>
Department of Computer Science
University of Cape Town
2017
Red-Black Trees
Binary Search Tree with additional balance
properties:
Every node has a colour: red or black.
Every leaf (nil) is black.
Embedded
SQL and
JDBC
Why Embedded SQL?
For complex queries and applications
Gives the capabilities of SQL and a high level
language like C+ or Java.
There are many :
PRO*C/C+, PRO*COBOL, PRO*FORTRAN, ODBC, JDBC, SQLJ,
Prerequisites
(these must all be
SELECT
SELECT . AS . FROM .WHERE . ORDER BY .
LIKE, IS NULL
AVG, MIN, MAX, SUM, COUNT
set operations
cartesian product
GROUP BY
HAVING
nested queries
JOIN
RESERVES
SID
BID
BOATS
Day
Deposit
23
109
01/08/2014
120
23
108
08/08/2014
120
25
101
08/08/20
Section 3
Entity-Relationship Models
Section Outline
Why do we need the ER model?
ER modelling constructs
Designing an ER model
Translating an ER model into a relational
database schema
Why do we need an ER model?
A database design is for a whole organis
What do these ER diagrams mean?
1) a student can take 0.N courses
2) a student can take 0.1 courses
3) a student can take 1.N courses
4) a student takes exactly 1 course
A) a course can have 0.N students
B) a course can have 1.N students
C) a course can h
Question 1
[10 Marks]
(a) What is the time complexity of an algorithm? Give the main reason why analysis of
algorithms is important. [3]
The time complexity of an algorithm is the amount of time [1] the algorithm takes to solve a
problem expressed as a fu
University of Cape Town
Department of Computer Science
Computer Science CSC2001F
Class Test 1, 19 March 2015
Marks: 35
Time: 45 minutes
Instructions: Answer all questions
Show all calculations where applicable
The use of calculators is permitted
Approxima
University of Cape Town
Department of Computer Science
Computer Science CSC2001F
Class Test 2, 11 May 2011
Marks:
Time:
Instructions:
35
45 minutes
Answer all questions
Show all calculations where applicable
The use of calculators is permitted
Approximate
Question 1 [6 marks]
An SRC needs a database of students and societies. Each society has a unique name,
membership fee that it charges students to join, and funding from the university.
Every society must have at least 40 members; its university funding i
University of Cape Town
Department of Computer Science
CSC2001F
Mock Solutions
1 March 2016
Solutions
Question 1
[6 Marks]
Give the Big O complexity for the following code pieces Briefly
justify each answer.
[1]
[2]
[2]
[1]
Question 2
[12 Marks]
a) Write
CSC2001F:
Non-Linear Data Structures and
Algorithms: Introduction
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
Overview
Analysis of Algorithms: Asymptotic (Big-O) Notation.
Recap: What is a Data Structure?
Its an abs
CSC2001F:
Non-Linear Data Structures and
Algorithms: Introduction
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
Overview
Big-O
Recursion
Algorithms and Code Structures Example
int partialSum = 0;
for ( int I = 0; I <
CSC2001F:
Non-Linear Data Structures and
Algorithms: Introduction
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
Course Overview
Data Structures 1 module:
Teaching Assistant:
Data Structures and Problem Solving Using J
CSC2001F:
Non-Linear Data Structures and
Algorithms:
AVL Trees
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
BST Operations and Efficiency
BST: is a linked structure similar to the linked list.
BST improves on linked
CSC2001F:
Non-Linear Data Structures and
Algorithms: Trees
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
Overview
Recurrence Relations
Trees
What is a Recurrence Relation?
A recurrence relation, T(n), is a recursive f
CSC2001F:
Non-Linear Data Structures and
Algorithms:
Binary Search Trees
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
Binary Trees Definition
An ordered tree is a tree for which the order of the children
of each node
CSC2001F:
Non-Linear Data Structures and
Algorithms AVL Trees
Geoff Nitschke
Department of Computer Science
University of Cape Town, South Africa
AVL Trees
Adelson-Velsky & Landis (1962):
1. A node of a tree is balanced if the heights of its
children diff