You are on page 1of 19

KAUNO TECHNOLOGIJOS UNIVERSITETAS

INFORMATIKOS FAKULTETAS

TAIKOMOSIOS INFORMATIKOS KATEDRA

Algoritmų sudarymas ir analizė (P170B400)

1 laboratorinio darbo ataskaita

Atliko: IF-9/2 gr. Studentas, Martynas Ravinis

2021 m. kovo 21 d.

Priėmė:

Doc. Vytautas Pilkauskas

KAUNAS 2021
1. Laboratorinio darbo užduotis:

Palyginti rikiavimo algoritmus, kai rikiavimas atliekamas masyve ir sąraše (linked list), t. y.
galimos tik tai struktūrai būdingos operacijos. Šiuos algoritmus reikia realizuojami dviem atvejais:
1) rikiuojami elementai (elemento struktūrą apibrėžia dėstytojas) saugomi operatyvinėje; 2)
rikiuojami duomenų elementai visą laiką saugojami išorinėje (diskinėje) atmintyje, o operatyvinėje
atmintyje gali būti saugojami tik neindeksuotuose kintamuosiuose (neturi būti masyvo, sąrašo ar jų
analogų operatyvinėje atmintyje). Mano atvėju buvo duoti a ir l atvėjai.
Rikiavimas „Merge Sort“, kai skaidoma į dvi dalis.
l) Paieškos uždavinys su Juodai Raudonu paieškos medžiu.

2. Duomenų struktūrų realizavimas išorinėje atmintyje.

DMArray.cs

using System;

namespace DMLibrary.Array
{
public class DMArray<T> : IDMArray<T> where T : IComparable
{
private System.Array _array;

public override T this[int i] { get => (T)_array.GetValue(i); set =>


_array.SetValue(value, i); }
public override int Length { get => _array.Length; }

public DMArray(int n) { _array = System.Array.CreateInstance(typeof(T),


n); }

public override void Empty()


{ System.Array.Clear(_array,0,_array.Length); }
public override void Swap(int a, int b)
{
T help = (T)_array.GetValue(b);
_array.SetValue((T)_array.GetValue(a), b);
_array.SetValue(help, a);

}
public override IDMArray<T> Copy()
{
var tempArray = new DMArray<T>(Length);
for (int i = 0; i < Length; i++)
{
tempArray[i] = this[i];
}
return tempArray;
}

public override void Dispose()


{
}
}
}

