Mar
22
2016

Data Structure Pertemuan 3 (Stack & Queue)

 

Stack:

  • An important data structure which stores its elements in an ordered manner.
  • Linear data structure which can be implemented using an array or linked list.
  • Last In First Out (LIFO)

Stack Operation:

  • Push(x)         : add an item x to the top of the stack.
  • Pop()  : remove an item from the top of the stack.
  • Top()  : reveal/return the top item from the stack.

Array Representation:

  • Top: Used to store topmost element of the stack
  • Max: Used to store the maximum number of elements that the stack can hold.
  • When Top is NULL, it means the stack is empty.
  • When Top = Max – 1, it means the stack is full.

Linked List Representation:

  • Linked list is more dynamic.
  • One part of node stores data.
  • One part of node stores the address of the next node.
  • Top in linked list is the START pointer
  • When Top is NULL, it means the stack empty.

Infix, Postfix, Prefix:

  • Prefix notation, also known as Reverse Polish notation.
  • Prefix : operator is written before operands
  • Infix notation (commonly used)
  • Infix  : operator is written between operands
  • Postfix notation, also known as Polish notation.
  • Postfix         : operator is written after operands

Depth First Search

  • An algorithm for traversing or searching in a tree or graph. We start at the root of the tree (or some arbitrary node in graph) and explore as far as possible along each branch before backtracking.

Queue

  • An important data structure which stores its elements in an ordered manner
  • The elements in a queue are added at one end called the rear and removed from the other one end called front.
  • FIRST IN FIRST OUT (FIFO)
  • Two Variable in queue are Front and rear that point to the position where deletions and insertions can be done respectively.
  • push(x)         : add an item x to the back of the queue.
  • pop()  : remove an item from the front of the queue.
  • front()         : reveal/return the most front item from the queue.

Type Of Queue:

  • Regular Queue
  • Circular Queue
  • Priority Queue

Priority Queue:

  • An abstract data type in which the each element is assigned a priority.
  • An element with higher priority is processes before an element with lower priority
  • Two elements with same priority are processed on a first come first served (FCFS) basis

Breadth First Search

  • An algorithm for traversing or searching in a tree or graph. We start at the root of the tree (or some arbitrary node in graph) and explore all neighboring nodes level per level until we find the goal.
  • BFS
Written by argadityarf in: Uncategorized |

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress. Theme: TheBuckmaker. Zinsen, Streaming Audio