Your SlideShare is downloading. ×
0
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Algorithms
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Algorithms

1,347

Published on

Event #3 for DevMix Team

Event #3 for DevMix Team

Published in: Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,347
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
64
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Program<br />By :- Eman El-ma’asarawi<br />2/24/2011<br />1<br />
  • 2. What is Program?<br />How to make program?<br />How to think about the program?<br />Steps for making a good project.<br />2/24/2011<br />2<br />
  • 3. 2/24/2011<br />3<br />
  • 4. DS<br />Algorithm<br />Program<br />+ <br />=<br />2/24/2011<br />4<br />
  • 5. list of instruction to achieve specific task.<br />Program<br />I/P instruction<br />Processing instruction<br />O/P instruction<br />2/24/2011<br />5<br />
  • 6. Programming Toolboxes<br />H/W<br />S/W<br />Os<br />Compiler <br />Text editor<br /> Idea ware<br />Algorithm<br />DS<br />Programming Methodologies<br />Structure Design<br />Oop<br /> S/W Concepts<br />Information hiding<br />Data encapsulation<br />Data abstraction<br />2/24/2011<br />6<br />
  • 7. Algorithm<br />DS<br />Methodologies<br />Application (text editor)<br />Compiler <br />OS<br />HW<br />2/24/2011<br />7<br />
  • 8. DS (Data Structure)<br />Data :- factual information <br />Structure :- Arrangement or relationship of elements as particles<br />Data structure :-A means of storing a collection of data<br />2/24/2011<br />8<br />
  • 9. DS cont…<br />A data structure can be viewed as consisting of a set of algorithms for performing operations on the data it stores.<br />2/24/2011<br />9<br />
  • 10. Variable:-<br /> data storage location that has a value that can change during program execution.<br /> Constant:-<br /> fixed value that can’t change.<br />2/24/2011<br />10<br />
  • 11. Applications of Data Structure<br />DS<br />Linear<br />Non-Linear<br />Sequential<br />Linked<br />Linked<br />queues<br />Graphs<br />Tree<br />Linked<br />stacks<br />linked<br />lists<br />queue<br />array<br />stack<br />2/24/2011<br />11<br />
  • 12. 1-Array<br />2-Linked List<br />3-Stack<br />4-Queue<br />5-Tree<br />2/24/2011<br />12<br />
  • 13. 1-Array <br />Is a data structure where all elements are stored in contiguous memory<br />n<br />2<br />1<br />0<br />Individual elements<br />Array <br />2/24/2011<br />13<br />
  • 14. Random access<br />Fixed size<br />Less efficient used on data stored in array<br />Array properties<br />Array size<br />Element size<br />1-in bytes<br />2-the number of element<br />Data type of array<br />2/24/2011<br />14<br />
  • 15. Exambel<br />0<br />1<br />2<br />3<br />4<br />5<br />6<br />7<br /> 1 2 34 56 2 78 0 10<br />2/24/2011<br />15<br />
  • 16. 2-linked list<br />Is a data structure in which the first element is (head) stored on its own<br />Data<br />List head /<br />Dummy Node<br />Null<br />2/24/2011<br />16<br />
  • 17. Linked list properties<br />The size not fixed grow/shrink<br />The extra space is needed to store the pointer of each element <br />More time<br />Implement linked list use array but not efficient<br />Complex to code and manage<br />2/24/2011<br />17<br />
  • 18. Appending Node<br /> add Node to the end of the list.<br />Traversing<br /> check the linked list.<br />Inserting Node<br /> add Node in the middle of a list.<br />Deleting Node from memory<br /> Modified links<br />Destroy<br />Operation on linked list<br />2/24/2011<br />18<br />
  • 19. Which is fast array or linked list?<br />Why?<br />2/24/2011<br />19<br />
  • 20. Is a data structure consisting of data nodes connected to each other with pointers.<br />Each node connected to 2 or more other nodes.<br />2/24/2011<br />20<br /> 5-Trees<br />
  • 21. The order of the tree:-<br /> is the max number of nodes to which any single node connected.<br /> binary tree:-<br /> is the simplest tree is of order 2.<br /> each child have two pointers.<br />Root node:-<br /> the topmost node in the tree.<br /> leaf node:-<br /> node with no children.<br />2/24/2011<br />21<br />Tree properties<br />
  • 22. Data<br />right<br />left<br />Data<br />right<br />left<br />Data<br />right<br />left<br />2/24/2011<br />22<br />
  • 23. Create binary tree<br />Inserting Node<br />Traversing the tree recursion<br />Searching the tree<br />Deleting the tree<br />2/24/2011<br />23<br />Binary search tree op…<br />
  • 24. Logical sequence of steps describe complete solution to solve problem in finite amount of time<br />May involve alternation, iteration or recursion<br />More than one algorithm possible for the same task<br />Algorithms<br />2/24/2011<br />24<br />
  • 25. Sorting Searching<br />-Insertion sort -linear search<br />-Merge sort -Binary search <br />-Heap sort<br />-Quick sort<br />2/24/2011<br />25<br />Algorithmes<br />
  • 26. What resources are required to accomplish the task <br />How one algorithm compares with other algorithms <br />How much time or space is required <br />Measured in terms of common basic operations<br />Efficiency of Algorithms<br />2/24/2011<br />26<br />
  • 27. Worst-case: (usually)<br /> T(n) = maximum time of algorithm on any input of size n.<br />Average-case: (sometimes)<br />T(n) = expected time of algorithm over all inputs of size n.<br />Need assumption of statistical distribution of inputs.<br />Best-case: (bogus)<br /> Cheat with a slow algorithm that works fast on some input.<br />2/24/2011<br />27<br />Kinds of analyses <br />
  • 28. Running time: <br />On a particular input, it is the number of<br />primitive operations (steps) executed.<br /> One line may take a different amount of time than<br />another, but each execution of line i takes the same<br />amount of time c .<br />Running time of the algorithm is<br /> Ʃ (cost of statement)*(number of times statement is executed)<br />2/24/2011<br />28<br />
  • 29. How efficiency varies with the size of the task <br />E.g. if the size of the task increases linearly, do the efficiency measures increase linearly, quadratically, exponentially,...? <br />Expressed in terms of standard functions of n<br />Complexity<br />2/24/2011<br />29<br />
  • 30. notations<br />Big o<br />Big Ɵ<br />Big Ω<br /> F(n)=g(n)<br />C1g(n)<=f(n)<=c2g(n)<br />F(n)<=g(n)<br />F(n)>=g(n)<br />Data shape<br />Ex - insertion sort<br />best case<br />Data method<br />Ex – insertion sort<br />worst case<br />2/24/2011<br />30<br />
  • 31. PseudoCodeconventions<br />Indentation indicates block structure. While, for, repeat , if , then, and else.<br />▹indicates comment.<br />indicates assignment.<br />Variables are local by default.<br />Array elements accessed as in A[i].<br />2/24/2011<br />31<br />
  • 32. Calculate x^n, where n is an integer greater than 0.<br />Algorithm<br />1. Set r = 1<br />2. Set i = 1<br />3. Repeat<br /> 3.1 If i=n then terminate loop<br /> 3.2 Multiply r by x<br /> 3.3 Add 1 to i<br />4. Exit with result r<br />ExampleSimple Power Algorithm<br />2/24/2011<br />32<br />
  • 33. O(n) - the algorithm requires n multiplications.<br />Time complexity<br />2/24/2011<br />33<br />
  • 34. Formulate a Concise Specification of the Problem<br />Design a high-level strategy for a solution<br />Refine steps 1 and 2 if necessary<br />Complete the details of the design<br />Implement in the chosen language<br />How to Approach Recursive Algorithms<br />2/24/2011<br />34<br />
  • 35. Calculate x^n, where n is an integer greater than 0. <br />Recursive Algorithm<br />1. If n=0 then <br />1.1 set r = 1 <br />2. Else <br />2.1 set p = n/2 (dropping any remainder) <br />2.2 set r = (xp)2 <br />2.3 if n is odd then <br />2.3.1 multiply r by x <br />3. Exit with result r<br />Recursive Power Algorithm<br />2/24/2011<br />35<br />
  • 36. static int power (int x, int n) {<br /> int r;<br /> if (n == 0)<br /> r = 1;<br /> else {<br /> r = power(x,n/2);<br /> r = r*r;<br /> if (n%2 != 0)<br /> r *= x;<br /> }<br /> return r;<br />}<br />2/24/2011<br />36<br />implementation<br />
  • 37. O(log n) - the algorithm requires approximately log n multiplications.<br />2<br />Time complexity<br />2/24/2011<br />37<br />
  • 38. 2/24/2011<br />38<br />
  • 39. Quiz<br />Towers of Hanoi<br />1<br />2<br />3<br />2/24/2011<br />39<br />
  • 40. 1<br />2<br />3<br />2/24/2011<br />40<br />
  • 41. 1<br />2<br />3<br />2/24/2011<br />41<br />
  • 42. 1<br />2<br />3<br />2/24/2011<br />42<br />
  • 43. 1<br />2<br />3<br />2/24/2011<br />43<br />
  • 44. 1<br />2<br />3<br />2/24/2011<br />44<br />
  • 45. 1<br />2<br />3<br />2/24/2011<br />45<br />
  • 46. 1<br />2<br />3<br />2/24/2011<br />46<br />
  • 47. Solution' ≡ shortest path <br />Recursive Solution:<br />1. Identify biggest discrepancy (=disk N) <br />2. If moveable to goal peg Then move<br /> Else<br />3. Subgoal: set-up (N−1)-disk tower on non-goal peg. <br />4. Go to 1. ...<br />2/24/2011<br />47<br />
  • 48. 2/24/2011<br />48<br />
  • 49. SDLC (s/w Development life cycle)<br />Design<br />Problem analysis<br />Maintenance <br />Testing<br />Requirement definitions<br />Implementation <br />Using program <br />Delivery<br />2/24/2011<br />49<br />
  • 50. The End<br />2/24/2011<br />50<br />

×