Difference between revisions of "Data Structures & Algorithms"

From Sinfronteras
Jump to: navigation, search
(Array)
Line 2: Line 2:
  
 
==Array==
 
==Array==
An array is a sequenced collection of variables all of the same type. Each variable, or cell, in an array has an index, which uniquely refers to the value stored in that cell. The cells of an array, A, are numbered 0, 1, 2, and so on.  
+
An array is a sequenced collection of variables all of the same type. Each variable, or cell, in an array has an index, which uniquely refers to the value stored in that cell. The cells of an array, A, are numbered 0, 1, 2, and so on. Each value stored in an array is often called an element of that array.
 
 
Each value stored in an array is often called an element of that array.
 
 
 
  
 
* An array can store primitive elements, such as characters.
 
* An array can store primitive elements, such as characters.
Line 13: Line 10:
 
* '''Adding an Entry:'''
 
* '''Adding an Entry:'''
 
** To add an entry e into array board at index i, we need to make room for it by shifting forward the n - i entries board[i],...,board[n - 1]
 
** To add an entry e into array board at index i, we need to make room for it by shifting forward the n - i entries board[i],...,board[n - 1]
 +
  
 
* '''Removing an Entry:'''
 
* '''Removing an Entry:'''
 
** To remove the entry e at index i, we need to fill the hole left by e by shifting backward the n - i - 1 elements board[i + 1],...,board[n - 1]
 
** To remove the entry e at index i, we need to fill the hole left by e by shifting backward the n - i - 1 elements board[i + 1],...,board[n - 1]

Revision as of 16:07, 14 October 2018

List and Linked lists

Array

An array is a sequenced collection of variables all of the same type. Each variable, or cell, in an array has an index, which uniquely refers to the value stored in that cell. The cells of an array, A, are numbered 0, 1, 2, and so on. Each value stored in an array is often called an element of that array.

  • An array can store primitive elements, such as characters.
  • An array can also store references to objects.


  • Adding an Entry:
    • To add an entry e into array board at index i, we need to make room for it by shifting forward the n - i entries board[i],...,board[n - 1]


  • Removing an Entry:
    • To remove the entry e at index i, we need to fill the hole left by e by shifting backward the n - i - 1 elements board[i + 1],...,board[n - 1]