DMArrayFile.cs
using DMLibrary.Array;
using DMLibrary.Helper;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace DMLibrary.Array
{
public class DMArrayFile<T> : IDMArray<T> where T : IComparable
{
private FileStream _fs;
private int _start;
private int _start_data;
private BackConverter<T> _converter;
private ToBuffer<T> _tobuffer;
private readonly int _n;
private readonly int _size; //Elemento dydis baitais;
private readonly OSVersion _version;
private readonly ArrayType _type = ArrayType.external;

public override void Dispose()


{
_fs.Close();
}

public override IDMArray<T> Copy()


{
return CopyToFile("Temp.bin");
}

public IDMArray<T> CopyToFile(string filename)


{
var fs = new FileStream(filename, FileMode.Create,
FileAccess.ReadWrite);

var masfCopy = new DMArrayFile<T>(_n,


fs,
_converter,
_tobuffer,
_type,
_size,
_start
);

for (int i = 0; i < Length; i++)


{
masfCopy[i] = this[i];
}
return masfCopy;
}
public override T this[int i]
{
get
{
if (i < 0 || _n <= i) throw new IndexOutOfRangeException();
_fs.Seek(i * _size + _start_data, SeekOrigin.Begin);
var help = new byte[_size];
_fs.Read(help);
if (_type == ArrayType.external)
{
var possition = BitConverter.ToInt32(help);
if (possition == 0) return default(T);

_fs.Seek(possition, SeekOrigin.Begin);
_fs.Read(help, 0, sizeof(int));
var size = BitConverter.ToInt32(help, 0);

//var buffer = new byte[sizeof(int) + size];


//_fs.Seek(-sizeof(int), SeekOrigin.Current);
var buffer = new byte[size];
_fs.Seek(0, SeekOrigin.Current);
_fs.Read(buffer);
return _converter(buffer);
}
else
{
return _converter(help);
}
}
set
{
if (i < 0 || _n <= i) throw new IndexOutOfRangeException();
var data = _tobuffer(value);
_fs.Seek(i * _size + _start_data, SeekOrigin.Begin);
if (_type == ArrayType.inside)
{
if (data.Length <= _size)
{
var data_buffer = new byte[_size];
System.Array.Copy(data, 0, data_buffer, 0, data.Length);
_fs.Write(data);
_fs.Flush();
}
else
throw new RankException();
}
else
{
var position_buffer = new byte[_size];
_fs.Read(position_buffer);
//Skirtumas
var position = BitConverter.ToInt32(position_buffer);
//
if (position != 0)
{
_fs.Seek(position, SeekOrigin.Begin);
var size_buffer = new byte[sizeof(int)];
_fs.Read(size_buffer);
var size = BitConverter.ToInt32(size_buffer);
if (data.Length <= size)
{
_fs.Seek(-sizeof(int), SeekOrigin.Current);
_fs.Write(data);
_fs.Flush();
return;
}
}
_fs.Seek(i * _size + _start_data, SeekOrigin.Begin);
//Skirtumas
_fs.Write(BitConverter.GetBytes((int)_fs.Length));
//
_fs.Seek(0, SeekOrigin.End);
_fs.Write(data);
_fs.Flush();
}
}
}
public override int Length { get => _n; }

public DMArrayFile(int n, FileStream fs, BackConverter<T> converter,


ToBuffer<T> tobuffer, ArrayType type, int size, int start = 0)
{
_version = OSVersion.v32;
_fs = fs;
_n = n;
//Skirtumas
_size = (size == 0 || type == ArrayType.external) ? sizeof(int) :
size;
//
_type = type;
_start = start;
_start_data = 2 * sizeof(byte) + 2 * sizeof(int) + start;
_converter = converter;
_tobuffer = tobuffer;
Empty();
}
public DMArrayFile(FileStream fs, BackConverter<T> converter,
ToBuffer<T> tobuffer, int start = 0)
{
_fs = fs;
_start = start;
_start_data = 2 * sizeof(byte) + 2 * sizeof(int) + start;
_converter = converter;
_tobuffer = tobuffer;

var buffer = new byte[2 * sizeof(byte) + 2 * sizeof(int)];


_fs.Seek(_start, SeekOrigin.Begin);
_fs.Read(buffer);
_version = (OSVersion)buffer[0];
_type = (ArrayType)buffer[1];
_n = BitConverter.ToInt32(buffer, 2 * sizeof(byte));
_size = BitConverter.ToInt32(buffer, 2 * sizeof(byte) +
sizeof(int));
}

public override void Empty()


{
_fs.Seek(_start, SeekOrigin.Begin);
_fs.Write(BitConverter.GetBytes((byte)_version), 0, 1);
_fs.Write(BitConverter.GetBytes((byte)_type), 0, 1);
_fs.Write(BitConverter.GetBytes(_n));
_fs.Write(BitConverter.GetBytes(_size));
_fs.Write(new byte[_n * _size]);
_fs.Flush();
}
public override void Swap(int a, int b)
{
if ((a < 0) || (b < 0) || (_n <= a) || (_n <= b))
{
throw new IndexOutOfRangeException();
}
_fs.Seek(a * _size + _start_data, SeekOrigin.Begin);
var ah = new byte[_size];
_fs.Read(ah);
_fs.Seek(b * _size + _start_data, SeekOrigin.Begin);
var bh = new byte[_size];
_fs.Read(bh);
_fs.Seek(a * _size + _start_data, SeekOrigin.Begin);
_fs.Write(bh);
_fs.Seek(b * _size + _start_data, SeekOrigin.Begin);
_fs.Write(ah);
_fs.Flush();
}

//http://www.morgantechspace.com/2013/08/convert-object-to-byte-array-
and-vice.html
// Convert an object to a byte array
public byte[] ObjectToByteArray(T obj)
{
if (obj == null)
return null;

BinaryFormatter bf = new BinaryFormatter();


MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);

return ms.ToArray();
}
// Convert a byte array to an Object
public T ByteArrayToObject(byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
Object obj = (Object)binForm.Deserialize(memStream);

return (T)obj;
}
}
}
IDMArray.cs

