Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures & Algorithms Week1. Contents Textbook Grade Software.

Similar presentations


Presentation on theme: "Data Structures & Algorithms Week1. Contents Textbook Grade Software."— Presentation transcript:

1 Data Structures & Algorithms Week1

2 Contents Textbook Grade Software

3 Textbook C & Data Structures – P. S. Deshpande, O. G. Kakde

4 Grade Midterm test (20%) Final test (50%) Quizzes (25%) Attendance (5%)

5 software Visual C++ 2008

6 Math background: Exponents مراجعة لبعض الخصائص الرياضية : الاسس 6 Exponents الاس (القوى) – X Y, or "X to the Y th power"; X multiplied by itself Y times (الـ X تُضرب في نفسها y مرة) Some useful identities (بعض المتطابقات المفيدة ) – X A X B = X A+B – X A / X B = X A-B – (X A ) B = X AB – X N +X N = 2X N – 2 N +2 N = 2 N+1 Fall 2010Data Structures

7 Math background: Logarithms مراجعة لبعض الخصائص الرياضية: اللوغاريتمات 7 Logarithms (اللوغاريتمات) – definition: X A = B log X B = A تعريف : X A = B اذا وفقط اذا كان log X B = A – intuition: log X B means: "the power must raised X to it, to get B" بديهيا ً: log X B تعني : القوة التي يجب ان نرفع X اليها حتى يعطينا B. – In this course, a logarithm with no base implies base 2. log B means log 2 B في هذا الكورس, اللوغاريتمات المكتوبة بدون اساس تعني الاساس 2 log B تعني log 2 B Examples – log 2 16 = 4(because 2 4 = 16) – log 10 1000 = 3(because 10 3 = 1000) Fall 2010Data Structures

8 Properties of Logarithms (خصائص اللوغاريتمات) 8 Identities for logs with addition, multiplication, powers: متطابقات اللوغاريتمات للجمع والضرب والاسس : log (AB) = log A + log B log (A/B) = log A – log B log (A B ) = B log A Fall 2010Data Structures

9 Data Structures - Introduction 9 Identity for converting bases of a logarithm: متطابقة لتحويل اساسات اللوغاريتمات : – example: log 4 32 = (log 2 32) / (log 2 4) = 5 / 2 Properties of Logarithms خصائص اللوغاريتمات))

10 Logarithm problem solving (استخدام اللوغاريتمات لحل المشاكل) 10 When presented with an expression of the form: – log a X = Y and trying to solve for X, raise both sides to the a power. – X = a Y When presented with an expression of the form: عند عرض تعبير رياضي بالشكل التالي : log a X = log b Y and trying to solve for X, find a common base between the logarithms using the identity on the last slide. لايجاد قيمة X, نحاول ايجاد اساس مشترك ما بين اللوغاريتمات باستخدام المتطابقة الموجودة في الشريحة السابقة – log a X = log a Y / log a b Fall 2010Data Structures

11 Logarithm practice problems تدريبات على اللوغاريتمات 11 Determine the value of x in the following equation. اوجدي قيمة X في المعادلة التالية : log 7 x + log 7 13 = 3 Determine the value of x in the following equation. اوجدي قيمة X في المعادلة التالية : – log 8 4 - log 8 x = log 8 5 + log 16 6 Fall 2010Data Structures

12 Data Structures - Introduction 12 Proof that 16n 3 log 8 (10n 2 ) + 100n 2 = O(n 3 log n) – Eliminate low-order terms – Eliminate constant coefficients 16n 3 log 8 (10n 2 ) + 100n 2  16n 3 log 8 (10n 2 )  n 3 log 8 (10n 2 )  n 3 (log 8 (10) + log 8 (n 2 ))  n 3 log 8 (10) + n 3 log 8 (n 2 )  n 3 log 8 (n 2 )  2n 3 log 8 (n)  n 3 log 8 (n)  n 3 log 8 (2)log(n)  n 3 log(n)/3  n 3 log(n) Logarithm practice problems تدريبات على مشاكل اللوغاريتمات

13 Math review: Arithmetic series مراجعة رياضية : السلاسل الحسابية 13 Series – for some expression Expr (possibly containing i ), means the sum of all values of Expr with each value of i between j and k inclusive الرمز يعني مجموع القيم الناتجة من التعبير الرياضي Expr بالتعويض بقيم i والتي تبدا من j وتنتهي بالـ K Example: = (2(0) + 1) + (2(1) + 1) + (2(2) + 1) + (2(3) + 1) + (2(4) + 1) = 1 + 3 + 5 + 7 + 9 = 25 Fall 2010Data Structures

14 Series identities متطابقات السلاسل 14 Arithmetic Series is there an intuition for this identity? – sum of all numbers from 1 to N 1 + 2 + 3 +... + (N-2) + (N-1) + N – how many terms are in this sum? Can we rearrange them? Fall 2010Data Structures

