Lecture 1:  Introduction

 

Objectives of this lecture

q       Take an overview of the course contents

q       Take an overview of basic concepts of data structures

q       Review some C Language concepts

 

Overview of the course contents

q       The aim of this course is to develop the skills of students to be able to handle real-life (complex) applications and also to prepare them for more serious courses ahead.

q       This will be done by leaning the various tools and methods that are required for such applications.

q       Students will also lean how to analyze the efficiency of algorithms.

 

q       The topics to be covered as stated in the syllabus are as follows:

 

Ø      Elementary Concepts: Concepts of data structures (data types) and algorithms. Elementary data types, Abstraction and Abstract Data Types (Ch. 4.8). Principles of good algorithm and program design (Ch. 2.6.2).

Ø      Algorithm Analysis and Sorting (chap 6 and chap 7): Algorithm analysis, space/time trade-offs, the Big-O notation (Ch. 6.7). Application to simple, familiar algorithms on searching (Sequential and binary search) (Ch. 6.2 & 6.4) and sorting (selection sort, bubble sort, and insertion sort) (Ch. 7.2 & 7.3). Merge sort, quick sort (Ch. 7.6 & 7.7).

Ø      Tables and Information retrieval (chap 8): Table Abstract Data Type. Hashing, and Conflict resolution. Radix Sort. Proxmap sort (chapter 8).

Ø      Stacks and Recursion (chap 3): Review and applications of Stacks,  Recursion. (chapter 3)

Ø      Queues and Linked Lists (chap 4 & 5): Review and applications of queues. Linked lists, Doubly and circularly linked list (chap 5).

Ø      Trees (Ch. 9): Binary trees. Heap trees, Ordered binary trees, B-trees. Implementation of binary trees using linear and linked lists. Tree traversals. Binary tree insertion and deletion. Heapsort (7.9).

Ø      Graphs (Ch. 11): Directed and undirected graphs. Depth-first search, breadth-first search. Topological sorting. Minimum Spanning Tress. Shortest path (Dijkstra algorithm).

 

 

Overview of Concepts of data structures

Data types

q       A data type is a set (collection of objects) together with a set of operations that act on those objects.

E.g.  type int (in C) consists of:

The set of objects: { -INT_MAX, …, -1, 0, 1, 2, …, MAX_INT }

And the set of operators: { +, -, /, *, >, <, …}

q       Data types may be pre-defined (e.g. int, float, char) or user-defined (e.g. weekday).

q       Data types may also be simple (also called atomic) or structured.  int, float, char are all examples of simple types, while arrays, structures and files are examples of structured types.

q       Recall that C provides the following tools for creating user-defined types:

enum – for specifying enumerated types

struct – for specifying structured types

typedef – for assigning names to types

 

e.g.

enum weekday {SUNDAY, MONDAY, TUESDAY, WEDNESDAY,

 THUSRDAY, FRIDAY, SATURDAY};

struct date {     int day; 
                           int month; 
                           int year;
                    };
typedef struct date { int day; 
                                       int month; 
                                       int year;
                                  } DATE;

 

Abstract Data Types (ADTs)

q       Abstract data type are data types that are organized in such a way that the specification of their objects and operations is separated from their implementation – information hiding

q       ADTs gives a very powerful method of organizing programs and their associated data structures

q       In an ADT the operations on the type are made available to the user while the data structure used to implement the operations as well as the details of such implementations are hidden from the user

q       The benefit of this is that the user of the ADT does not need to concern themselves with the implementation details.

 

q       The implementation can change without forcing the user to modify the code that uses that ADT. This creates a consistent interface to the ADT.

q       Hidden implementation protects structures from misuse.

q       Reasons for changing the implementation could include:

Ø      Fixing errors in the ADT code.

Ø      Changing representation to take advantage of more efficient algorithms or hardware.

 

ADTs: Examples

q       All built-in data types are are in fact ADTs since their implementation is hidden from the user

 

For example, while we can define values of floating-point types, the actual representation format of these values inside the computer are hidden from the user

 

The user cannot directly manipulate the parts of the actual representation of floating-point objects because that representation is hidden

 

q       The ADT Stack

Stack is a non-implemented data structure with a set of operations that can be used to access the data structure

 

In the ADT stack, items are added/removed from the same stack location called the top.

 

The following are the basic operations for ADT stack:

1. createStack()

2. destroyStack()

3. fullStack()

4. emptyStack()

5. pushStack()

6. popStack()

 

 

 

q       The ADT Queue

Like the array and the stack, the queue is also a homogeneous collection of objects

 

The difference between a stack and queue lies in the way they are accessed

 

While the stack is a LIFO structure, the queue is a FIFO structure

 

While a stack has one access point, the top, a queue has two access points: the front from where objects are removed and the rear where objects are added

 

The following are the basic operations on  ADT queue:

1. createQueue()

2. destroyQueue()

3. fullQueue()

4. emptyQueue()

5. enqueueItem()

6. dequeueItem()

 

 

 

q       We shall take a detail review and applications of these very important ADTs later in the course.

 

Review of some C concepts

q       It is instructive to review the notes on C from ICS201

q       Some of the areas of importance are:

q       Scope and life-time of variables

Ø      -local/global

Ø      -auto,static, extern and register

q       Function parameters

Ø      Parameters (formal parameters)/arguments (actual parameters)

Ø      Pass by value & pass by reference

q       Arrays (One and multi-dimensional)

Ø      -declarations

Ø      -accessing

Ø      -relationship with pointers

Ø      -passing as arguments/parameters to functions

q       Pointers

Ø      -declaration/meaning

Ø      operators (& and *)

Ø      assignment / de-referencing

Ø      obtaining memory with (anonymous variables)

Ø      associated functions – malloc(), free(), sizeof()

q       Functions for handling text files, strings and characters

Ø      -fopen(), fscanf(), etc.

Ø      strcpy(), strcat(), etc.

Ø      tolower(), isupper(), etc.