using System;

namespace DMLibrary.Array
{
public abstract class IDMArray<T>: IDisposable where T : IComparable
{
public abstract T this[int i] { get; set; }
public abstract int Length { get; }

public abstract void Empty();


public abstract void Swap(int a, int b);
public abstract IDMArray<T> Copy();
public abstract void Dispose();

void Merge(int l, int m, int r)


{
// Find sizes of two
// subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;

IDMArray<T> L, R;

switch (this)
{
case DMArrayFile<T> file:
L = file.CopyToFile("L.bin");
R = file.CopyToFile("R.bin");
break;
default:
L = Copy();
R = Copy();
break;
}

// Create temp arrays


int i, j;

// Copy data to temp arrays


for (i = 0; i < n1; ++i)
L[i] = this[l + i];
for (j = 0; j < n2; ++j)
R[j] = this[m + 1 + j];

// Merge the temp arrays

// Initial indexes of first


// and second subarrays
i = 0;
j = 0;

// Initial index of merged


// subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i].CompareTo(R[j]) <= 0)
{
this[k] = L[i];
i++;
}
else
{
this[k] = R[j];
j++;
}
k++;
}

// Copy remaining elements


// of L[] if any
while (i < n1)
{
this[k] = L[i];
i++;
k++;
}

// Copy remaining elements


// of R[] if any
while (j < n2)
{
this[k] = R[j];
j++;
k++;
}

L.Dispose();
R.Dispose();
}

public void MergeSort(int l, int r)


{
if (l >= r)
return;
var m = l + (r - l) / 2;

MergeSort(l, m);
MergeSort(m + 1, r);

Merge(l, m, r);

}
}

ArrayType.cs
namespace DMLibrary.Helper
{
public enum ArrayType
{
inside = 0,
external = 1
}
}
Delegates.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace DMLibrary.Helper
{
public delegate T BackConverter<T>(byte[] buffer);
public delegate byte[] ToBuffer<T>(T item);
}

OSVersion.cs

namespace DMLibrary.Helper
{
public enum OSVersion
{
v32 = 32,
v64 = 64
}
}

