Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structure and Algorithms (DDA 1224) Week 1 Introduction to data structures.

Similar presentations


Presentation on theme: "Data Structure and Algorithms (DDA 1224) Week 1 Introduction to data structures."— Presentation transcript:

1 Data Structure and Algorithms (DDA 1224) Week 1 Introduction to data structures

2 Rules and Regulations during Lecture  Be PUNCTUAL >10 minutes lateness will be considered LATE. >15 minutes lateness will be considered ABSENT.  Keep all your belongings aside and PAY ATTENTION.  Be QUIET. RISE YOUR HAND if you like to interrupt. Use ENGLISH ONLY.  Bring your own laptop/ stationery to jot down notes ONLY AFTER EACH MINI LECTURE.

3 Course Learning Outcomes  Implement basic data structures.  Apply the use of basic data structures in applications.  Apply the use of searching, sorting and recursive techniques in applications.

4 Pre-requisites Knowledge C++ Programming language Object-oriented programming (DOP1254)

5 Orwell Dev-C++ 5.11 Size: 51MB Source: Dev-C++Dev-C++ Require Tools

6 Content SectionTopicsDuration 1Module introduction30 2Mini lecture 1: Data structure30 3Break10 4Mini lecture 2: Algorithms30 5References10

7 Initial lecture …

8 Data Structure Data that is being stored during run time. It is an organization of a collection of items. It allows operations like indexing, sorting and searching.

9 Data structure ArrayStack Linked- list QueueTree Hash table

10 Pointers A pointer is a variable, which consisted of an address and a value. It is used to refer to an address for another variable. Example: *, Dereferencing operator. Retrieve value for a pointer that it is pointing to. &, Ampersand, referencing operator. Retrieve the address for a pointer that it is pointing to.

11 Pointers int *pointer; //To declare a pointer. pointer = null; //Initialization of a pointer. int variableA = 5; pointer = variableA; //Pointing pointer to variableA. cout<<*pointer<<endl; //Output: 5 cout<<pointer<<endl; //Output: Address of variableA.

12 Pointers To declare a pointer int *ptr; ptr = NULL; Point to an array ptr = array; 01234 ptr NULL

13 Pointers int *ptr; ptr = NULL; int arrayA[5]; ptr = arrayA; cout<<*ptr<<endl; //Output: 2 cout<<*(ptr+1)<<endl; //Output: 4 cout<<*(ptr+4)<<endl; //Output: 10 01234 246810 ptr NULL

14 2D Array Pointer: Part 1 To declare a pointer for the pointers int **ptr; Pointer to the backbone ptr = new int*[5]; ptr 0 1 2 3 4

15 2D Array Pointer: Part 2 Point each of the pointers to a new array. ptr[0] = new int[5]; ptr[1] = new int[5]; ptr[2] = new int[5]; ptr[3] = new int[5]; ptr[4] = new int[5]; cout<<ptr[2][2]<<endl; //Output: 2 cout<<ptr[3][4]<<endl; //Output: 4 cout<<ptr[5][4]<<endl; //Run time error. Because memory is not allocated in the RAM. ptr 0 1 2 3 4 01234 01234 01234 01234 01234

16 2D Array Pointer: Part 3 Point each of the pointers to a new array. ptr[0] = new int[5]; ptr[1] = new int[4]; ptr[2] = new int[3]; ptr[3] = new int[1]; ptr[4] = new int[2]; ptr 0 1 2 3 4 0123 012 0 01 01234

17 Continue lecture …

18 Algorithms An algorithm is a step by step of instructions to solve a problem. It is a combination of arithmetic operations and logic. Typically the pseudocode are used to express its definitions. Flowcharts are used as well to visualize the flow.

19 Pseudo codes ALGORITHM GCD(X, Y) 1. WHILE (X ≠ Y) a. IF (X > Y) THEN i. X <- X – Y b. ELSE i. Y <- Y - X 2. RETURN (X) END OF FUNCTION GCD Flowchart FALSE TRUE

20 References Malik D.S. (2010). Data structure using C++. 2 nd Ed., Thomson Course Technology. Deitel P. (2010). C++: How to program. 7th Ed., Prentice Hall. Main M. (2010). Data structure & other objects using C++. 4 th Ed., Prentice Hall.


Download ppt "Data Structure and Algorithms (DDA 1224) Week 1 Introduction to data structures."

Similar presentations


Ads by Google