15 More series identities المزيد من متطابقات السلاسل : 15 sum from a through N inclusive (when the series doesn't start at 1) مجموع القيم مابين a و N (في حالة السلاسل التي لاتبدا بـ 1) is there an intuition for this identity? – The sum of all numbers from 4 to 10 is just the sum of all numbers from 1 to 10, minus the sum of 1 through 3. Fall 2010Data Structures

16 Series of constants سلاسل الثوابت 16 sum of constants (when the body of the series doesn't contain the counter variable such as i) مجموع القيم الثابتة (عندما يكون جسم السلسلة لايحتوي على متغير عداد, مثلا i) example: Fall 2010Data Structures

17 Splitting series السلاسل المجزاة 17 for any constant k, splitting a sum with addition تجزئة التجميع باستخدام + moving out a constant multiple تحريك المضروب الثابت الى الخارج Fall 2010Data Structures

18 Geometric Series السلاسل الهندسية 18 sum of powers of 2 مجموع قوى الـ 2 – 1 + 2 + 4 + 8 + 16 + 32 = 64 - 1 = 63 when the series doesn't start at 0: عندما لاتبدا السلاسل بالصفر Fall 2010Data Structures

19 Series practice تدريبات على السلاسل 19 Solve each of the following summation. – i.e Find the expression without the  or "…". Fall 2010Data Structures

20 CHAPTER 0: INTRODUTION What is Data Structures? – A data structure is defined by (1) the logical arrangement of data elements, combined with (2) the set of operations we need to access the elements.

21 Atomic Variables Atomic variables can only store one value at a time. int num; float s; A value stored in an atomic variable cannot be subdivided.

22 What is Data Structures? Example:library – is composed of elements (books) – Accessing a particular book requires knowledge of the arrangement of the books – Users access books only through the librarian the logical arrangement of data elements, combined with the set of operations we need to access the elements.

23 Basic Data Structures Structures include – linked lists – Stack, Queue – binary trees – …and others

24 What is Algorithm? Algorithm: – A computable set of steps to achieve a desired result – Ralationship to Data Structure Example: Find an element 1234567 1 2 3 4 5 6 7

25 Sumary

26 ADT ADT = Abstract Data Types ADT is A logical view of the data objects together with specifications of the operations required to create and manipulate these objects. ADT=user-defined data taype بمعنى االمبرمج هو الذي يبنيها تبعا لاحتياجاته مثال int لا يعتبر ADT لانها مبنية وجاهزة في اللغة ولكن المثال لتقريب المعنى Fall 2010 26 Data Structures

27 Chapter 0: C LANGUAGE 1. ADDRESS 2. POINTERS 3. ARRAYS 4. PASS ARRAY TO FUNCTION 5. ADDRESS OF EACH ELEMENT IN AN ARRAY 6. ACCESSING & MANIPULATING AN ARRAY USING POINTERS 7. TWO-DIMENSIONAL ARRAY 8. POINTER ARRAYS 9. STRUCTURES 10. STRUCTURE POINTERS

28 Chapter 0: C LANGUAGE 1. ADDRESS For every variable there are two attributes: address and value cout << "Value of 'y' is: " << y << "\n"; cout << "Address of 'y' is: " << &y << "\n\n"; In memory with address 3: value: 45. In memory with address 2: value "Dave"

29 Chapter 0: C LANGUAGE 2. POINTERS 1. is a variable whose value is also an address. 2. A pointer to an integer is a variable that can store the address of that integer ia: value of variable &ia: address of ia *ia means you are printing the value at the location specified by ia

30 Chapter 0: C LANGUAGE int i; //A int * ia; //B printf("The address of i is %p\n", &i); printf("The address of ia is %p\n", &ia); i = 10; //C ia = &i; //D printf("after assigning value:\n"); printf("The address of i is %p value= %d\n", &i,i); printf("The address of ia is %p value= %p point to %d\n", &ia,ia,*ia);

31 Chapter 0: C LANGUAGE Points to Remember Pointers give a facility to access the value of a variable indirectly. You can define a pointer by including a * before the name of the variable. You can get the address where a variable is stored by using &.

32 Chapter 0: C LANGUAGE 3. ARRAYS 1. An array is a data structure 2. used to process multiple elements with the same data type when a number of such elements are known. 3. An array is a composite data structure; that means it had to be constructed from basic data types such as array integers. 1. int a[5]; 2. for(int i = 0;i<5;i++) 1. {a[i]=i; }

33 Chapter 0: C LANGUAGE 4. نستطيع تمرير المصفوفة كمعامل في الدالة 4. WE CAN PASS ARRAY AS ARGUMNET IN A FUNCTION

34 Chapter 0: C LANGUAGE 5. عناوين عناصر المصفوفة 5. ADDRESS OF EACH ELEMENT IN AN ARRAY Each element of the array has a memory address.

35 Chapter 0: C LANGUAGE العلاقة مابين المصفوفات والمؤشرات (relation between array and pointer) يمكن الوصول الى عناصر المصفوفة باستخدام المؤشرات ملاحظة مهمة / اسم المصفوفة هو عبارة عن مؤشر ثابت يشير الى اول عنصر في المصفوفة 6. ACCESSING & MANIPULATING AN ARRAY USING POINTERS – You can access an array element by using a pointer. – If an array stores integers->use a pointer to integer to access array elements. int a[5]; int *p; a=b; //error b=a; //OK

36 Chapter 0: C LANGUAGE 7. المصفوفة ذات البعدين. 7. TWO-DIMENSIONAL ARRAY int a[3][2];

37 Chapter 0: C LANGUAGE 8. POINTER ARRAYS You can define a pointer array (similarly to an array of integers). In the pointer array, the array elements store the pointer that points to integer values. مصفوفة المؤشرات : هي عبارة عن مصفوفة عناصرها عبارة عن مؤشرات لقيم في الذاكرة أي ان عناصر المصفوفة تحتوي عناوين.

38 8. POINTER ARRAYS

39 Chapter 0: C LANGUAGE 9. STRUCTURES Structures are used when you want to process data of multiple data types But you still want to refer to the data as a single entity Access data: structureveriable.membername

40 Chapter 0: C LANGUAGE

41 Chapter 1: C LANGUAGE 10. STRUCTURE POINTERS Process the structure using a structure pointer

42 End ملاحظة : الاسبوع القادم سيكون الكويز (1)


Download ppt "Data Structures & Algorithms Week1. Contents Textbook Grade Software."

Similar presentations


Ads by Google