RedBlackTree.cs

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace OpinionatedCode.Collections
{
public sealed class RedBlackTree<TKey, TValue>
{
private readonly RedBlackTreeNode<TKey, TValue> _leaf =
RedBlackTreeNode<TKey, TValue>.CreateLeaf();

public RedBlackTree()
{
Root = _leaf;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue Get(TKey key)
{
try
{
int hashedKey = key.GetHashCode();
RedBlackTreeNode<TKey, TValue> node = Root;
do
{
if (node.HashedKey == hashedKey)
return node.Value;
node = hashedKey < node.HashedKey ? node.Left : node.Right;
} while (true);
}
catch (NullReferenceException)
{
throw new KeyNotFoundException();
}
}
internal RedBlackTreeNode<TKey, TValue> Root { get; private set; }

public void Add(TKey key, TValue value)


{
RedBlackTreeNode<TKey, TValue> newNode = RedBlackTreeNode<TKey,
TValue>.CreateNode(key, value, RedBlackTreeNode<TKey, TValue>.ColorEnum.Red,
key.GetHashCode());
Insert(newNode);
}

private void Insert(RedBlackTreeNode<TKey, TValue> z)


{
var y = _leaf;
var x = Root;
while (x != _leaf)
{
y = x;
x = z.HashedKey < x.HashedKey ? x.Left : x.Right;
}

z.Parent = y;
if (y == _leaf)
{
Root = z;
}
else if (z.HashedKey < y.HashedKey)
{
y.Left = z;
}
else
{
y.Right = z;
}

z.Left = _leaf;
z.Right = _leaf;
z.Color = RedBlackTreeNode<TKey, TValue>.ColorEnum.Red;
InsertFixup(z);
}

private void InsertFixup(RedBlackTreeNode<TKey, TValue> z)


{
while (z.Parent.Color == RedBlackTreeNode<TKey,
TValue>.ColorEnum.Red)
{
if (z.Parent == z.Parent.Parent.Left)
{
var y = z.Parent.Parent.Right;
if (y.Color == RedBlackTreeNode<TKey, TValue>.ColorEnum.Red)
{
z.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
y.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
z.Parent.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Red;
z = z.Parent.Parent;
}
else
{
if (z == z.Parent.Right)
{
z = z.Parent;
RotateLeft(z);
}

z.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
z.Parent.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Red;
RotateRight(z.Parent.Parent);
}
}
else
{
var y = z.Parent.Parent.Left;
if (y.Color == RedBlackTreeNode<TKey, TValue>.ColorEnum.Red)
{
z.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
y.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
z.Parent.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Red;
z = z.Parent.Parent;
}
else
{
if (z == z.Parent.Left)
{
z = z.Parent;
RotateRight(z);
}

z.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Black;
z.Parent.Parent.Color = RedBlackTreeNode<TKey,
TValue>.ColorEnum.Red;
RotateLeft(z.Parent.Parent);
}
}
}

Root.Color = RedBlackTreeNode<TKey, TValue>.ColorEnum.Black;


}

private void RotateLeft(RedBlackTreeNode<TKey, TValue> x)


{
var y = x.Right;
x.Right = y.Left;
if (y.Left != _leaf)
{
y.Left.Parent = x;
}

y.Parent = x.Parent;
if (x.Parent == _leaf)
{
Root = y;
}
else if (x == x.Parent.Left)
{
x.Parent.Left = y;
}
else
{
x.Parent.Right = y;
}

y.Left = x;
x.Parent = y;
}

private void RotateRight(RedBlackTreeNode<TKey, TValue> x)


{
var y = x.Left;
x.Left = y.Right;
if (y.Right != _leaf)
{
y.Right.Parent = x;
}
y.Parent = x.Parent;
if (x.Parent == _leaf)
{
Root = y;
}
else if (x == x.Parent.Left)
{
x.Parent.Left = y;
}
else
{
x.Parent.Right = y;
}

y.Right = x;
x.Parent = y;
}
}
}

namespace OpinionatedCode.Collections
{
internal sealed class RedBlackTreeNode<TKey, TValue>
{
public enum ColorEnum
{
Red,
Black
};

public readonly TValue Value;

public readonly TKey Key;

public readonly bool IsLeaf;

public readonly int HashedKey;

public ColorEnum Color;

public RedBlackTreeNode<TKey, TValue> Parent;


public RedBlackTreeNode<TKey, TValue> Left;

public RedBlackTreeNode<TKey, TValue> Right;

public static RedBlackTreeNode<TKey, TValue> CreateLeaf()


{
return new RedBlackTreeNode<TKey, TValue>();
}

public static RedBlackTreeNode<TKey, TValue> CreateNode(TKey key, TValue


value, ColorEnum color, int hashedKey)
{
return new RedBlackTreeNode<TKey, TValue>(key, value, color,
hashedKey);
}

internal RedBlackTreeNode(TKey key, TValue value, ColorEnum color, int


hashedKey)
{
Value = value;
HashedKey = hashedKey;
Color = color;
Key = key;
}

internal RedBlackTreeNode()
{
IsLeaf = true;
Color = ColorEnum.Black;
HashedKey = 0;
}

public RedBlackTreeNode<TKey, TValue> Grandparent => Parent?.Parent;

public RedBlackTreeNode<TKey, TValue> Sibling =>


Parent == null ? null : Parent.Left == this ? Parent.Right :
Parent.Left;

public RedBlackTreeNode<TKey, TValue> Uncle => Parent?.Sibling;


}
}

Program.cs

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using DMLibrary.Array;
using DMLibrary.Helper;
using OpinionatedCode.Collections;

namespace Pavyzdys__Array_
{
[Serializable]
class Data : IComparable<Data>, IComparable
{
public string str { get; set; }
public double frac { get; set; }

public int CompareTo(Data other)


{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var strComparison = string.Compare(str, other.str,
StringComparison.Ordinal);
if (strComparison != 0) return strComparison;

return frac.CompareTo(other.frac);
}

public int CompareTo(object? obj)


{
return CompareTo(obj as Data);
}

public byte[] ToByteArray()


{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, (Object)this);
byte[] arr = new byte[ms.Length + sizeof(int)];
Array.Copy(BitConverter.GetBytes(ms.Length), arr, sizeof(int));
Array.Copy(ms.ToArray(), 0, arr, sizeof(int), ms.Length);

return arr;
}

public static Data ByteArrayToObject(byte[] arrBytes)


{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);

return (Data)binForm.Deserialize(memStream);
}

public override string ToString()


{
return $"| {str} | {frac:F5} |";
}
}

