Fundamentals of Computer Science: Binary Search Trees and Stacks, Slides of Computer Science

An overview of binary search trees and stacks in computer science. It covers the basics of stack and queue interfaces, their lifo and fifo properties, and their implementation using arrays and linked lists. The document also introduces binary trees, their definitions, and implementation using an array. It discusses binary tree traversals, including inorder, preorder, postorder, and level order traversals. The document concludes with some facts and questions about trees and an introduction to big-o notation.

Typology: Slides

2012/2013

Uploaded on 01/02/2013

netii
netii 🇮🇳

4.4

(7)

91 documents

1 / 57

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fundamental Structures of
Computer Science
Binary Search Trees
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download Fundamentals of Computer Science: Binary Search Trees and Stacks and more Slides Computer Science in PDF only on Docsity!

Fundamental Structures of

Computer Science

Binary Search Trees

A Stack interface

public interface Stack { public void push(Object x); public void pop(); public Object top(); public boolean isEmpty(); public void clear(); }

Stacks are LIFO

a

b

c

d

e

Pop operation:

Last element that was pushed is the first to be popped.

A Queue interface

public interface Queue { public void enqueue(Object x); public Object dequeue(); public boolean isEmpty(); public void clear(); }

Queues are FIFO

back front

y^ k^ r^ q^ c^ m

Enqueue operation:

Queues are FIFO

back front y k r q c m

Enqueue operation:

Implementing stacks, 1

a

b

c

Linked representation. All operations constant time, or O(1).

Implementing stacks, 2

  • An alternative is to use an array-based

representation.

  • What are some advantages and disadvantages of an

array-based representation?

a b c

top

Now to Trees

CS is upside down

root

leaves

Arithmetic Expressions

Game trees

Tree Definitions

• A tree is a set of nodes and a set of directed

edges that connects pairs of nodes.

• A tree is a a Directed, Acyclic Graph (DAG)

with the following properties

• - one vertex is distinguished as the root;

no edges enter this vertex

• - every other vertex has exactly one

entering edge

Trees, more abstractly

• A tree is a directed graph with the following

characteristics:

  • There is a distinguished node called the root node.
  • Every non-root node has exactly one parent node

(the root has none).