Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Data Structure

- Specialized format to store and organize data in a computer's


memory or disk.

- Collection of variables, possibly of several different types


connected in a various ways.

Type of data structure:

• Array
• Linked List
• Stacks
• Queue
• Tree
Arrays

- Ordered collection of data items of the same type referred to


collectively by a single name.

- Index – each variable or cell in an array.

- Elements – individual data/items in an array indicated by the


array name followed by its dimensions appears in a bracket.

- Dimensions – an integer from 1-A called dimensioned variables.

Array name [0] [0]

Operation in an Array

1. Insert
2. Search
3. Delete

Three types of an Array:

1. One-dimensional Array - A one-dimensional array (or single


dimension array) is a type of linear array - Accessing its elements
involves a single subscript, which can either represent a row or
column index.

2. Two-dimensional Array - Two-dimensional arrays are defined as "an


array of arrays".

3. Multi-dimensional Array -
Searching

- Great algorithms have been devised for searching because it is


important.

- Information retrieval is one of most common operations


performed by computer applications.

- Search key – uniquely identifies the data being requested by the


user..

Key field – contains the key record


Information key – contains the information associated with the key in the
key field.

Bubble Sort – simplest in sorting process

 Compare two elements in the array


 If the element on the left is larger than the element in the
right, swap them
 If vice versa, no move will be done
 Compare now the element that was swapped to the element
on its right position.

How to sort?

 As human, we can do this by living up the items


 Computer’s not like humans can visually compare things two
items at once

 It uses two steps to execute over and over until data are
stored
- Compare the two items
- Swap the two items or copy one item but still; the data
are handled in different ways.

Insertion Sort

- To perform insertion sort:


- Divide the list into two: sorted part and the unsorted
part.
- Unsorted part: transfer one by one to their correct
location in the sorted area.
Linked List

Contains class of list maybe represented using arrays

- List that are fixed in length


- List that do not require a considerable amount of insertion and
deletion

Types of Linked List:

• Singly-linked list
• Doubly-linked list

Singly-linked lists

-Is represented as a structure called node.

Basic part:

Data Pointer

Data field – is used to contain the value of the element.


Pointer field – contains the address of the next node in the list of a
computer memory, which is a number that refers to an object.

The “next node” in the list is called SUCCESSOR. If a node is the last node
in the list, meaning it has no successor, the pointer would contain the
value NULL.

10 05 03 15
Martin Anabelle Bella Carlo
05 03 15 N

Common operation on Linked list:

1. Insert – it is usually inserted at the beginning of the list. This


is the simplest approach though it’s also possible to insert
nodes anywhere in the list
2. Search – when searching a value existing in a list, it moves
along the list searching for the specified vale then prompts
you the address of the node. However, when not found, an
error will return prompting you that the item can’t be found.
3. Delete – specify value to delete in the list and it performs the
searching before deleting the value.
Doubly linked Lists

- List allows you to traverse backward as well as forward


through the list.

Format of a Doubly-linked List:

Right
Left Pointer Data
Pointer

Divided into three (3) parts:

1. Left pointer – contains the address of the previous node in the list.
2. Data Field – is used to contain the value of the element.
3. Right pointer – contain the address of the next node in the list.

The data field and the right pointer function in the manner as singly-linked
lists. If the node is the last node in the list, then the right pointer field
would contain the value NULL. The only new concept in a doubly-linked
list node is the left pointer field. It is used to contain the of the preceding
node in the list or what is known as the PREDECESSOR. If the node is the
first node in the list, this field will contain the value NULL since it has no
predecessor.

03 10 05

N X 10 03 Y 05 10 Z N

Traversal Operation

Two methods of display to demonstrate traversal in doubly-linked list

1. displayFoward() - method – used to display the list forward or from


head to tail.
2. displayBackward() – used to display the list backward or from tail to
head.

The displayBackward() is similar to displayForward(),only the that it starts


at the last elements in the list and proceeds towards the start of the list,
going to each element’s previous field.

You might also like