class Program
{
static void Main(string[] args)
{
int n = 1400;
var mas = new DMArray<Data>(n);
var rnd = new Random(1000);

for (int i = 0; i < n; i++)


{
var (str, frac) = DataSequence(3, rnd);
mas[i] = new Data()
{
str = str,
frac = frac
};
}
for (int i = 0; i < n; i++)
{
Console.WriteLine(mas[i]);
}
using (var fs = new FileStream("Array.bin", FileMode.Create,
FileAccess.ReadWrite))
{
var masf = new DMArrayFile<Data>(n,
fs,
(byte[] a) => (Data)Data.ByteArrayToObject(a),
(Data s) => s.ToByteArray(),
ArrayType.external,
0
);
var masf2 = new DMArrayFile<Data>(n,
fs,
(byte[] a) =>
{
int length = BitConverter.ToInt32(a, 0);
var str = new byte[length];
Array.Copy(a, sizeof(int), str, 0, length);
return Data.ByteArrayToObject(str);
},
(Data s) => s.ToByteArray(),
ArrayType.inside,
250,
10 + n * 4
);

var llist = new DMLinkedList<Data>();

for (int i = 0; i < n; i++)


{
masf[i] = mas[i];
masf2[i] = mas[i];
llist.Add(mas[i]);
}

Console.WriteLine("=masf======================");
for (int i = 0; i < n; i++)
{
Console.WriteLine(masf[i]);
}
Console.WriteLine("=masf2=====================");
for (int i = 0; i < n; i++)
{
Console.WriteLine(masf2[i]);
}

var sw = Stopwatch.StartNew();
mas.MergeSort(0, masf.Length - 1);
sw.Stop();
var sort_list_ram = sw.ElapsedMilliseconds;

sw.Restart();
llist.MergeSort(0, masf.Length - 1);
sw.Stop();
var sort_llist_ram = sw.ElapsedMilliseconds;
sw.Restart();
masf.MergeSort(0, masf.Length - 1);
sw.Stop();
var sort_list = sw.ElapsedMilliseconds;

sw.Restart();
masf2.MergeSort(0, masf2.Length - 1);
sw.Stop();
var sort_llist = sw.ElapsedMilliseconds;

Console.WriteLine("=masf=sorted=====================");
for (int i = 0; i < n; i++)
{
Console.WriteLine(masf[i]);
}
Console.WriteLine("=masf2=sorted====================");
for (int i = 0; i < n; i++)
{
Console.WriteLine(masf2[i]);
}

var rbl = new RedBlackTree<string, double>();


// var RBTree = new RedBlackTree<string>();

Console.WriteLine("Kas kelinta elementa praleisti: ");


var num = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
if (i % num == 0)
rbl.Add(mas[i].str, mas[i].frac);
}

var found = 0;

sw.Restart();
for (int i = 0; i < mas.Length; i++)
{
var key = mas[i].str;
try
{
rbl.Get(key);
found++;
}
catch (KeyNotFoundException)
{ }
}
sw.Stop();

Console.WriteLine($"Found in RBT: {found}, missing: {mas.Length


- found} elements");
Console.WriteLine($"Array sort (file): {sort_list}ms");
Console.WriteLine($"Array sort (ram): {sort_list_ram}ms");
Console.WriteLine($"Linked list sort (file): {sort_llist}ms");
Console.WriteLine($"Linked list sort (ram):
{sort_llist_ram}ms");
Console.WriteLine($"RBT: {sw.ElapsedMilliseconds}ms");
}
}

static (string, double) DataSequence(int n, Random rnd)


{
//const string str = "aąbcčdeęėfghiįyjklmnoprsštuųūvzž";
const string str = "abcdefghijklm";
Func<string> genStr = () => str[rnd.Next(0,
str.Length)].ToString().ToUpper();

string hlp = genStr();


for (int i = 0; i < n - 1; i++)
{
hlp += genStr();
}
return (hlp, rnd.NextDouble());
}
}
}

