Data Types and Components of Data Structure

Only available on StudyMode
  • Topic: Hash table, Hash function, Data structure
  • Pages : 10 (3449 words )
  • Download(s) : 273
  • Published : April 26, 2013
Open Document
Text Preview

Data types
1. Primitive: is a data type provided by a programming language as a basic building block 2. Composite: is any data type which can be constructed in a program using its programming language's primitive data types and other composite types 3. Abstract: is a mathematical model for a certain class of data structures that have similar behavior; or for certain data types of one or more programming languages that have similar semantics TEN COMPONENTS OF DATA STRUCTURE

A. Array
Arrays are one of the simplest and most widely used data structures in computer programs. Arrays in any programming language all share a few common properties: • The contents of an array are stored in contiguous memory. • All of the elements of an array must be of the same type or of a derived type; hence arrays are referred to as homogeneous data structures. • Array elements can be directly accessed. With arrays if you know you want to access the ith element, you can simply use one line of code: arrayName[i]. The common operations performed on arrays are:

• Allocation
• Accessing
An array holds several values of the same kind. Accessing the elements is very fast. It may not be possible to add more values than defined at the start, without copying all values into a new array.

B. List
A List can hold several values. Each item in the list has a way of telling where the next element is; some lists can also tell where the previous element is. It is very easy to add a new element at the start of the list; telling whether an element is already in the list is more difficult, and needs going through all elements of a list. Here are all of the methods of list objects:

Add an item to the end of the list; equivalent to a[len(a):] = [x]. list.extend(L)
Extend the list by appending all the items in the given list; equivalent toa[len(a):] = L. list.insert(i, x)

Remove the first item from the list whose value is x. It is an error if there is no such item. list.pop([i])

Return the index in the list of the first item whose value is x. It is an error if there is no such item. list.count(x)
Return the number of times x appears in the list.

C. Stack
A stack is like a list, but elements can only be added and removed at one end. In addition to adding ('push') or removing ('pop') an element, there's often an operation to look at top of the stack, without removing the element ('peek'). In computer science, a stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push, and removal of an entity, known as pop. The relation between the push and pop operations is such that the stack is a Last-In-First-Out (LIFO) data structure. In a LIFO data structure, the last element added to the structure must be the first one to be removed. This is equivalent to the requirement that, considered as a linear data structure, or more abstractly a sequential collection, the push and pop operations occur only at one end of the structure, referred to as the top of the stack. Often a peek or top operation is also implemented, returning the value of the top element without removing it. A stack...
tracking img