530 likes | 783 Views
Data Structures & Algorithms. Week1. Contents. Textbook Grade Software. Textbook. C & Data Structures P. S. Deshpande, O. G. Kakde. Grade. Midterm test (20%) Final test (50%) Quizzes (25%) Attendance (5%). software. Visual C++ 2008. Exponents الاس (القوى)
E N D
Contents • Textbook • Grade • Software
Textbook • C & Data Structures • P. S. Deshpande, O. G. Kakde
Grade • Midterm test (20%) • Final test (50%) • Quizzes (25%) • Attendance (5%)
software • Visual C++ 2008
Exponents الاس (القوى) XY , or "X to the Yth power";X multiplied by itself Y times (الـ X تُضرب في نفسها y مرة) Some useful identities (بعض المتطابقات المفيدة ) XA XB = XA+B XA / XB = XA-B (XA)B = XAB XN+XN = 2XN 2N+2N = 2N+1 Math background: Exponentsمراجعة لبعض الخصائص الرياضية : الاسس Data Structures
Logarithms (اللوغاريتمات) definition: XA = B <===> logX B = A تعريف : XA = B اذا وفقط اذا كان logX B = A intuition: logX B means: "the power must raised X to it , to get B" بديهيا ً: logX B تعني : القوة التي يجب ان نرفع X اليها حتى يعطينا B . In this course, a logarithm with no base implies base 2.log B means log2 B في هذا الكورس , اللوغاريتمات المكتوبة بدون اساس تعني الاساس 2 log B تعني log2 B Examples log2 16 = 4 (because 24 = 16) log10 1000 = 3 (because 103 = 1000) Math background: Logarithmsمراجعة لبعض الخصائص الرياضية: اللوغاريتمات Data Structures
Identities for logs with addition, multiplication, powers: متطابقات اللوغاريتمات للجمع والضرب والاسس : log (AB) = log A + log B log (A/B) = log A – log B log (AB) = B log A Properties of Logarithms (خصائص اللوغاريتمات) Data Structures
Properties of Logarithms خصائص اللوغاريتمات)) Identity for converting bases of a logarithm: متطابقة لتحويل اساسات اللوغاريتمات : • example:log432 = (log2 32) / (log2 4) = 5 / 2 Data Structures - Introduction
When presented with an expression of the form: logaX = Y and trying to solve for X, raise both sides to the a power. X = aY When presented with an expression of the form: عند عرض تعبير رياضي بالشكل التالي : logaX = logbY and trying to solve for X, find a common base between the logarithms using the identity on the last slide. لايجاد قيمة X , نحاول ايجاد اساس مشترك ما بين اللوغاريتمات باستخدام المتطابقة الموجودة في الشريحة السابقة logaX = logaY / logab Logarithm problem solving (استخدام اللوغاريتمات لحل المشاكل) Data Structures
Determine the value of x in the following equation. اوجدي قيمة X في المعادلة التالية : log7 x + log713 = 3 Determine the value of x in the following equation. اوجدي قيمة X في المعادلة التالية : log8 4 - log8 x = log8 5 + log16 6 Logarithm practice problemsتدريبات على اللوغاريتمات Data Structures
Logarithm practice problemsتدريبات على مشاكل اللوغاريتمات • Proof that 16n3log8(10n2) + 100n2 = O(n3log n) • Eliminate low-order terms • Eliminate constant coefficients 16n3log8(10n2) + 100n2 16n3log8(10n2) n3log8(10n2) n3(log8(10) + log8(n2)) n3log8(10) + n3log8(n2) n3log8(n2) 2n3log8(n) n3log8(n) n3log8(2)log(n) n3log(n)/3 n3log(n) Data Structures - Introduction
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 Math review: Arithmetic seriesمراجعة رياضية : السلاسل الحسابية Data Structures
Arithmetic Series is there an intuition for this identity? sum of all numbers from 1 to N1 + 2 + 3 + ... + (N-2) + (N-1) + N how many terms are in this sum? Can we rearrange them? Series identitiesمتطابقات السلاسل Data Structures
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. More series identitiesالمزيد من متطابقات السلاسل : Data Structures
sum of constants(when the body of the series doesn't contain the counter variable such as i) مجموع القيم الثابتة (عندما يكون جسم السلسلة لايحتوي على متغير عداد , مثلا i) example: Series of constantsسلاسل الثوابت Data Structures
for any constant k, splitting a sum with addition تجزئة التجميع باستخدام + moving out a constant multiple تحريك المضروب الثابت الى الخارج Splitting seriesالسلاسل المجزاة Data Structures
sum of powers of 2 مجموع قوى الـ 2 1 + 2 + 4 + 8 + 16 + 32 = 64 - 1 = 63 when the series doesn't start at 0: عندما لاتبدا السلاسل بالصفر Geometric Seriesالسلاسل الهندسية Data Structures
Solve each of the following summation. i.e Find the expression without the S or "…". Series practiceتدريبات على السلاسل Data Structures
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.
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.
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.
Basic Data Structures • Structures include • linked lists • Stack, Queue • binary trees • …and others
2 4 6 1 3 5 7 1 2 3 4 5 6 7 What is Algorithm? • Algorithm: • A computable set of steps to achieve a desired result • Ralationship to Data Structure • Example: Find an element
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 لانها مبنية وجاهزة في اللغة ولكن المثال لتقريب المعنى ADT Data Structures
Chapter 0: C LANGUAGE • ADDRESS • POINTERS • ARRAYS • PASS ARRAY TO FUNCTION • ADDRESS OF EACH ELEMENT IN AN ARRAY • ACCESSING & MANIPULATING AN ARRAY USING POINTERS • TWO-DIMENSIONAL ARRAY • POINTER ARRAYS • STRUCTURES • STRUCTURE POINTERS
Chapter 0: C LANGUAGE • ADDRESS For every variable there are two attributes: address and value In memory with address 3: value: 45. In memory with address 2: value "Dave" cout << "Value of 'y' is: " << y << "\n"; cout << "Address of 'y' is: " << &y << "\n\n";
Chapter 0: C LANGUAGE 2. POINTERS • is a variable whose value is also an address. • 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
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);
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 &.
Chapter 0: C LANGUAGE 3. ARRAYS • An array is a data structure • used to process multiple elements with the same data type when a number of such elements are known. • An array is a composite data structure; that means it had to be constructed from basic data types such as array integers. • int a[5]; • for(int i = 0;i<5;i++) • {a[i]=i; }
Chapter 0: C LANGUAGE 4. نستطيع تمرير المصفوفة كمعامل في الدالة 4. WE CAN PASS ARRAY AS ARGUMNET IN A FUNCTION
Chapter 0: C LANGUAGE 5. عناوين عناصر المصفوفة 5. ADDRESS OF EACH ELEMENT IN AN ARRAY Each element of the array has a memory address.
Chapter 0: C LANGUAGE العلاقة مابين المصفوفات والمؤشرات (relation between array and pointer) يمكن الوصول الى عناصر المصفوفة باستخدام المؤشرات ملاحظة مهمة / اسم المصفوفة هو عبارة عن مؤشر ثابت يشير الى اول عنصر في المصفوفة 6. ACCESSING & MANIPULATINGAN 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
Chapter 0: C LANGUAGE 7. المصفوفة ذات البعدين . 7. TWO-DIMENSIONAL ARRAY int a[3][2];
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. مصفوفة المؤشرات : هي عبارة عن مصفوفة عناصرها عبارة عن مؤشرات لقيم في الذاكرة أي ان عناصر المصفوفة تحتوي عناوين .
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
Chapter 1: C LANGUAGE 10. STRUCTURE POINTERS Process the structure using a structure pointer
End ملاحظة : الاسبوع القادم سيكون الكويز (1)