Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkipList.py: Added SkipList Data Structure Implementation #236

Closed
wants to merge 14 commits into from

Conversation

tanseersaji
Copy link
Member

@tanseersaji tanseersaji commented Oct 3, 2018

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Fixes #234

By submitting this pull request I confirm I've read and complied with the
below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the commit guidelines for this project.
  • My code follows the standard code structure.
  • This pull request has a descriptive title. For example, {Tag}: Add {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
  • This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met.
  • I have mentioned the issue number correctly (with hyperlink) in this pull request description.

After you submit your pull request, DO NOT click the 'Update Branch' button.

This adds the implementation of Skip List Data Structure in python, this also adds the operation that can be done in a SkipList Data Structure like Insertion, Deletion, Traversal.

Closes NITSkmOS#234
x = x.next[i]
update[i] = x
return update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -62,7 +62,7 @@
                 x = x.next[i]
             update[i] = x
         return update
-        
+
     '''
         This function inserts an element in the correct possition.
         The insertion operation takes O(n) time complexity

self.maxHeight = max(self.maxHeight, len(node.next))
while len(self.head.next) < len(node.next):
self.head.next.append(None)
update = self.updateList(elem)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -73,7 +73,7 @@
         self.maxHeight = max(self.maxHeight, len(node.next))
         while len(self.head.next) < len(node.next):
             self.head.next.append(None)
-        update = self.updateList(elem)            
+        update = self.updateList(elem)
         if self.find(elem, update) == None:
             for i in range(len(node.next)):
                 node.next[i] = update[i].next[i]

self.len += 1

'''
This function will remove the specified element from the list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -81,7 +81,7 @@
             self.len += 1
 
     '''
-        This function will remove the specified element from the list. 
+        This function will remove the specified element from the list.
         The deletion operation in Skip List takes O(log(n)) time.
     '''
     def remove(self, elem):

update[i].next[i] = x.next[i]
if self.head.next[i] == None:
self.maxHeight -= 1
self.len -= 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -92,7 +92,7 @@
                 update[i].next[i] = x.next[i]
                 if self.head.next[i] == None:
                     self.maxHeight -= 1
-            self.len -= 1            
+            self.len -= 1
 
     '''
         This function will print the entier Data Structure, level by level (top to bottom)


'''
This function will print the entier Data Structure, level by level (top to bottom)
'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -96,7 +96,7 @@
 
     '''
         This function will print the entier Data Structure, level by level (top to bottom)
-    '''       
+    '''
     def printList(self):
         for i in range(len(self.head.next)-1, -1, -1):
             x = self.head

t0 = time.time()
# Skip List takes the maximum time to search the elements in the middle.
print(skipList.find(596536) != None)
print("Time taken to search in a list of size 1 Million: "+str(time.time() - t0)+" s.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • No newline at EOF.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
+++ b/tmp/tmpphsfotv0/skip_list/Python/SkipList.py
@@ -119,4 +119,4 @@
     t0 = time.time()
     # Skip List takes the maximum time to search the elements in the middle.
     print(skipList.find(596536) != None)
-    print("Time taken to search in a list of size 1 Million: "+str(time.time() - t0)+" s.")+    print("Time taken to search in a list of size 1 Million: "+str(time.time() - t0)+" s.")

@sangamcse
Copy link
Member

Never open a PR from master branch. Read the guidelines before solving any issue

This adds the implementation of Skip List Data Structure in python, this also adds the operation that can be done in a SkipList Data Structure like Insertion, Deletion, Traversal.

Closes NITSkmOS#234
level by level (top to bottom)
'''
def printList(self):
for i in range(len(self.head.next)-1, -1, -1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmphyrtd5og/skip_list/Python/SkipList.py
+++ b/tmp/tmphyrtd5og/skip_list/Python/SkipList.py
@@ -56,7 +56,7 @@
             while x.next[i]!=None and x.next[i].elem<elem:
                 x=x.next[i]
             update[i]=x
-        return update        
+        return update
     '''
         This function inserts an element in the correct possition.
         The insertion operation takes O(n) time complexity

This adds the implementation of Skip List Data Structure in python, this also adds the operation that can be done in a SkipList Data Structure like Insertion, Deletion, Traversal.

Closes NITSkmOS#234
@sangamcse
Copy link
Member

Comment on d08032f, file skip_list/Python/SkipList.py, line 59.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpn2153vea/skip_list/Python/SkipList.py
+++ b/tmp/tmpn2153vea/skip_list/Python/SkipList.py
@@ -56,7 +56,7 @@
             while x.next[i]!=None and x.next[i].elem<elem:
                 x=x.next[i]
             update[i]=x
-        return update        
+        return update
     '''
         This function inserts an element in the correct possition.
         The insertion operation takes O(n) time complexity

@sangamcse
Copy link
Member

Comment on d08032f, file skip_list/Python/SkipList.py, line 69.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpn2153vea/skip_list/Python/SkipList.py
+++ b/tmp/tmpn2153vea/skip_list/Python/SkipList.py
@@ -66,7 +66,7 @@
         self.maxHeight=max(self.maxHeight,len(node.next))
         while(len(self.head.next)<len(node.next)):
             self.head.next.append(None)
-        update=self.updateList(elem)            
+        update=self.updateList(elem)
         if(self.find(elem, update)==None):
             for i in range(len(node.next)):
                 node.next[i]=update[i].next[i]

@sangamcse
Copy link
Member

Comment on d08032f, file skip_list/Python/SkipList.py, line 76.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpn2153vea/skip_list/Python/SkipList.py
+++ b/tmp/tmpn2153vea/skip_list/Python/SkipList.py
@@ -73,7 +73,7 @@
                 update[i].next[i]=node
             self.len+=1
     '''
-        This function will remove the specified element from the list. 
+        This function will remove the specified element from the list.
         The deletion operation in Skip List takes O(log(n)) time.
     '''
     def remove(self,elem):

@sangamcse
Copy link
Member

Comment on d08032f, file skip_list/Python/SkipList.py, line 87.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpn2153vea/skip_list/Python/SkipList.py
+++ b/tmp/tmpn2153vea/skip_list/Python/SkipList.py
@@ -84,7 +84,7 @@
                 update[i].next[i]=x.next[i]
                 if(self.head.next[i]==None):
                     self.maxHeight-=1
-            self.len-=1            
+            self.len-=1
     '''
         This function will print the entier Data Structure,
         level by level (top to bottom)

@sangamcse
Copy link
Member

Comment on d08032f, file skip_list/Python/SkipList.py, line 91.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpn2153vea/skip_list/Python/SkipList.py
+++ b/tmp/tmpn2153vea/skip_list/Python/SkipList.py
@@ -88,7 +88,7 @@
     '''
         This function will print the entier Data Structure,
         level by level (top to bottom)
-    '''       
+    '''
     def printList(self):
         for i in range(len(self.head.next)-1, -1, -1):
             x=self.head

@@ -0,0 +1,24 @@
#include <stdio.h>
void main()
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ should almost always be at the end of the previous line [whitespace/braces] [4]

Origin: CPPLintBear, Section: all.cpplint.

#include <stdio.h>
void main()
{
int a[10], i, item,n,flag=0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around = [whitespace/operators] [4]

Origin: CPPLintBear, Section: all.cpplint.

#include <stdio.h>
void main()
{
int a[10], i, item,n,flag=0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after , [whitespace/comma] [3]

Origin: CPPLintBear, Section: all.cpplint.

{
int a[10], i, item,n,flag=0;
printf("Enter number of elements : ");
scanf("%d",&n);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after , [whitespace/comma] [3]

Origin: CPPLintBear, Section: all.cpplint.

printf("Enter number of elements : ");
scanf("%d",&n);
printf("\nEnter elements of an array:\n");
for (i=0; i<n; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around < [whitespace/operators] [3]

Origin: CPPLintBear, Section: all.cpplint.

scanf("%d", &a[i]);}
printf("\nEnter item to search: ");
scanf("%d", &item);
for (i=0; i<n; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around < [whitespace/operators] [3]

Origin: CPPLintBear, Section: all.cpplint.

printf("\nEnter item to search: ");
scanf("%d", &item);
for (i=0; i<n; i++)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ should almost always be at the end of the previous line [whitespace/braces] [4]

Origin: CPPLintBear, Section: all.cpplint.

for (i=0; i<n; i++)
{
if (item == a[i])
{ flag=1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around = [whitespace/operators] [4]

Origin: CPPLintBear, Section: all.cpplint.

break;
}
}
if (flag==0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around == [whitespace/operators] [3]

Origin: CPPLintBear, Section: all.cpplint.

Copy link
Member

@sangamcse sangamcse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow https://github.com/NITSkmOS/Algorithms#contributing.
Open new one after rebasing your local repo.
For rebase, get help from https://github.com/NITSkmOS/Algorithms/blob/master/GIT_BASICS.md

@sangamcse sangamcse closed this Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Data Structure] Skip List [Python]
3 participants