gyan from the geek n.
Skip this Video
Loading SlideShow in 5 Seconds..
Gyan from the Geek PowerPoint Presentation
Download Presentation
Gyan from the Geek

Gyan from the Geek

160 Views Download Presentation
Download Presentation

Gyan from the Geek

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Gyan from the Geek ApoorvaVadi M.S Information Systems New York University

  2. What is computer Science?

  3. Lets talk about M&M?The Math Monster

  4. BAD MATH !!!!

  5. Algorithms… What are those things?

  6. An algorithm…is like a recipe Problem solving as an analogy to cooking: 1. Inputs 2. Recipe/Set of defined rules (or an Algorithm) 3. Outputs

  7. Now lets use algorithms… To solve Puzzles! • Towers of Hanoi • Dining Philosophers • Travelling salesman • Eight queens

  8. Towers of Hanoi You have a stack of discs, from largest to smallest, that slide on to the first peg of a three peg board. Your goal is to move the entire stack of discs from the first peg to the third peg. However, you can only move the topmost disc of any peg, and smaller discs must always be placed on larger discs. How many moves will it take? 

  9. Now lets write a recipe for this… Alternating between the smallest and the next-smallest disks, follow the steps for the appropriate case: • For an even number of disks: • make the legal move between pegs A and B • make the legal move between pegs A and C • make the legal move between pegs B and C • repeat until complete For an odd number of disks: • make the legal move between pegs A and C • make the legal move between pegs A and B • make the legal move between pegs B and C • repeat until complete • In each case, a total of 2n-1 moves are made.

  10. But that was too long… lets try recursion… Step 1: Move N−1 discs from A to B. This leaves Nth disc alone on peg A. Step 2: Move Nth disc from A to C Step 3: Move N−1 discs from B to C so they sit on disc N.

  11. Dining Philosophers Problem Lets try something ‘non-arkymalarky’: Five philosophers sit around a circular table. In front of each philosopher is a large plate of rice. The philosophers alternate their time between eating and thinking. There is one chopstick between each philosopher, to their immediate right and left. In order to eat, a given philosopher needs to use both chopsticks. How can you ensure all the philosophers can eat reliably without starving to death?

  12. So this is a classic example of a common computing problem in concurrency… Issues: • Deadlock - cycle of unwarranted requests. Every philosopher picked up a left fork and waits for a right fork (forever). • Resource Starvation – one philosopher might have to wait extended amounts of time. • Mutual exclusion – multiple processes accessing sets of data.

  13. Welcome to the world of Data Structures • Stacks • Queues • Linked Lists • Trees Have Fun

  14. Applications of Stacks • Direct applications Page-visited history in a Web brows Undo sequence in a text editor • Indirect applications Component of other data structures

  15. Applications of Queues • Direct application Waiting lines Access to shared resources (e.g., printer) Multiprogramming • Indirect applications Component of other data structures

  16. List • A singly linked list is a concrete data structure • consisting of a sequence of nodes • -Each node stores element • -link to the next node

  17. We can implement a queue with a singly linked list -The front element is stored at the first node-The rear element is stored at the last node Queue with a Singly Linked List

  18. Doubly Linked List • A doubly linked list provides a natural implementation of the List ADT • Nodes implement Position and store: -element -link to the previous node -link to the next node • Special trailer and header nodes

  19. Doubly Linked List

  20. Trees • In computer science, a tree is an abstract model of a hierarchical • structure • -A tree consists of nodes with a parent-child • relation • Applications: • -Organization charts • -File systems • -Programming environments

  21. Binary Trees • A binary tree is a tree with the following properties: -Each internal node has two children -The children of a node are an ordered pair - We call the children of an internal • node left child and right child - Alternative recursive definition: a • binary tree is either -a tree consisting of a single node, or - a tree whose root has an ordered pair of children, each of which is a binary tree • Applications: -arithmetic expressions -decision processes -searching

  22. Binary Tree

  23. Tree Traversals(power of recursion) Depth First Search • Pre-order(NLR): Root Node- Left child- Right child A-B-D-E-H-I-C-F-G • In-order(LNR): Left child - Root Node - Right child D-B-H-E-I-A-F-C-G • Post-order(LRN): Left child - Right child – Root Node D-H-I-E-B-F-G-C-A Breadth First Traversal • Level order Traversal: Traverse each node level by level A-B-C-D-E-F-G-H-I

  24. Links • •

  25. That’s all folks !