3. Rezultatai:

Eksperimento metu buvo generuojami bei rikiuojami 200, 400, 600, 800, 1000, 1200, 1400,
1600 bei 1800 duomenų su string‘o 3 raidėm, bei double skaičiumi. Duomenys buvo rikiuojami ir
kaip masyvas, ir kaip sąrašas. Eksperimento rezultatai pateikti grafikuose (rikiavimo laiko
priklausomybė nuo duomenų kiekio):

Rekurentinė išraiška:

T(n) = 2T(n/2) + O(n)

Geriausias atvėjis: Ω(n*log(n))

Vidutinis atvėjis: Θ(n*log(n))

Blogiausias atvėjis: O(n*log(n))

Diskinėje atmintyje rezultatai:


n Array(File) LinkedList(File)
0
200 6.841 3.704
400 21.431 11.549
600 40.175 22.738
800 56.745 28.491
1000 120.094 64.742
1200 196.603 116.536
1400 210.921 122.389
1600 280.343 139.300
1800 348.553 160.004
Grafikas:

Array ir LinkedList diskinėje atmintyje


400.000
350.000
300.000
250.000
200.000
150.000
100.000
50.000
0.000
0 200 400 600 800 1000 1200 1400 1600 1800

Array LinkedList

Rikiavimas operatyvioje atmintyje. Lentelė:


n Array(Ram) LinkedList(RAM)
0
200 0.009 0.133
400 0.043 0.567
600 0.104 1.301
800 0.112 2.344
1000 0.128 5.768
1200 0.173 11.735
1400 0.229 17.489
1600 0.245 19.829
1800 0.342 28.522

Grafikas:

Array ir Linked list Operatyvinėje atmintyje


30.000

25.000

20.000

15.000

10.000

5.000

0.000
0 200 400 600 800 1000 1200 1400 1600 1800

Array LinkedList
Raudonai-Juodas paieškos medis.

Sudėtingumas vidutiniu atvėju: Θ (log(n))

Blogiausiu atvėju: O(log(n))

n Rbmedis
0
200 0.000
400 0.000
600 0.000
800 0.000
1000 0.001
1200 0.001
1400 0.001
1600 0.001
1800 0.001

Raudonai-Juodas paieškos medis


0.002

0.001

0.000
0 200 400 600 800 1000 1200 1400 1600 1800

4. Išvados:
Remiantis svetainių https://www.journaldev.com/31541/merge-sort-algorithm-java-c-python
ir https://en.wikipedia.org/wiki/Merge_sort duomenimis, teorinis įterpimo rikiavimo algoritmo
efektyvumas visais trimis atvėjais yra toks pat. Galime pamatyti, kad operatyvėje atmintyje Linked
List yra daug spartesnis nei masyvo. Diskinėje atmintyje Linked List yra spartesnis nei masyvo.

You might also like